List of usage examples for com.amazonaws.services.dynamodbv2.model ScanResult getItems
public java.util.List<java.util.Map<String, AttributeValue>> getItems()
An array of item attributes that match the scan criteria.
From source file:NYSEScan.java
License:Open Source License
private static void scan(String tableName) { Table table = null;//from www .ja v a 2 s . c o m try { // Create table if it does not exist yet if (!Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is does not exist"); } else { table = dynamo.getTable(tableName); } // select * from stock_eod where stockTicker = 'HCA' and v > 1000000; // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>(); expressionAttributeValues.put(":val", new AttributeValue().withN("1000000")); //Below is not recommended as stockTicker is part of the key expressionAttributeValues.put(":st", new AttributeValue().withS("HCA")); ScanRequest scanRequest = new ScanRequest().withTableName(tableName) .withFilterExpression("v > :val and stockTicker = :st") // select stockTicker, tradeDate, v from stock_eod where stockTicker = 'HCA' and v > 1000000; .withProjectionExpression("stockTicker,tradeDate,v") .withExpressionAttributeValues(expressionAttributeValues); ScanResult result = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : result.getItems()) { System.out.println(item); } } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.iterator.MultiRowParallelScanInterpreter.java
License:Open Source License
/** * This class relies heavily on the behavior of segmented scans with respect to which hash keys are scanned by each segment. * Here's a rough ASCII example to help illustrate: * ___________________________// w ww .ja v a2s . c o m * |hk:A |hk:B | * ---------------------------- * ^segment 1 ^segment 2 * * Because we are scanning in segments across the entire hash key space, it is possible for the same hash key to appear in two different segments. * We are also running all of the scan segments in parallel, so we have no control over which segment returns first. * * In the example, if segment 2 was the first segment to post a result, we would store hk:B as a "boundary" key. That way when * segment 1 eventually reaches hk:B in its scan, we know that another segment has already returned this hash key and we can safely skip returning it. * * By doing this, we avoid returning a RecordIterator for the same hash key twice and we only need to store at most 2 hash keys per segment. * */ @Override public List<SingleKeyRecordIterator> buildRecordIterators(final ScanContext scanContext) { final ScanResult dynamoDbResult = scanContext.getScanResult(); final int segment = scanContext.getScanRequest().getSegment(); final List<Map<String, AttributeValue>> items = dynamoDbResult.getItems(); // If the scan returned no results, we need to shortcut and just throw back an empty result set if (items.isEmpty()) { return Collections.emptyList(); } final List<SingleKeyRecordIterator> recordIterators = Lists.newLinkedList(); final Iterator<Map<String, AttributeValue>> itemIterator = items.iterator(); final Map<String, AttributeValue> firstItem = itemIterator.next(); final StaticBuffer firstKey = new KeyBuilder(firstItem).build(Constants.JANUSGRAPH_HASH_KEY); // Computes the full set of boundary keys up to this point. This includes the previous end key for this segment. final ImmutableSet<StaticBuffer> boundaryKeys = aggregateBoundaryKeys(); // The first key in this scan segment might already have been returned by a previous scan segment if (!boundaryKeys.contains(firstKey)) { recordIterators.add(buildRecordIteratorForHashKey(firstKey)); } StaticBuffer hashKey = firstKey; while (itemIterator.hasNext()) { final Optional<StaticBuffer> nextKey = findNextHashKey(itemIterator, hashKey); if (nextKey.isPresent()) { // Found a new hash key. Make a record iterator and look for the next unique hash key hashKey = nextKey.get(); recordIterators.add(buildRecordIteratorForHashKey(hashKey)); } } // If we've already seen the final hashKey in a previous scan segment result, we want to avoid returning it again. if (!hashKey.equals(firstKey) && boundaryKeys.contains(hashKey)) { recordIterators.remove(recordIterators.size() - 1); } // Update the boundary keys for this segment if (scanContext.isFirstResult()) { setInitialBoundaryKeys(segment, firstKey, hashKey); } else { updateLastKey(segment, hashKey); } return recordIterators; }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public boolean isExist(String UserID) { ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { if (!(item.isEmpty())) return true; }//from w w w .j av a2s.co m return false; }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public String getUserName(String UserID) { String result = ""; ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserID", new Condition().withAttributeValueList(new AttributeValue(UserID)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { System.out.println(item.get("UserName")); result = item.get("UserName").toString(); }//from w w w.j a va 2 s . co m return result; }
From source file:com.app.dynamoDb.DynamoFacebookUsers.java
License:Open Source License
public AttributeValue getUserID(String UserName) { ScanRequest scanRequest = new ScanRequest("FacebookUsers"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(UserName)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { return item.get("UserID"); }//from w w w. j a va2s .com return null; }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
@SuppressWarnings("null") public void insert(String UserName, String Password, String Email) { ScanRequest scanRequest = new ScanRequest("Users"); ScanResult scanResult = dynamoDB.scan(scanRequest); int s[] = new int[100]; int i = 0;/*from w ww .j a v a 2 s. c o m*/ for (Map<String, AttributeValue> item : scanResult.getItems()) { s[i] = Integer.valueOf(item.get("UserID").getS()); i++; } Arrays.sort(s); int max = s[s.length - 1]; String userid = String.valueOf(max + 1); Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put("UserID", new AttributeValue(userid)); item.put("UserName", new AttributeValue(UserName)); item.put("Password", new AttributeValue(Password)); item.put("Email", new AttributeValue(Email)); this.setUserID(userid); this.setUserName(UserName); this.setPassword(Password); this.setEmail(Email); PutItemRequest putItemRequest = new PutItemRequest("Users", item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public boolean validateEmail(String Email, String Password) { ScanRequest scanRequest = new ScanRequest("Users"); scanRequest.setConditionalOperator(ConditionalOperator.AND); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(Email)) .withComparisonOperator(ComparisonOperator.EQ)); scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(Password)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { //System.out.println(item); if (!item.isEmpty()) return true; }/*from ww w .j a va 2s. co m*/ return false; }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public boolean validateName(String UserName, String Password) { ScanRequest scanRequest = new ScanRequest("Users"); scanRequest.setConditionalOperator(ConditionalOperator.AND); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserName", new Condition().withAttributeValueList(new AttributeValue(UserName)) .withComparisonOperator(ComparisonOperator.EQ)); scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(Password)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { //System.out.println(item); if (!item.isEmpty()) return true; }/*from w w w . j a v a2 s .c o m*/ return false; }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public String getUserIDfromUserName(String UserName) { String result = ""; ScanRequest scanRequest = new ScanRequest("Users"); //scanRequest.setConditionalOperator(ConditionalOperator.OR); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("UserName", new Condition().withAttributeValueList(new AttributeValue(UserName)) .withComparisonOperator(ComparisonOperator.EQ)); //scanFilter.put("Password", new Condition().withAttributeValueList(new AttributeValue(UserName)).withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { // System.out.println(item.get("UserID")); result = item.get("UserID").toString().replaceAll("\\W", "").trim().toLowerCase(); result = result.replaceAll("\\D", ""); }/*from w w w . j av a2 s .c o m*/ return result; }
From source file:com.app.dynamoDb.DynamoUser.java
License:Open Source License
public String getUserIDfromEmail(String Email) { String result = ""; ScanRequest scanRequest = new ScanRequest("Users"); Map<String, Condition> scanFilter = new HashMap<String, Condition>(); scanFilter.put("Email", new Condition().withAttributeValueList(new AttributeValue(Email)) .withComparisonOperator(ComparisonOperator.EQ)); scanRequest.setScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); for (Map<String, AttributeValue> item : scanResult.getItems()) { // System.out.println(item.get("UserID")); result = item.get("UserID").toString().replaceAll("\\W", "").trim().toLowerCase(); result = result.replaceAll("\\D", ""); }/* www. j a v a 2 s . c o m*/ return result; }