com.amazonaws.services.dynamodbv2.model.Select Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.Select. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DyUser.java    From jare with MIT License 6 votes vote down vote up
@Override
public Iterable<Domain> mine() {
    return this.table()
        .frame()
        .through(
            new QueryValve()
                .withSelect(Select.ALL_ATTRIBUTES)
                .withLimit(Tv.HUNDRED)
                .withConsistentRead(false)
                .withIndexName("mine")
        )
        .where("user", Conditions.equalTo(this.handle))
        .stream()
        .map(DyDomain::new)
        .map(Domain.class::cast)
        .collect(Collectors.toList());
}
 
Example #2
Source File: DyBase.java    From jare with MIT License 6 votes vote down vote up
@Override
public Iterable<Domain> domain(final String name) {
    return this.table()
        .frame()
        .through(
            new QueryValve()
                .withSelect(Select.ALL_ATTRIBUTES)
                .withLimit(1)
                .withConsistentRead(true)
        )
        .where(
            "domain",
            Conditions.equalTo(name.toLowerCase(Locale.ENGLISH))
        )
        .stream()
        .map(DyDomain::new)
        .map(Domain.class::cast)
        .collect(Collectors.toList());
}
 
Example #3
Source File: Mistakes.java    From jpeek with MIT License 5 votes vote down vote up
/**
 * Worst metrics.
 * @return List of them
 * @throws IOException If fails
 */
public Iterable<Iterable<Directive>> worst() throws IOException {
    return new Mapped<>(
        item -> new Directives()
            .add("metric")
            .attr("id", item.get("metric").getS())
            .add("pos").set(item.get("pos").getN()).up()
            .add("neg").set(item.get("neg").getN()).up()
            .add("psum").set(new DyNum(item, "psum").doubleValue()).up()
            .add("pavg").set(new DyNum(item, "pavg").doubleValue()).up()
            .add("nsum").set(new DyNum(item, "nsum").doubleValue()).up()
            .add("navg").set(new DyNum(item, "navg").doubleValue()).up()
            .add("avg").set(new DyNum(item, "avg").doubleValue()).up()
            .add("champions").set(item.get("champions").getN()).up()
            .add("artifact").set(item.get("artifact").getS()).up()
            .add("mean").set(new DyNum(item, "mean").doubleValue()).up()
            .add("sigma").set(new DyNum(item, "sigma").doubleValue()).up()
            .up(),
        this.table.frame()
            .where("version", new Version().value())
            .through(
                new QueryValve()
                    .withScanIndexForward(false)
                    .withIndexName("mistakes")
                    .withConsistentRead(false)
                    // @checkstyle MagicNumber (1 line)
                    .withLimit(20)
                    .withSelect(Select.ALL_ATTRIBUTES)
            )
    );
}
 
Example #4
Source File: LowLevelLocalSecondaryIndexExample.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void query(String indexName) {

        System.out.println("\n***********************************************************\n");
        System.out.println("Querying table " + tableName + "...");

        QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withConsistentRead(true)
            .withScanIndexForward(true).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

        HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();

        keyConditions.put("CustomerId", new Condition().withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS("[email protected]")));

        if (indexName == "IsOpenIndex") {
            System.out.println("\nUsing index: '" + indexName + "': Bob's orders that are open.");
            System.out.println("Only a user-specified list of attributes are returned\n");
            queryRequest.setIndexName(indexName);

            keyConditions.put("IsOpen", new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withN("1")));

            // ProjectionExpression
            queryRequest.setProjectionExpression("OrderCreationDate, ProductCategory, ProductName, OrderStatus");

        }
        else if (indexName == "OrderCreationDateIndex") {
            System.out.println("\nUsing index: '" + indexName + "': Bob's orders that were placed after 01/31/2013.");
            System.out.println("Only the projected attributes are returned\n");
            queryRequest.setIndexName(indexName);

            keyConditions.put("OrderCreationDate", new Condition().withComparisonOperator(ComparisonOperator.GT)
                .withAttributeValueList(new AttributeValue().withN("20130131")));

            // Select
            queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);

        }
        else {
            System.out.println("\nNo index: All of Bob's orders, by OrderId:\n");
        }

        queryRequest.setKeyConditions(keyConditions);

        QueryResult result = client.query(queryRequest);
        List<Map<String, AttributeValue>> items = result.getItems();
        Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
        while (itemsIter.hasNext()) {
            Map<String, AttributeValue> currentItem = itemsIter.next();

            Iterator<String> currentItemIter = currentItem.keySet().iterator();
            while (currentItemIter.hasNext()) {
                String attr = (String) currentItemIter.next();
                if (attr == "OrderId" || attr == "IsOpen" || attr == "OrderCreationDate") {
                    System.out.println(attr + "---> " + currentItem.get(attr).getN());
                }
                else {
                    System.out.println(attr + "---> " + currentItem.get(attr).getS());
                }
            }
            System.out.println();
        }
        System.out.println("\nConsumed capacity: " + result.getConsumedCapacity() + "\n");

    }
 
Example #5
Source File: Sigmas.java    From jpeek with MIT License 4 votes vote down vote up
/**
 * Add one metric.
 * @param metric XML with metric
 * @throws IOException If fails
 */
private void add(final XML metric) throws IOException {
    final Item item;
    final Iterator<Item> items = this.table.frame()
        .through(
            new QueryValve()
                .withLimit(1)
                .withSelect(Select.ALL_ATTRIBUTES)
        )
        .where("metric", metric.xpath("@name").get(0))
        .where("version", new Version().value())
        .iterator();
    if (items.hasNext()) {
        item = items.next();
    } else {
        item = this.table.put(
            new Attributes()
                .with("metric", metric.xpath("@name").get(0))
                .with("version", new Version().value())
                .with("artifact", "?")
                .with("champions", 0L)
                // @checkstyle MagicNumber (2 lines)
                .with("mean", new DyNum(0.5d).longValue())
                .with("sigma", new DyNum(0.1d).longValue())
        );
    }
    final double mean = Double.parseDouble(
        metric.xpath("mean/text()").get(0)
    );
    final double sigma = Double.parseDouble(
        metric.xpath("sigma/text()").get(0)
    );
    final boolean reverse = Boolean.parseBoolean(
        metric.xpath("reverse/text()").get(0)
    );
    final double mbefore = new DyNum(item, "mean").doubleValue();
    final double sbefore = new DyNum(item, "sigma").doubleValue();
    // @checkstyle BooleanExpressionComplexityCheck (1 line)
    if (sigma < sbefore || mean < mbefore && reverse
        || mean > mbefore && !reverse) {
        item.put(
            new AttributeUpdates()
                .with("artifact", metric.xpath("/index/@artifact").get(0))
                .with(
                    "champions",
                    new AttributeValueUpdate()
                        .withValue(new AttributeValue().withN("1"))
                        .withAction(AttributeAction.ADD)
                )
                .with("mean", new DyNum(mean).update())
                .with("sigma", new DyNum(sigma).update())
        );
    }
}
 
Example #6
Source File: LowLevelGlobalSecondaryIndexExample.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void queryIndex(String indexName) {

        System.out.println("\n***********************************************************\n");
        System.out.print("Querying index " + indexName + "...");

        QueryRequest queryRequest = new QueryRequest().withTableName(tableName).withIndexName(indexName)
            .withScanIndexForward(true);

        HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();

        if (indexName == "CreateDateIndex") {
            System.out.println("Issues filed on 2013-11-01");
            keyConditions.put("CreateDate", new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("2013-11-01")));
            keyConditions.put("IssueId", new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                .withAttributeValueList(new AttributeValue().withS("A-")));

        }
        else if (indexName == "TitleIndex") {
            System.out.println("Compilation errors");

            keyConditions.put("Title", new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("Compilation error")));
            keyConditions.put("IssueId", new Condition().withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                .withAttributeValueList(new AttributeValue().withS("A-")));

            // Select
            queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);

        }
        else if (indexName == "DueDateIndex") {
            System.out.println("Items that are due on 2013-11-30");

            keyConditions.put("DueDate", new Condition().withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("2013-11-30")));

            // Select
            queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);

        }
        else {
            System.out.println("\nNo valid index name provided");
            return;
        }

        queryRequest.setKeyConditions(keyConditions);

        QueryResult result = client.query(queryRequest);

        List<Map<String, AttributeValue>> items = result.getItems();
        Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();

        System.out.println();

        while (itemsIter.hasNext()) {
            Map<String, AttributeValue> currentItem = itemsIter.next();

            Iterator<String> currentItemIter = currentItem.keySet().iterator();
            while (currentItemIter.hasNext()) {
                String attr = (String) currentItemIter.next();
                if (attr == "Priority") {
                    System.out.println(attr + "---> " + currentItem.get(attr).getN());
                }
                else {
                    System.out.println(attr + "---> " + currentItem.get(attr).getS());
                }
            }
            System.out.println();
        }

    }
 
Example #7
Source File: AbstractDynamoDBQueryCriteria.java    From spring-data-dynamodb with Apache License 2.0 4 votes vote down vote up
protected QueryRequest buildQueryRequest(String tableName, String theIndexName, String hashKeyAttributeName,
		String rangeKeyAttributeName, String rangeKeyPropertyName, List<Condition> hashKeyConditions,
		List<Condition> rangeKeyConditions) {

	// TODO Set other query request properties based on config
	QueryRequest queryRequest = new QueryRequest();
	queryRequest.setTableName(tableName);
	queryRequest.setIndexName(theIndexName);

	if (isApplicableForGlobalSecondaryIndex()) {
		List<String> allowedSortProperties = new ArrayList<String>();

		for (Entry<String, List<Condition>> singlePropertyCondition : propertyConditions.entrySet()) {
			if (entityInformation.getGlobalSecondaryIndexNamesByPropertyName().keySet()
					.contains(singlePropertyCondition.getKey())) {
				allowedSortProperties.add(singlePropertyCondition.getKey());
			}
		}

		HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();

		if (hashKeyConditions != null && hashKeyConditions.size() > 0) {
			for (Condition hashKeyCondition : hashKeyConditions) {
				keyConditions.put(hashKeyAttributeName, hashKeyCondition);
				allowedSortProperties.add(hashKeyPropertyName);
			}
		}
		if (rangeKeyConditions != null && rangeKeyConditions.size() > 0) {
			for (Condition rangeKeyCondition : rangeKeyConditions) {
				keyConditions.put(rangeKeyAttributeName, rangeKeyCondition);
				allowedSortProperties.add(rangeKeyPropertyName);
			}
		}

		for (Entry<String, List<Condition>> singleAttributeConditions : attributeConditions.entrySet()) {

			for (Condition condition : singleAttributeConditions.getValue()) {
				keyConditions.put(singleAttributeConditions.getKey(), condition);
			}
		}

		queryRequest.setKeyConditions(keyConditions);
		queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
		applySortIfSpecified(queryRequest, new ArrayList<String>(new HashSet<String>(allowedSortProperties)));
	}
	return queryRequest;
}
 
Example #8
Source File: LowLevelLocalSecondaryIndexExample.java    From aws-dynamodb-examples with Apache License 2.0 4 votes vote down vote up
public static void query(String indexName) {

        System.out.println("\n***********************************************************\n");
        System.out.println("Querying table " + tableName + "...");

        QueryRequest queryRequest = new QueryRequest()
            .withTableName(tableName)
            .withConsistentRead(true).withScanIndexForward(true)
            .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

        HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();

        keyConditions.put(
            "CustomerId",
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue()
                    .withS("[email protected]")));

        if (indexName == "IsOpenIndex") {
            System.out.println("\nUsing index: '" + indexName
                    + "': Bob's orders that are open.");
            System.out.println("Only a user-specified list of attributes are returned\n");
            queryRequest.setIndexName(indexName);
            
            keyConditions.put(
                "IsOpen",
                new Condition()
                    .withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withN("1")));
            
            // ProjectionExpression
            queryRequest.setProjectionExpression("OrderCreationDate, ProductCategory, ProductName, OrderStatus");

        } else if (indexName == "OrderCreationDateIndex") {
            System.out.println("\nUsing index: '" + indexName
                + "': Bob's orders that were placed after 01/31/2013.");
            System.out.println("Only the projected attributes are returned\n");
            queryRequest.setIndexName(indexName);
            
            keyConditions.put("OrderCreationDate", new Condition()
                .withComparisonOperator(ComparisonOperator.GT)
                .withAttributeValueList(new AttributeValue()
                    .withN("20130131")));
            
            // Select
            queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
            
        } else {
            System.out.println("\nNo index: All of Bob's orders, by OrderId:\n");
        }

        queryRequest.setKeyConditions(keyConditions);

        QueryResult result = client.query(queryRequest);
        List<Map<String, AttributeValue>> items = result.getItems();
        Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
        while (itemsIter.hasNext()) {
            Map<String, AttributeValue> currentItem = itemsIter.next();
            
            Iterator<String> currentItemIter = currentItem.keySet().iterator();
            while (currentItemIter.hasNext()) {
                String attr = (String) currentItemIter.next();
                if (attr == "OrderId" || attr == "IsOpen"
                        || attr == "OrderCreationDate") {
                    System.out.println(attr + "---> "
                            + currentItem.get(attr).getN());
                } else {
                    System.out.println(attr + "---> "
                            + currentItem.get(attr).getS());
                }
            }
            System.out.println();    
        }
        System.out.println("\nConsumed capacity: " + result.getConsumedCapacity() + "\n");

    }
 
Example #9
Source File: LowLevelGlobalSecondaryIndexExample.java    From aws-dynamodb-examples with Apache License 2.0 4 votes vote down vote up
public static void queryIndex(String indexName) {

    System.out.println
         ("\n***********************************************************\n");
    System.out.print("Querying index " + indexName + "...");

    QueryRequest queryRequest = new QueryRequest()
        .withTableName(tableName)
        .withIndexName(indexName)
        .withScanIndexForward(true);

    HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();

    if (indexName == "CreateDateIndex") {
        System.out.println("Issues filed on 2013-11-01");
        keyConditions.put("CreateDate",new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue()
                    .withS("2013-11-01")));
        keyConditions.put("IssueId",new Condition()
                .withComparisonOperator(ComparisonOperator.BEGINS_WITH)
                .withAttributeValueList(new AttributeValue().withS("A-")));

    } else if (indexName == "TitleIndex") {
        System.out.println("Compilation errors");

        keyConditions.put("Title",new Condition()
            .withComparisonOperator( ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue()
                    .withS("Compilation error")));
        keyConditions.put("IssueId", new Condition()
            .withComparisonOperator(ComparisonOperator.BEGINS_WITH)
            .withAttributeValueList(new AttributeValue().withS("A-")));

        // Select
        queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);

    } else if (indexName == "DueDateIndex") {
        System.out.println("Items that are due on 2013-11-30");

        keyConditions.put("DueDate",new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("2013-11-30")));

        // Select
        queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);

    } else {
        System.out.println("\nNo valid index name provided");
        return;
    }

    queryRequest.setKeyConditions(keyConditions);

    QueryResult result = client.query(queryRequest);
    
    List<Map<String, AttributeValue>> items = result.getItems();
    Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
    
    System.out.println();
    
    while (itemsIter.hasNext()) {
        Map<String, AttributeValue> currentItem = itemsIter.next();

        Iterator<String> currentItemIter = currentItem.keySet().iterator();
        while (currentItemIter.hasNext()) {
            String attr = (String) currentItemIter.next();
            if (attr == "Priority" ) {
                System.out.println(attr + "---> " + currentItem.get(attr).getN());
            } else {
                System.out.println(attr + "---> " + currentItem.get(attr).getS());
            }
        }
        System.out.println();
    }

}