Search in sources :

Example 1 with RelationMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata in project calcite by apache.

the class CassandraSchema method getClusteringOrder.

/**
 * Get the collation of all clustering key columns.
 *
 * @return A RelCollations representing the collation of all clustering keys
 */
public List<RelFieldCollation> getClusteringOrder(String columnFamily, boolean isView) {
    RelationMetadata table = getRelationMetadata(columnFamily, isView);
    Collection<ClusteringOrder> clusteringOrder = table.getClusteringColumns().values();
    List<RelFieldCollation> keyCollations = new ArrayList<>();
    int i = 0;
    for (ClusteringOrder order : clusteringOrder) {
        RelFieldCollation.Direction direction;
        switch(order) {
            case DESC:
                direction = RelFieldCollation.Direction.DESCENDING;
                break;
            case ASC:
            default:
                direction = RelFieldCollation.Direction.ASCENDING;
                break;
        }
        keyCollations.add(new RelFieldCollation(i, direction));
        i++;
    }
    return keyCollations;
}
Also used : RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) ArrayList(java.util.ArrayList) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) RelationMetadata(com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata)

Aggregations

ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)1 RelationMetadata (com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata)1 ArrayList (java.util.ArrayList)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1