List of usage examples for com.amazonaws.services.dynamodbv2.model ComparisonOperator LT
ComparisonOperator LT
To view the source code for com.amazonaws.services.dynamodbv2.model ComparisonOperator LT.
Click Source Link
From source file:com.dell.doradus.db.s3.DynamoDBService2.java
License:Apache License
@Override public List<DColumn> getColumns(String storeName, String rowKey, String startColumn, String endColumn, int count) { Timer t = new Timer(); String key = storeName + "_" + rowKey; HashMap<String, Condition> keyConditions = new HashMap<String, Condition>(); keyConditions.put("key", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(key))); if (startColumn != null && endColumn != null) { keyConditions.put("column", new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList( new AttributeValue().withS(startColumn), new AttributeValue(endColumn))); } else if (startColumn != null) { keyConditions.put("column", new Condition().withComparisonOperator(ComparisonOperator.GE) .withAttributeValueList(new AttributeValue().withS(startColumn))); } else if (endColumn != null) { keyConditions.put("column", new Condition().withComparisonOperator(ComparisonOperator.LT) .withAttributeValueList(new AttributeValue().withS(endColumn))); }//from www . j a va 2 s .c om QueryRequest request = new QueryRequest().withTableName(getTenant().getName()) .withLimit(Math.min(100, count)).withKeyConditions(keyConditions); QueryResult result = m_client.query(request); List<DColumn> list = fromItems(result.getItems()); m_logger.debug("get columns range for {} in {}", getTenant().getName(), t); return list; }
From source file:com.intuit.tank.persistence.databases.AmazonDynamoDatabaseDocApi.java
License:Open Source License
/** * @{inheritDoc//from w w w .j ava 2 s. c o m */ @SuppressWarnings("unchecked") @Override public PagedDatabaseResult getPagedItems(String tableName, Object nextToken, String minRange, String maxRange, String instanceId, String jobId) { List<Item> ret = new ArrayList<Item>(); Map<String, AttributeValue> lastKeyEvaluated = (Map<String, AttributeValue>) nextToken; ScanRequest scanRequest = new ScanRequest().withTableName(tableName); Map<String, Condition> conditions = new HashMap<String, Condition>(); if (jobId != null) { Condition jobIdCondition = new Condition(); jobIdCondition.withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(jobId)); conditions.put(DatabaseKeys.JOB_ID_KEY.getShortKey(), jobIdCondition); } if (StringUtils.isNotBlank(instanceId)) { // add a filter Condition filter = new Condition(); filter.withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(instanceId)); scanRequest.addScanFilterEntry(DatabaseKeys.INSTANCE_ID_KEY.getShortKey(), filter); } Condition rangeKeyCondition = new Condition(); if (minRange != null && maxRange != null) { rangeKeyCondition.withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList(new AttributeValue().withS(minRange)) .withAttributeValueList(new AttributeValue().withS(maxRange)); } else if (minRange != null) { rangeKeyCondition.withComparisonOperator(ComparisonOperator.GE.toString()) .withAttributeValueList(new AttributeValue().withS(minRange)); } else if (maxRange != null) { rangeKeyCondition.withComparisonOperator(ComparisonOperator.LT.toString()) .withAttributeValueList(new AttributeValue().withS(maxRange)); } else { rangeKeyCondition = null; } if (rangeKeyCondition != null) { conditions.put(DatabaseKeys.REQUEST_NAME_KEY.getShortKey(), rangeKeyCondition); } scanRequest.withScanFilter(conditions); scanRequest.withExclusiveStartKey(lastKeyEvaluated); ScanResult result = dynamoDb.scan(scanRequest); for (Map<String, AttributeValue> item : result.getItems()) { ret.add(getItemFromResult(item)); } return new PagedDatabaseResult(ret, result.getLastEvaluatedKey()); }
From source file:com.numenta.taurus.service.TaurusClient.java
License:Open Source License
/** * Get list of tweets for the given metric filtered by the given time range returning the * results as they become available asynchronously. * * @param metricName The metric name to retrieve the tweets from * @param from The start time (aggregated) inclusive. * @param to The end time (aggregated) inclusive. * @param callback Callback for asynchronous call. It will be called on every {@link Tweet} *//* w w w .j a v a2 s .c o m*/ public void getTweets(String metricName, Date from, Date to, DataCallback<Tweet> callback) throws GrokException, IOException { if (metricName == null) { throw new ObjectNotFoundException("Cannot get tweets without metric name"); } final TaurusDataFactory dataFactory = TaurusApplication.getInstance().getDataFactory(); final SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US); timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // Key conditions Map<String, Condition> keyConditions = new HashMap<>(); // uid = modelId Condition modelIdCond = new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue(metricName)); keyConditions.put("metric_name", modelIdCond); Condition timestampCondition; if (from != null && to != null) { // timestamp >= from and timestamp <=to timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN) .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(from)), new AttributeValue().withS(timestampFormat.format(to))); keyConditions.put("agg_ts", timestampCondition); } else if (from != null) { // timestamp >= from timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(from))); keyConditions.put("agg_ts", timestampCondition); } else if (to != null) { // timestamp <= to timestampCondition = new Condition().withComparisonOperator(ComparisonOperator.LT) .withAttributeValueList(new AttributeValue().withS(timestampFormat.format(to))); keyConditions.put("agg_ts", timestampCondition); } // Prepare query request QueryRequest query = new QueryRequest().withTableName(TWEETS_TABLE) .withAttributesToGet("tweet_uid", "userid", "text", "username", "agg_ts", "created_at", "retweet_count") .withKeyConditions(keyConditions).withScanIndexForward(false) .withIndexName("taurus.metric_data-metric_name_index"); QueryResult result; String tweetId; String userId; String userName; String text; Date created; Date aggregated; AttributeValue retweet; int retweetCount; Map<String, AttributeValue> lastKey; try { do { // Get results result = _awsClient.query(query); for (Map<String, AttributeValue> item : result.getItems()) { tweetId = item.get("tweet_uid").getS(); userId = item.get("userid").getS(); text = item.get("text").getS(); userName = item.get("username").getS(); aggregated = DataUtils.parseGrokDate(item.get("agg_ts").getS()); created = DataUtils.parseGrokDate(item.get("created_at").getS()); // "retweet_count" is optional retweet = item.get("retweet_count"); if (retweet != null && retweet.getN() != null) { retweetCount = Integer.parseInt(retweet.getN()); } else { retweetCount = 0; } if (!callback.onData(dataFactory.createTweet(tweetId, aggregated, created, userId, userName, text, retweetCount))) { // Canceled by the user break; } } // Make sure to get all pages lastKey = result.getLastEvaluatedKey(); query.setExclusiveStartKey(lastKey); } while (lastKey != null); } catch (AmazonClientException e) { // Wraps Amazon's unchecked exception as IOException throw new IOException(e); } }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.java
License:Apache License
protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part, Iterator<Object> iterator) { if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS)) throw new UnsupportedOperationException("Case insensitivity not supported"); Class<?> leafNodePropertyType = part.getProperty().getLeafProperty().getType(); PropertyPath leafNodePropertyPath = part.getProperty().getLeafProperty(); String leafNodePropertyName = leafNodePropertyPath.toDotPath(); if (leafNodePropertyName.indexOf(".") != -1) { int index = leafNodePropertyName.lastIndexOf("."); leafNodePropertyName = leafNodePropertyName.substring(index); }/* w ww .jav a2 s . co m*/ switch (part.getType()) { case IN: Object in = iterator.next(); Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '" + leafNodePropertyName + "'"); boolean isIterable = ClassUtils.isAssignable(Iterable.class, in.getClass()); boolean isArray = ObjectUtils.isArray(in); Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters"); Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in)); return criteria.withPropertyIn(leafNodePropertyName, iterable, leafNodePropertyType); case CONTAINING: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.CONTAINS, iterator.next(), leafNodePropertyType); case STARTING_WITH: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.BEGINS_WITH, iterator.next(), leafNodePropertyType); case BETWEEN: Object first = iterator.next(); Object second = iterator.next(); return criteria.withPropertyBetween(leafNodePropertyName, first, second, leafNodePropertyType); case AFTER: case GREATER_THAN: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GT, iterator.next(), leafNodePropertyType); case BEFORE: case LESS_THAN: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LT, iterator.next(), leafNodePropertyType); case GREATER_THAN_EQUAL: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GE, iterator.next(), leafNodePropertyType); case LESS_THAN_EQUAL: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LE, iterator.next(), leafNodePropertyType); case IS_NULL: return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NULL); case IS_NOT_NULL: return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NOT_NULL); case TRUE: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.TRUE, leafNodePropertyType); case FALSE: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.FALSE, leafNodePropertyType); case SIMPLE_PROPERTY: return criteria.withPropertyEquals(leafNodePropertyName, iterator.next(), leafNodePropertyType); case NEGATING_SIMPLE_PROPERTY: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.NE, iterator.next(), leafNodePropertyType); default: throw new IllegalArgumentException("Unsupported keyword " + part.getType()); } }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java
License:Apache License
public boolean comparisonOperatorsPermittedForQuery() { List<ComparisonOperator> comparisonOperatorsPermittedForQuery = Arrays.asList(new ComparisonOperator[] { ComparisonOperator.EQ, ComparisonOperator.LE, ComparisonOperator.LT, ComparisonOperator.GE, ComparisonOperator.GT, ComparisonOperator.BEGINS_WITH, ComparisonOperator.BETWEEN }); // Can only query on subset of Conditions for (Collection<Condition> conditions : attributeConditions.values()) { for (Condition condition : conditions) { if (!comparisonOperatorsPermittedForQuery .contains(ComparisonOperator.fromValue(condition.getComparisonOperator()))) { return false; }/*from w w w . j av a 2s. c o m*/ } } return true; }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBQueryCreator.java
License:Apache License
protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part, Iterator<Object> iterator) { if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS)) throw new UnsupportedOperationException("Case insensitivity not supported"); Class<?> propertyType = part.getProperty().getType(); switch (part.getType()) { case IN:/*from w ww . j ava2 s . com*/ Object in = iterator.next(); Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '" + part.getProperty().getSegment() + "'"); boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class); boolean isArray = ObjectUtils.isArray(in); Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters"); Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in)); return criteria.withPropertyIn(part.getProperty().getSegment(), iterable, propertyType); case CONTAINING: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.CONTAINS, iterator.next(), propertyType); case STARTING_WITH: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.BEGINS_WITH, iterator.next(), propertyType); case BETWEEN: Object first = iterator.next(); Object second = iterator.next(); return criteria.withPropertyBetween(part.getProperty().getSegment(), first, second, propertyType); case AFTER: case GREATER_THAN: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GT, iterator.next(), propertyType); case BEFORE: case LESS_THAN: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LT, iterator.next(), propertyType); case GREATER_THAN_EQUAL: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GE, iterator.next(), propertyType); case LESS_THAN_EQUAL: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LE, iterator.next(), propertyType); case IS_NULL: return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NULL); case IS_NOT_NULL: return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NOT_NULL); case TRUE: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ, Boolean.TRUE, propertyType); case FALSE: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ, Boolean.FALSE, propertyType); case SIMPLE_PROPERTY: return criteria.withPropertyEquals(part.getProperty().getSegment(), iterator.next(), propertyType); case NEGATING_SIMPLE_PROPERTY: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.NE, iterator.next(), propertyType); default: throw new IllegalArgumentException("Unsupported keyword " + part.getType()); } }