Tokenizer tokenizer = new Tokenizer(sql, hintToken, parserConfig.quoting()); List<Token> list = new ArrayList<>(); while (true) {
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); }
/** * Creates a <code>SqlParser</code> to parse the given string using the * parser implementation created from given {@link SqlParserImplFactory} * with given quoting syntax and casing policies for identifiers. * * @param sql A SQL statement or expression to parse. * @param config The parser configuration (identifier max length, etc.) * @return A parser */ public static SqlParser create(String sql, Config config) { SqlAbstractParserImpl parser = config.parserFactory().getParser(new StringReader(sql)); return new SqlParser(sql, parser, config); }
new SqlMonikerImpl(ImmutableList.of("*"), SqlMonikerType.KEYWORD); String hintToken = parserConfig.unquotedCasing() == Casing.TO_UPPER ? UPPER_HINT_TOKEN : HINT_TOKEN; if (hintList.contains(star) && !isSelectListItem(sqlNode, pos, hintToken)) { hintList.remove(star);
new SqlMonikerImpl(ImmutableList.of("*"), SqlMonikerType.KEYWORD); String hintToken = parserConfig.unquotedCasing() == Casing.TO_UPPER ? UPPER_HINT_TOKEN : HINT_TOKEN; if (hintList.contains(star) && !isSelectListItem(sqlNode, pos, hintToken)) { hintList.remove(star);
new StrTokenizer(storeTablePath, '.', config.quoting().string.charAt(0)) .setIgnoreEmptyTokens(true) .getTokenList();
Tokenizer tokenizer = new Tokenizer(sql, hintToken, parserConfig.quoting()); List<Token> list = new ArrayList<>(); while (true) {
@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); } }
private SqlConverter(SqlConverter parent, SchemaPlus defaultSchema, SchemaPlus rootSchema, DrillCalciteCatalogReader catalog) { this.parserConfig = parent.parserConfig; this.sqlToRelConverterConfig = parent.sqlToRelConverterConfig; this.defaultSchema = defaultSchema; this.functions = parent.functions; this.util = parent.util; this.isInnerQuery = true; this.typeFactory = parent.typeFactory; this.costFactory = parent.costFactory; this.settings = parent.settings; this.rootSchema = rootSchema; this.catalog = catalog; this.opTab = parent.opTab; this.planner = parent.planner; this.validator = new DrillValidator(opTab, catalog, typeFactory, parserConfig.conformance()); this.temporarySchema = parent.temporarySchema; this.session = parent.session; this.drillConfig = parent.drillConfig; validator.setIdentifierExpansion(true); this.cluster = parent.cluster; }
private SqlParser(String s, SqlAbstractParserImpl parser, Config config) { this.originalInput = s; this.parser = parser; parser.setOriginalSql(s); parser.setTabSize(1); parser.setQuotedCasing(config.quotedCasing()); parser.setUnquotedCasing(config.unquotedCasing()); parser.setIdentifierMaxLength(config.identifierMaxLength()); parser.setConformance(config.conformance()); switch (config.quoting()) { case DOUBLE_QUOTE: parser.switchTo("DQID"); break; case BACK_TICK: parser.switchTo("BTID"); break; case BRACKET: parser.switchTo("DEFAULT"); break; } }
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); } }
/** * Creates a <code>SqlParser</code> to parse the given string using the * parser implementation created from given {@link SqlParserImplFactory} * with given quoting syntax and casing policies for identifiers. * * <p>Unlike * {@link #create(java.lang.String, org.apache.calcite.sql.parser.SqlParser.Config)}, * the parser is not able to return the original query string, but will * instead return "?". * * @param reader The source for the SQL statement or expression to parse * @param config The parser configuration (identifier max length, etc.) * @return A parser */ public static SqlParser create(Reader reader, Config config) { SqlAbstractParserImpl parser = config.parserFactory().getParser(reader); return new SqlParser(parser, config); }
private SqlParser(SqlAbstractParserImpl parser, Config config) { this.parser = parser; parser.setTabSize(1); parser.setQuotedCasing(config.quotedCasing()); parser.setUnquotedCasing(config.unquotedCasing()); parser.setIdentifierMaxLength(config.identifierMaxLength()); parser.setConformance(config.conformance()); switch (config.quoting()) { case DOUBLE_QUOTE: parser.switchTo("DQID"); break; case BACK_TICK: parser.switchTo("BTID"); break; case BRACKET: parser.switchTo("DEFAULT"); break; } }
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 void assertTokenizesTo(String sql, String expected) { SqlSimpleParser.Tokenizer tokenizer = new SqlSimpleParser.Tokenizer(sql, "xxxxx", tester.getFactory().getParserConfig().quoting()); StringBuilder buf = new StringBuilder(); while (true) { SqlSimpleParser.Token token = tokenizer.nextToken(); if (token == null) { break; } buf.append(token).append("\n"); } Assert.assertEquals(expected, buf.toString()); }
private char quoteStart() { return parserConfig.quoting().string.charAt(0); }
private char quoteStart() { return parserConfig.quoting().string.charAt(0); }
private void assertTokenizesTo(String sql, String expected) { SqlSimpleParser.Tokenizer tokenizer = new SqlSimpleParser.Tokenizer(sql, "xxxxx", tester.getFactory().getParserConfig().quoting()); StringBuilder buf = new StringBuilder(); while (true) { SqlSimpleParser.Token token = tokenizer.nextToken(); if (token == null) { break; } buf.append(token).append("\n"); } Assert.assertEquals(expected, buf.toString()); }