public List<SqlMoniker> getAllSchemaObjectNames(List<String> names) { List<SqlMoniker> result; switch (names.size()) { case 0: // looking for schema names result = new ArrayList<SqlMoniker>(); for (MockSchema schema : schemas.values()) { result.add(new SqlMonikerImpl(schema.name, SqlMonikerType.Schema)); } return result; case 1: // looking for table names in the given schema MockSchema schema = schemas.get(names.get(0)); if (schema == null) { return Collections.emptyList(); } result = new ArrayList<SqlMoniker>(); for (String tableName : schema.tableNames) { result.add(new SqlMonikerImpl(tableName, SqlMonikerType.Table)); } return result; default: return Collections.emptyList(); } }
/** * Derives the list of column names suitable for NATURAL JOIN. These are the columns that occur * exactly once on each side of the join. * * @param leftRowType Row type of left input to the join * @param rightRowType Row type of right input to the join * @return List of columns that occur once on each side */ public static List<String> deriveNaturalJoinColumnList( RelDataType leftRowType, RelDataType rightRowType) { List<String> naturalColumnNames = new ArrayList<String>(); final List<String> leftNames = leftRowType.getFieldNames(); final List<String> rightNames = rightRowType.getFieldNames(); for (String name : leftNames) { if ((Collections.frequency(leftNames, name) == 1) && (Collections.frequency(rightNames, name) == 1)) { naturalColumnNames.add(name); } } return naturalColumnNames; }
public static RelDataType createTypeFromProjection( RelDataType type, List<String> columnNameList, RelDataTypeFactory typeFactory, boolean caseSensitive) { // If the names in columnNameList and type have case-sensitive differences, // the resulting type will use those from type. These are presumably more // canonical. final List<RelDataTypeField> fields = new ArrayList<RelDataTypeField>(columnNameList.size()); for (String name : columnNameList) { RelDataTypeField field = type.getField(name, caseSensitive); fields.add(type.getFieldList().get(field.getIndex())); } return typeFactory.createStructType(fields); }
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<String>(); int i = 0; while (newNames.size() < newNames2.length) { newNames.add(i, newNames2[i]); ++i; } names = newNames; } return createColumnSet(table, names, rowType, collationList); }
private static List<RelCollation> deduceMonotonicity(Prepare.PreparingTable table) { final List<RelCollation> collationList = new ArrayList<RelCollation>(); // Deduce which fields the table is sorted on. int i = -1; for (RelDataTypeField field : table.getRowType().getFieldList()) { ++i; final SqlMonotonicity monotonicity = table.getMonotonicity(field.getName()); if (monotonicity != SqlMonotonicity.NotMonotonic) { final RelFieldCollation.Direction direction = monotonicity.isDecreasing() ? RelFieldCollation.Direction.Descending : RelFieldCollation.Direction.Ascending; collationList.add( RelCollationImpl.of( new RelFieldCollation(i, direction, RelFieldCollation.NullDirection.UNSPECIFIED))); } } return collationList; }
private List<RelCollation> deduceMonotonicity(SqlValidatorTable table) { final RelDataType rowType = table.getRowType(); final List<RelCollation> collationList = new ArrayList<RelCollation>(); // 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( RelCollationImpl.of( new RelFieldCollation( i, direction, RelFieldCollation.NullDirection.UNSPECIFIED))); } } return collationList; }
public void add(SqlNode node) { list.add(node); }
public void addTable(String name) { tableNames.add(name); }