private boolean matchesUnquoted(String name, String idToAppend) { String recasedId = applyCasing(idToAppend, parserConfig.unquotedCasing()); return recasedId.regionMatches(!parserConfig.caseSensitive(), 0, name, 0, name.length()); }
private boolean matchesUnquoted(String name, String idToAppend) { String recasedId = applyCasing(idToAppend, parserConfig.unquotedCasing()); return recasedId.regionMatches(!parserConfig.caseSensitive(), 0, name, 0, name.length()); }
private CalciteCatalogReader createCatalogReader() { SchemaPlus rootSchema = FlinkPlannerImpl.rootSchema(this.defaultSchema); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(prop); return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(this.defaultSchema).path(null), this.typeFactory, connectionConfig); }
@Override public RelRoot expandView(RelDataType rowType, String queryString, SchemaPlus rootSchema, List<String> schemaPath) { final DrillCalciteCatalogReader catalogReader = new DrillCalciteCatalogReader( rootSchema, parserConfig.caseSensitive(), schemaPath, typeFactory, drillConfig, session); SchemaPlus schema = rootSchema; for (String s : schemaPath) { SchemaPlus newSchema = schema.getSubSchema(s); if (newSchema == null) { throw UserException .validationError() .message( "Failure while attempting to expand view. Requested schema %s not available in schema %s.", s, schema.getName()) .addContext("View Context", Joiner.on(", ").join(schemaPath)) .addContext("View SQL", queryString) .build(logger); } schema = newSchema; } SqlConverter parser = new SqlConverter(SqlConverter.this, schema, rootSchema, catalogReader); return expandView(queryString, parser); }
public SqlConverter(QueryContext context) { this.settings = context.getPlannerSettings(); this.util = context; this.functions = context.getFunctionRegistry(); this.parserConfig = new DrillParserConfig(settings); this.sqlToRelConverterConfig = new SqlToRelConverterConfig(); this.isInnerQuery = false; this.typeFactory = new JavaTypeFactoryImpl(DRILL_TYPE_SYSTEM); this.defaultSchema = context.getNewDefaultSchema(); this.rootSchema = rootSchema(defaultSchema); this.temporarySchema = context.getConfig().getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE); this.session = context.getSession(); this.drillConfig = context.getConfig(); this.catalog = new DrillCalciteCatalogReader( rootSchema, parserConfig.caseSensitive(), DynamicSchema.from(defaultSchema).path(null), typeFactory, drillConfig, session); this.opTab = new ChainedSqlOperatorTable(Arrays.asList(context.getDrillOperatorTable(), catalog)); this.costFactory = (settings.useDefaultCosting()) ? null : new DrillCostBase.DrillCostFactory(); this.validator = new DrillValidator(opTab, catalog, typeFactory, parserConfig.conformance()); validator.setIdentifierExpansion(true); cluster = null; }
/** * 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); } }
public static BlinkRelBuilder create(FrameworkConfig config) { JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(config.getTypeSystem()); VolcanoPlanner planner = new VolcanoPlanner(config.getCostFactory(), Contexts.empty()); planner.setExecutor(config.getExecutor()); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory)); CalciteSchema calciteSchema = CalciteSchema.from(config.getDefaultSchema()); Properties prop = new Properties(); prop.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(config.getParserConfig().caseSensitive())); CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(prop); RelOptSchema relOptSchema = new CalciteCatalogReader( calciteSchema, CalciteSchema.from(config.getDefaultSchema()).path(null), typeFactory, connectionConfig); return new BlinkRelBuilder(config.getContext(), cluster, relOptSchema); } }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
@Override public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, List<String> viewPath) { final DrillCalciteCatalogReader catalogReader = new DrillCalciteCatalogReader( rootSchema, parserConfig.caseSensitive(), schemaPath, typeFactory, drillConfig, session); final SqlConverter parser = new SqlConverter(SqlConverter.this, defaultSchema, rootSchema, catalogReader); return expandView(queryString, parser); }