Collection<SqlMoniker> hintList) { List<String> subNames = Util.skipLast(names);
/** Returns every element of a list but its last element. */ public static <E> List<E> skipLast(List<E> list) { return skipLast(list, 1); }
/** Returns every element of a list but its last element. */ public static <E> List<E> skipLast(List<E> list) { return skipLast(list, 1); }
public static void getSchemaObjectMonikers( SqlValidatorCatalogReader catalogReader, List<String> names, List<SqlMoniker> hints) { // Assume that the last name is 'dummy' or similar. List<String> subNames = Util.skipLast(names); // Try successively with catalog.schema, catalog and no prefix for (List<String> x : catalogReader.getSchemaPaths()) { final List<String> names2 = ImmutableList.<String>builder().addAll(x).addAll(subNames).build(); hints.addAll(catalogReader.getAllSchemaObjectNames(names2)); } }
public static void getSchemaObjectMonikers( SqlValidatorCatalogReader catalogReader, List<String> names, List<SqlMoniker> hints) { // Assume that the last name is 'dummy' or similar. List<String> subNames = Util.skipLast(names); // Try successively with catalog.schema, catalog and no prefix for (List<String> x : catalogReader.getSchemaPaths()) { final List<String> names2 = ImmutableList.<String>builder().addAll(x).addAll(subNames).build(); hints.addAll(catalogReader.getAllSchemaObjectNames(names2)); } }
public <T> T unwrap(Class<T> clazz) { if (clazz.isInstance(this)) { return clazz.cast(this); } if (clazz.isInstance(table)) { return clazz.cast(table); } if (table instanceof Wrapper) { final T t = ((Wrapper) table).unwrap(clazz); if (t != null) { return t; } } if (clazz == CalciteSchema.class) { return clazz.cast( Schemas.subSchema(((CalciteCatalogReader) schema).rootSchema, Util.skipLast(getQualifiedName()))); } return null; }
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = Util.skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = Util.skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
public <T> T unwrap(Class<T> clazz) { if (clazz.isInstance(this)) { return clazz.cast(this); } if (clazz.isInstance(table)) { return clazz.cast(table); } if (table instanceof Wrapper) { final T t = ((Wrapper) table).unwrap(clazz); if (t != null) { return t; } } if (clazz == CalciteSchema.class) { return clazz.cast( Schemas.subSchema(((CalciteCatalogReader) schema).rootSchema, Util.skipLast(getQualifiedName()))); } return null; }
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = Util.skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
/** Creates a call that concatenates patterns; * for use in {@link #match}. */ public RexNode patternConcat(Iterable<? extends RexNode> nodes) { final ImmutableList<RexNode> list = ImmutableList.copyOf(nodes); if (list.size() > 2) { // Convert into binary calls return patternConcat(patternConcat(Util.skipLast(list)), Util.last(list)); } final RelDataType t = getTypeFactory().createSqlType(SqlTypeName.NULL); return getRexBuilder().makeCall(t, SqlStdOperatorTable.PATTERN_CONCAT, list); }
/** Creates a call that concatenates patterns; * for use in {@link #match}. */ public RexNode patternConcat(Iterable<? extends RexNode> nodes) { final ImmutableList<RexNode> list = ImmutableList.copyOf(nodes); if (list.size() > 2) { // Convert into binary calls return patternConcat(patternConcat(Util.skipLast(list)), Util.last(list)); } final RelDataType t = getTypeFactory().createSqlType(SqlTypeName.NULL); return getRexBuilder().makeCall(t, SqlStdOperatorTable.PATTERN_CONCAT, list); }
private void registerTable(final List<String> names, final Table table) { assert names.get(0).equals(DEFAULT_CATALOG); final List<String> schemaPath = Util.skipLast(names); final String tableName = Util.last(names); final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, SqlNameMatchers.withCaseSensitive(true)); schema.add(tableName, table); }
protected void registerType(final List<String> names, final RelProtoDataType relProtoDataType) { assert names.get(0).equals(DEFAULT_CATALOG); final List<String> schemaPath = Util.skipLast(names); final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, SqlNameMatchers.withCaseSensitive(true)); schema.add(Util.last(names), relProtoDataType); }
private void registerTable(final List<String> names, final Table table) { assert names.get(0).equals(DEFAULT_CATALOG); final List<String> schemaPath = Util.skipLast(names); final String tableName = Util.last(names); final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, SqlNameMatchers.withCaseSensitive(true)); schema.add(tableName, table); }
protected void registerType(final List<String> names, final RelProtoDataType relProtoDataType) { assert names.get(0).equals(DEFAULT_CATALOG); final List<String> schemaPath = Util.skipLast(names); final CalciteSchema schema = SqlValidatorUtil.getSchema(rootSchema, schemaPath, SqlNameMatchers.withCaseSensitive(true)); schema.add(Util.last(names), relProtoDataType); }
/** * check if the schema provided is a valid schema: * <li>schema is not indicated (only one element in the names list)<li/> * * @param names list of schema and table names, table name is always the last element * @throws UserException if the schema is not valid. */ private void isValidSchema(final List<String> names) throws UserException { SchemaPlus defaultSchema = session.getDefaultSchema(this.rootSchema); String defaultSchemaCombinedPath = SchemaUtilites.getSchemaPath(defaultSchema); List<String> schemaPath = Util.skipLast(names); String schemaPathCombined = SchemaUtilites.getSchemaPath(schemaPath); String commonPrefix = SchemaUtilites.getPrefixSchemaPath(defaultSchemaCombinedPath, schemaPathCombined, parserConfig.caseSensitive()); boolean isPrefixDefaultPath = commonPrefix.length() == defaultSchemaCombinedPath.length(); List<String> fullSchemaPath = Strings.isNullOrEmpty(defaultSchemaCombinedPath) ? schemaPath : isPrefixDefaultPath ? schemaPath : ListUtils.union(SchemaUtilites.getSchemaPathAsList(defaultSchema), schemaPath); if (names.size() > 1 && (SchemaUtilites.findSchema(this.rootSchema, fullSchemaPath) == null && SchemaUtilites.findSchema(this.rootSchema, schemaPath) == null)) { SchemaUtilites.throwSchemaNotFoundException(defaultSchema, schemaPath); } }
/** * Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TypeEntry} in a * given schema whose type has the given name, possibly qualified. * * @param rootSchema root schema * @param typeName name of the type, may be qualified or fully-qualified * * @return TypeEntry with a table with the given name, or null */ public static CalciteSchema.TypeEntry getTypeEntry( CalciteSchema rootSchema, SqlIdentifier typeName) { final String name; final List<String> path; if (typeName.isSimple()) { path = ImmutableList.of(); name = typeName.getSimple(); } else { path = Util.skipLast(typeName.names); name = Util.last(typeName.names); } CalciteSchema schema = rootSchema; for (String p : path) { if (schema == rootSchema && SqlNameMatchers.withCaseSensitive(true).matches(p, schema.getName())) { continue; } schema = schema.getSubSchema(p, true); } return schema == null ? null : schema.getType(name, false); }
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { validateQuantifier(validator, call); // check DISTINCT/ALL List<SqlNode> operands = call.getOperandList(); if (operands.size() == 1) { // No CASE needed return operands.get(0); } SqlParserPos pos = call.getParserPosition(); SqlNodeList whenList = new SqlNodeList(pos); SqlNodeList thenList = new SqlNodeList(pos); // todo: optimize when know operand is not null. for (SqlNode operand : Util.skipLast(operands)) { whenList.add( SqlStdOperatorTable.IS_NOT_NULL.createCall(pos, operand)); thenList.add(SqlNode.clone(operand)); } SqlNode elseExpr = Util.last(operands); assert call.getFunctionQuantifier() == null; return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr); } }
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { validateQuantifier(validator, call); // check DISTINCT/ALL List<SqlNode> operands = call.getOperandList(); if (operands.size() == 1) { // No CASE needed return operands.get(0); } SqlParserPos pos = call.getParserPosition(); SqlNodeList whenList = new SqlNodeList(pos); SqlNodeList thenList = new SqlNodeList(pos); // todo: optimize when know operand is not null. for (SqlNode operand : Util.skipLast(operands)) { whenList.add( SqlStdOperatorTable.IS_NOT_NULL.createCall(pos, operand)); thenList.add(SqlNode.clone(operand)); } SqlNode elseExpr = Util.last(operands); assert call.getFunctionQuantifier() == null; return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr); } }