com.datastax.oss.driver.api.core.cql.ColumnDefinitions Java Examples

The following examples show how to use com.datastax.oss.driver.api.core.cql.ColumnDefinitions. 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: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 4 votes vote down vote up
@Override
public DynamoDBResponse query(QueryRequest payload)
{
    logger.debug("query against JSON table");
    ResultSet resultSet;

    if (payload.getKeyConditionExpression() != null)
        resultSet = queryByKeyExpression(payload);
    else if (payload.getKeyConditions() != null)
        resultSet = queryByKeyCondition(payload);
    else
        throw new UnsupportedOperationException("un-supported query type");

   try
    {
        Collection<Map<String, AttributeValue>> items = new HashSet<Map<String, AttributeValue>>();
        for (Row row : resultSet)
        {
            AttributeValue item;
            ColumnDefinitions colDefs = row.getColumnDefinitions();
            Map<String, AttributeValue> keysSet = new HashMap<>();
            for (ColumnDefinition colDef : colDefs)
            {
                if (colDef.getName().asInternal().equals("json_blob"))
                    continue;

                item = rowToAV(colDef, row);
                keysSet.put(colDef.getName().asInternal(), item);
            }

            Map<String, AttributeValue> itemSet = blobToItemSet(row.getString("json_blob"));
            itemSet.putAll(keysSet);

            if (payload.getFilterExpression() != null){
                if(!matchesFilterExpression(itemSet, payload)){
                    continue;
                }
            }
            items.add(itemSet);
        }

        QueryResult queryResult = new QueryResult();
        queryResult.setItems(items);

        return new DynamoDBResponse(queryResult, 200);
    } catch (Throwable e) {
        logger.warn("Query error", e);

        DynamoDBResponse ddbResponse = new DynamoDBResponse(null, 500);
        String msg= String.format("query failed with error: %s", e.getMessage());
        ddbResponse.setError(msg);
        return ddbResponse;
    }
}
 
Example #2
Source File: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 4 votes vote down vote up
@Override
public DynamoDBResponse getItem(GetItemRequest getItemRequest) {
    logger.debug("get item from JSON table");

    String tableName = getItemRequest.getTableName();
    TableDef tableDef = cassandraManager.getTableDef(tableName);
    PreparedStatement selectStatement = tableDef.getQueryRowStatement();

    AttributeDefinition partitionKeyDef = tableDef.getPartitionKey();
    Optional<AttributeDefinition> clusteringKeyDef = tableDef.getClusteringKey();

    Map<String, AttributeValue> keys = getItemRequest.getKey();

    AttributeValue partitionKey = keys.get(partitionKeyDef.getAttributeName());
    AttributeValue clusteringKey = clusteringKeyDef.isPresent() ?
            keys.get(clusteringKeyDef.get().getAttributeName()) : null;

    ScalarAttributeType partitionKeyType = ScalarAttributeType.valueOf(partitionKeyDef.getAttributeType());
    ScalarAttributeType clusteringKeyType = clusteringKeyDef.isPresent() ?
            ScalarAttributeType.valueOf(clusteringKeyDef.get().getAttributeType()) : null;

    BoundStatement boundStatement = clusteringKey == null ?
            selectStatement.bind(getAttributeObject(partitionKeyType, partitionKey)) :
            selectStatement.bind(getAttributeObject(partitionKeyType, partitionKey),
                    getAttributeObject(clusteringKeyType, clusteringKey));

    ResultSet result = session().execute(boundStatement);

    GetItemResult gir = new GetItemResult();
    Map<String, AttributeValue> item = new HashMap<>();
    ColumnDefinitions colDefs = result.getColumnDefinitions();

    Row row = result.one();

    //Case that nothing is found
    if (row == null)
        return new DynamoDBResponse(null, 200);

    Map<String, AttributeValue> keysSet = new HashMap<>();
    for (ColumnDefinition colDef : colDefs)
    {
        if (colDef.getName().asInternal().equals("json_blob"))
            continue;

        keysSet.put(colDef.getName().asInternal(), rowToAV(colDef, row));
    }

    try
    {
        item = blobToItemSet(row.getString("json_blob"));
        item.putAll(keysSet);

        gir.withItem(item);
        return new DynamoDBResponse(gir, 200);
    } catch (IOException e) {
        DynamoDBResponse ddbResponse = new DynamoDBResponse(gir, 500);
        String msg = String.format("GetItem failed", getItemRequest.getTableName());
        ddbResponse.setError(msg);
        return ddbResponse;
    }
}
 
Example #3
Source File: ResultSetImpl.java    From vertx-cassandra-client with Apache License 2.0 4 votes vote down vote up
@Override
public ColumnDefinitions getColumnDefinitions() {
  return resultSetRef.get().getColumnDefinitions();
}
 
Example #4
Source File: InputFormatGrakn.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public ColumnDefinitions getColumnDefinitions() {
    return row.getColumnDefinitions();
}
 
Example #5
Source File: ResultSet.java    From vertx-cassandra-client with Apache License 2.0 2 votes vote down vote up
/**
 * @see AsyncResultSet#getColumnDefinitions()
 */
@GenIgnore(GenIgnore.PERMITTED_TYPE)
ColumnDefinitions getColumnDefinitions();