Search in sources :

Example 1 with ClusteringOrder

use of com.datastax.driver.core.ClusteringOrder 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 view) {
    AbstractTableMetadata table;
    if (view) {
        table = getKeyspace().getMaterializedView(columnFamily);
    } else {
        table = getKeyspace().getTable(columnFamily);
    }
    List<ClusteringOrder> clusteringOrder = table.getClusteringOrder();
    List<RelFieldCollation> keyCollations = new ArrayList<RelFieldCollation>();
    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 : AbstractTableMetadata(com.datastax.driver.core.AbstractTableMetadata) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) ArrayList(java.util.ArrayList) ClusteringOrder(com.datastax.driver.core.ClusteringOrder)

Aggregations

AbstractTableMetadata (com.datastax.driver.core.AbstractTableMetadata)1 ClusteringOrder (com.datastax.driver.core.ClusteringOrder)1 ArrayList (java.util.ArrayList)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1