public ParserConfig cloneWithSystemDefault(){ if(quoting == QUOTING && !supportFullyQualifiedProjections){ return this; } return new ParserConfig(QUOTING, identifierMaxLength); }
@Override public boolean allowBangEqual() { return conformance().isBangEqualAllowed(); }
@Override public GetServerMetaResp execute() throws Exception { final GetServerMetaResp.Builder respBuilder = GetServerMetaResp.newBuilder(); final ServerMeta.Builder metaBuilder = session.getRecordBatchFormat() != RecordBatchFormat.DRILL_1_0 ? ServerMeta.newBuilder(DEFAULT) : ServerMeta.newBuilder(DRILL_1_0_DEFAULT); PlannerSettings plannerSettings = new PlannerSettings(dContext.getConfig(), session.getOptions(), dContext.getClusterResourceInformation()); ParserConfig config = ParserConfig.newInstance(session, plannerSettings); int identifierMaxLength = config.identifierMaxLength(); Metadata metadata = SqlParser.create("", config).getMetadata(); metaBuilder .setMaxCatalogNameLength(identifierMaxLength) .setMaxColumnNameLength(identifierMaxLength) .setMaxCursorNameLength(identifierMaxLength) .setMaxSchemaNameLength(identifierMaxLength) .setMaxTableNameLength(identifierMaxLength) .setMaxUserNameLength(identifierMaxLength) .setIdentifierQuoteString(config.quoting().string) .setIdentifierCasing(getIdentifierCasing(config.unquotedCasing(), config.caseSensitive())) .setQuotedIdentifierCasing(getIdentifierCasing(config.quotedCasing(), config.caseSensitive())) .addAllSqlKeywords(Splitter.on(",").split(metadata.getJdbcKeywords())); respBuilder.setServerMeta(metaBuilder); respBuilder.setStatus(RequestStatus.OK); respBuilder.setQueryId(queryId); return respBuilder.build(); }
public SqlConverter(SqlConverter parent, DremioCatalogReader catalog) { this.nestingLevel = parent.nestingLevel + 1; // since this is level 1 or deeper, we need to use system defaults instead of any overridden edge parser. this.parserConfig = parent.parserConfig.cloneWithSystemDefault(); this.substitutions = parent.substitutions; this.functions = parent.functions; this.session = parent.session; this.functionContext = parent.functionContext; this.isInnerQuery = true; this.observer = parent.observer; this.typeFactory = parent.typeFactory; this.costFactory = parent.costFactory; this.settings = parent.settings; this.flattenCounter = parent.flattenCounter; this.cluster = parent.cluster; this.catalogReader = catalog; this.opTab = parent.opTab; this.planner = parent.planner; this.materializations = parent.materializations; this.validator = new SqlValidatorImpl(parent.flattenCounter, opTab, catalog, typeFactory, DremioSqlConformance.INSTANCE); validator.setIdentifierExpansion(true); this.viewExpansionContext = parent.viewExpansionContext; this.config = parent.config; this.scanResult = parent.scanResult; }
this.functions = functions; this.session = Preconditions.checkNotNull(session, "user session is required"); this.parserConfig = ParserConfig.newInstance(session, settings); this.isInnerQuery = false; this.typeFactory = JavaTypeFactoryImpl.INSTANCE;
public static void main(String[] args) throws Exception { if (args.length != 1) { throw new IllegalArgumentException("Usage: java {cp} " + SqlReservedKeywordGenerator.class.getName() + " path/where/to/write/the/file"); } final File outputFile = new File(args[0], RESERVED_KEYWORD_FILE_NAME); System.out.println("Writing reserved SQL keywords to file: " + outputFile.getAbsolutePath()); try(PrintWriter outFile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputFile), UTF_8))) { outFile.printf("# AUTO-GENERATED LIST OF SQL RESERVED KEYWORDS (generated by %s)", SqlReservedKeywordGenerator.class.getName()); outFile.println(); final SqlAbstractParserImpl.Metadata metadata = SqlParser.create("", new ParserConfig(Quoting.DOUBLE_QUOTE, 256)).getMetadata(); for (String s : metadata.getTokens()) { if (metadata.isKeyword(s) && metadata.isReservedWord(s)) { outFile.println(s); } } } } }
public static ParserConfig newInstance(UserSession session, PlannerSettings settings) { Quoting quote = session.getInitialQuoting() != null ? session.getInitialQuoting() : ParserConfig.QUOTING; return new ParserConfig(quote, settings.getIdentifierMaxLength(), session.supportFullyQualifiedProjections()); }
private SqlNode parse(String toParse) throws SqlParseException{ ParserConfig config = new ParserConfig(Quoting.DOUBLE_QUOTE, 255); SqlParser parser = SqlParser.create(toParse, config); return parser.parseStmt(); }
private SqlNode parse(String toParse) throws SqlParseException{ ParserConfig config = new ParserConfig(Quoting.DOUBLE_QUOTE, 255); SqlParser parser = SqlParser.create(toParse, config); return parser.parseStmt(); }
@Test public void testUpdateSql() throws Exception { final String sql = "select foo, bar as b from tbl"; SqlParser parser = SqlParser.create(sql, new ParserConfig(Quoting.DOUBLE_QUOTE, 128)); final SqlNode sqlNode = parser.parseStmt(); final JavaTypeFactory typeFactory = JavaTypeFactoryImpl.INSTANCE; final RelDataType rowType = new RelRecordType(Arrays.<RelDataTypeField>asList( new RelDataTypeFieldImpl("foo", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)), new RelDataTypeFieldImpl("b", 0, typeFactory.createSqlType(SqlTypeName.INTEGER)) )); TransformActor actor = new TransformActor(state, false, "test_user", null) { @Override protected QueryMetadata getMetadata(SqlQuery query) { return new QueryMetadata(null, null, null, null, sqlNode, rowType, null, null, null, null, BatchSchema.fromCalciteRowType(rowType), null); } @Override protected boolean hasMetadata() { return true; } }; TransformResult result = new TransformUpdateSQL(sql).accept(actor); VirtualDatasetState newState = result.getNewState(); assertEquals(2, newState.getColumnsList().size()); assertEquals("foo", newState.getColumnsList().get(0).getName()); assertEquals(new ExpColumnReference("foo").wrap(), newState.getColumnsList().get(0).getValue()); assertEquals("b", newState.getColumnsList().get(1).getName()); assertEquals(new ExpColumnReference("bar").wrap(), newState.getColumnsList().get(1).getValue()); }