Java Code Examples for org.apache.calcite.sql.parser.SqlAbstractParserImpl#Metadata
The following examples show how to use
org.apache.calcite.sql.parser.SqlAbstractParserImpl#Metadata .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlReservedKeywordGenerator.java From dremio-oss with Apache License 2.0 | 6 votes |
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); } } } }
Example 2
Source File: BabelParserTest.java From calcite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} * * <p>Copy-pasted from base method, but with some key differences. */ @Override @Test protected void testMetadata() { SqlAbstractParserImpl.Metadata metadata = getSqlParser("").getMetadata(); assertThat(metadata.isReservedFunctionName("ABS"), is(true)); assertThat(metadata.isReservedFunctionName("FOO"), is(false)); assertThat(metadata.isContextVariableName("CURRENT_USER"), is(true)); assertThat(metadata.isContextVariableName("CURRENT_CATALOG"), is(true)); assertThat(metadata.isContextVariableName("CURRENT_SCHEMA"), is(true)); assertThat(metadata.isContextVariableName("ABS"), is(false)); assertThat(metadata.isContextVariableName("FOO"), is(false)); assertThat(metadata.isNonReservedKeyword("A"), is(true)); assertThat(metadata.isNonReservedKeyword("KEY"), is(true)); assertThat(metadata.isNonReservedKeyword("SELECT"), is(false)); assertThat(metadata.isNonReservedKeyword("FOO"), is(false)); assertThat(metadata.isNonReservedKeyword("ABS"), is(true)); // was false assertThat(metadata.isKeyword("ABS"), is(true)); assertThat(metadata.isKeyword("CURRENT_USER"), is(true)); assertThat(metadata.isKeyword("CURRENT_CATALOG"), is(true)); assertThat(metadata.isKeyword("CURRENT_SCHEMA"), is(true)); assertThat(metadata.isKeyword("KEY"), is(true)); assertThat(metadata.isKeyword("SELECT"), is(true)); assertThat(metadata.isKeyword("HAVING"), is(true)); assertThat(metadata.isKeyword("A"), is(true)); assertThat(metadata.isKeyword("BAR"), is(false)); assertThat(metadata.isReservedWord("SELECT"), is(true)); assertThat(metadata.isReservedWord("CURRENT_CATALOG"), is(false)); // was true assertThat(metadata.isReservedWord("CURRENT_SCHEMA"), is(false)); // was true assertThat(metadata.isReservedWord("KEY"), is(false)); String jdbcKeywords = metadata.getJdbcKeywords(); assertThat(jdbcKeywords.contains(",COLLECT,"), is(false)); // was true assertThat(!jdbcKeywords.contains(",SELECT,"), is(true)); }
Example 3
Source File: DocumentationTest.java From calcite with Apache License 2.0 | 4 votes |
/** Generates a copy of {@code reference.md} with the current set of key * words. Fails if the copy is different from the original. */ @Test void testGenerateKeyWords() throws IOException { final FileFixture f = new FileFixture(); f.outFile.getParentFile().mkdirs(); try (BufferedReader r = Util.reader(f.inFile); FileOutputStream fos = new FileOutputStream(f.outFile); PrintWriter w = Util.printWriter(f.outFile)) { String line; int stage = 0; while ((line = r.readLine()) != null) { if (line.equals("{% comment %} end {% endcomment %}")) { ++stage; } if (stage != 1) { w.println(line); } if (line.equals("{% comment %} start {% endcomment %}")) { ++stage; SqlAbstractParserImpl.Metadata metadata = new SqlParserTest().getSqlParser("").getMetadata(); int z = 0; for (String s : metadata.getTokens()) { if (z++ > 0) { w.println(","); } if (metadata.isKeyword(s)) { w.print(metadata.isReservedWord(s) ? ("**" + s + "**") : s); } } w.println("."); } } w.flush(); fos.flush(); fos.getFD().sync(); } String diff = DiffTestCase.diff(f.outFile, f.inFile); if (!diff.isEmpty()) { throw new AssertionError("Mismatch between " + f.outFile + " and " + f.inFile + ":\n" + diff); } }
Example 4
Source File: SqlAdvisor.java From Bats with Apache License 2.0 | 2 votes |
/** * Returns the underlying Parser metadata. * * <p>To use a different parser (recognizing a different dialect of SQL), * derived class should override. * * @return metadata */ protected SqlAbstractParserImpl.Metadata getParserMetadata() { SqlParser parser = SqlParser.create("", parserConfig); return parser.getMetadata(); }
Example 5
Source File: SqlAdvisor.java From calcite with Apache License 2.0 | 2 votes |
/** * Returns the underlying Parser metadata. * * <p>To use a different parser (recognizing a different dialect of SQL), * derived class should override. * * @return metadata */ protected SqlAbstractParserImpl.Metadata getParserMetadata() { SqlParser parser = SqlParser.create("", parserConfig); return parser.getMetadata(); }