Search in sources :

Example 1 with Direction

use of org.apache.calcite.rel.RelFieldCollation.Direction in project hive by apache.

the class RelOptHiveTable method getCollationList.

@Override
public List<RelCollation> getCollationList() {
    ImmutableList.Builder<RelFieldCollation> collationList = new ImmutableList.Builder<RelFieldCollation>();
    for (Order sortColumn : this.hiveTblMetadata.getSortCols()) {
        for (int i = 0; i < this.hiveTblMetadata.getSd().getCols().size(); i++) {
            FieldSchema field = this.hiveTblMetadata.getSd().getCols().get(i);
            if (field.getName().equals(sortColumn.getCol())) {
                Direction direction;
                NullDirection nullDirection;
                if (sortColumn.getOrder() == BaseSemanticAnalyzer.HIVE_COLUMN_ORDER_ASC) {
                    direction = Direction.ASCENDING;
                    nullDirection = NullDirection.FIRST;
                } else {
                    direction = Direction.DESCENDING;
                    nullDirection = NullDirection.LAST;
                }
                collationList.add(new RelFieldCollation(i, direction, nullDirection));
                break;
            }
        }
    }
    return new ImmutableList.Builder<RelCollation>().add(RelCollationTraitDef.INSTANCE.canonize(new HiveRelCollation(collationList.build()))).build();
}
Also used : Order(org.apache.hadoop.hive.metastore.api.Order) ImmutableList(com.google.common.collect.ImmutableList) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) Direction(org.apache.calcite.rel.RelFieldCollation.Direction) NullDirection(org.apache.calcite.rel.RelFieldCollation.NullDirection) NullDirection(org.apache.calcite.rel.RelFieldCollation.NullDirection)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1 Direction (org.apache.calcite.rel.RelFieldCollation.Direction)1 NullDirection (org.apache.calcite.rel.RelFieldCollation.NullDirection)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 Order (org.apache.hadoop.hive.metastore.api.Order)1