org.apache.calcite.sql.validate.SqlValidatorTable Java Examples

The following examples show how to use org.apache.calcite.sql.validate.SqlValidatorTable. 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: SqlToRelTestBase.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RelOptTable getTableForMember(List<String> names) {
  final SqlValidatorTable table =
      catalogReader.getTable(names);
  final RelDataType rowType = table.getRowType();
  final List<RelCollation> collationList = deduceMonotonicity(table);
  if (names.size() < 3) {
    String[] newNames2 = {"CATALOG", "SALES", ""};
    List<String> newNames = new ArrayList<>();
    int i = 0;
    while (newNames.size() < newNames2.length) {
      newNames.add(i, newNames2[i]);
      ++i;
    }
    names = newNames;
  }
  return createColumnSet(table, names, rowType, collationList);
}
 
Example #2
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 6 votes vote down vote up
private List<RelCollation> deduceMonotonicity(SqlValidatorTable table) {
  final RelDataType rowType = table.getRowType();
  final List<RelCollation> collationList = new ArrayList<>();

  // Deduce which fields the table is sorted on.
  int i = -1;
  for (RelDataTypeField field : rowType.getFieldList()) {
    ++i;
    final SqlMonotonicity monotonicity =
        table.getMonotonicity(field.getName());
    if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
      final RelFieldCollation.Direction direction =
          monotonicity.isDecreasing()
              ? RelFieldCollation.Direction.DESCENDING
              : RelFieldCollation.Direction.ASCENDING;
      collationList.add(
          RelCollations.of(new RelFieldCollation(i, direction)));
    }
  }
  return collationList;
}
 
Example #3
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 5 votes vote down vote up
protected MockColumnSet createColumnSet(
    SqlValidatorTable table,
    List<String> names,
    final RelDataType rowType,
    final List<RelCollation> collationList) {
  return new MockColumnSet(names, rowType, collationList);
}