本文整理汇总了Java中org.apache.calcite.avatica.util.Quoting类的典型用法代码示例。如果您正苦于以下问题:Java Quoting类的具体用法?Java Quoting怎么用?Java Quoting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Quoting类属于org.apache.calcite.avatica.util包,在下文中一共展示了Quoting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
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);
}
}
}
}
示例2: testDoubleQuotesForQuotingIdentifiers
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testDoubleQuotesForQuotingIdentifiers() throws Exception {
try {
test("ALTER SESSION SET `%s` = '%s'", PlannerSettings.QUOTING_IDENTIFIERS_KEY,
Quoting.DOUBLE_QUOTE.string);
testBuilder()
.sqlQuery("select \"employee_id\", \"full_name\" from cp.\"employee.json\" limit 1")
.ordered()
.baselineColumns("employee_id", "full_name")
.baselineValues(1L, "Sheri Nowmer")
.go();
// Other quoting characters are not acceptable while particular one is chosen,
// since calcite doesn't support parsing sql statements with several quoting identifiers characters
errorMsgTestHelper("select `employee_id`, `full_name` from cp.`employee.json` limit 1", "Encountered: \"`\"");
// Mix of different quotes in the one SQL statement is not acceptable
errorMsgTestHelper("select \"employee_id\", \"full_name\" from cp.`employee.json` limit 1", "Encountered: \"`\"");
} finally {
test("ALTER SESSION RESET %s", PlannerSettings.QUOTING_IDENTIFIERS_KEY);
}
}
示例3: testQuotingIdentifiersProperty
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testQuotingIdentifiersProperty() throws SQLException {
try {
// Test DoubleQuotes for the DrillProperty#QUOTING_IDENTIFIERS in connection URL
connection = connect("jdbc:drill:zk=local;quoting_identifiers='\"'");
dbmd = connection.getMetaData();
assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.DOUBLE_QUOTE.string));
reset();
// Test Brackets for the DrillProperty#QUOTING_IDENTIFIERS in connection URL
connection = connect("jdbc:drill:zk=local;quoting_identifiers=[");
dbmd = connection.getMetaData();
assertThat(dbmd.getIdentifierQuoteString(), equalTo(Quoting.BRACKET.string));
} finally {
reset();
}
}
示例4: getParser
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
public Parser getParser(String sql, Properties info)
throws SQLException {
SqlParser parser = SqlParser.create(sql,
SqlParser.configBuilder()
.setQuotedCasing(Casing.UNCHANGED)
.setUnquotedCasing(Casing.UNCHANGED)
.setQuoting(Quoting.DOUBLE_QUOTE)
.setParserFactory(QuarkParserImpl.FACTORY)
.build());
SqlNode sqlNode;
try {
sqlNode = parser.parseStmt();
} catch (SqlParseException e) {
throw new RuntimeException(
"parse failed: " + e.getMessage(), e);
}
if (sqlNode.getKind().equals(SqlKind.OTHER_DDL)) {
return new DDLParser();
} else {
return getSqlQueryParser(info);
}
}
示例5: buildPlanner
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
private Planner buildPlanner(QueryContext context) {
final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
final ChainedSqlOperatorTable opTab =
new ChainedSqlOperatorTable(
ImmutableList.of(SqlStdOperatorTable.instance(),
HiveSqlOperatorTable.instance(), catalogReader));
FrameworkConfig config = Frameworks.newConfigBuilder() //
.parserConfig(SqlParser.configBuilder()
.setQuotedCasing(Casing.UNCHANGED)
.setUnquotedCasing(Casing.TO_UPPER)
.setQuoting(Quoting.DOUBLE_QUOTE)
.build()) //
.defaultSchema(context.getDefaultSchema()) //
.operatorTable(opTab) //
.traitDefs(traitDefs) //
.convertletTable(StandardConvertletTable.INSTANCE)//
.programs(getPrograms()) //
.typeSystem(RelDataTypeSystem.DEFAULT) //
.build();
return Frameworks.getPlanner(config);
}
示例6: testBracketIdentifier
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test public void testBracketIdentifier() {
quoting = Quoting.BRACKET;
checkExp("ab", "`AB`");
checkExp(" [a \" b!c]", "`a \" b!c`");
checkExpFails(" ^`^a \" b!c`", "(?s).*Encountered.*");
checkExpFails(" ^\"^a \"\" b!c\"", "(?s).*Encountered.*");
checkExp("[x`y`z]", "`x``y``z`");
checkExpFails("^\"^x`y`z\"", "(?s).*Encountered.*");
checkExpFails("^`^x``y``z`", "(?s).*Encountered.*");
checkExp("[anything [even brackets]] is].[ok]",
"`anything [even brackets] is`.`ok`");
// What would be a call to the 'item' function in DOUBLE_QUOTE and BACK_TICK
// is a table alias.
check("select * from myMap[field], myArray[1 + 2]",
"SELECT *\n"
+ "FROM `MYMAP` AS `field`,\n"
+ "`MYARRAY` AS `1 + 2`");
check("select * from myMap [field], myArray [1 + 2]",
"SELECT *\n"
+ "FROM `MYMAP` AS `field`,\n"
+ "`MYARRAY` AS `1 + 2`");
}
示例7: testCaseInsensitive
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Tests using case-insensitive matching of identifiers. */
@Test public void testCaseInsensitive() {
final SqlTester tester1 = tester
.withCaseSensitive(false)
.withQuoting(Quoting.BRACKET);
final SqlTester tester2 = tester.withQuoting(Quoting.BRACKET);
tester1.checkQuery("select EMPNO from EMP");
tester1.checkQuery("select empno from emp");
tester1.checkQuery("select [empno] from [emp]");
tester1.checkQuery("select [E].[empno] from [emp] as e");
tester1.checkQuery("select t.[x] from (\n"
+ " select [E].[empno] as x from [emp] as e) as [t]");
// correlating variable
tester1.checkQuery(
"select * from emp as [e] where exists (\n"
+ "select 1 from dept where dept.deptno = [E].deptno)");
tester2.checkQueryFails(
"select * from emp as [e] where exists (\n"
+ "select 1 from dept where dept.deptno = ^[E]^.deptno)",
"(?s).*Table 'E' not found; did you mean 'e'\\?");
checkFails("select count(1), ^empno^ from emp",
"Expression 'EMPNO' is not being grouped");
}
示例8: testCaseInsensitiveTableAlias
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-319">[CALCITE-319]
* Table aliases should follow case-sensitivity policy</a>. */
@Test public void testCaseInsensitiveTableAlias() {
final SqlTester tester1 = tester
.withCaseSensitive(false)
.withQuoting(Quoting.BRACKET);
final SqlTester tester2 = tester.withQuoting(Quoting.BRACKET);
// Table aliases should follow case-sensitivity preference.
//
// In MySQL, table aliases are case-insensitive:
// mysql> select `D`.day from DAYS as `d`, DAYS as `D`;
// ERROR 1066 (42000): Not unique table/alias: 'D'
tester1.checkQueryFails("select count(*) from dept as [D], ^dept as [d]^",
"Duplicate relation name 'd' in FROM clause");
tester2.checkQuery("select count(*) from dept as [D], dept as [d]");
tester2.checkQueryFails("select count(*) from dept as [D], ^dept as [D]^",
"Duplicate relation name 'D' in FROM clause");
}
示例9: testCaseInsensitiveSubQuery
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/** Tests referencing columns from a sub-query that has duplicate column
* names. (The standard says it should be an error, but we don't right
* now.) */
@Test public void testCaseInsensitiveSubQuery() {
final SqlTester insensitive = tester
.withCaseSensitive(false)
.withQuoting(Quoting.BRACKET);
final SqlTester sensitive = tester
.withCaseSensitive(true)
.withQuoting(Quoting.BRACKET);
String sql = "select [e] from (\n"
+ "select empno as [e], deptno as d, 1 as [e] from EMP)";
sensitive.checkQuery(sql);
insensitive.checkQuery(sql);
String sql1 = "select e from (\n"
+ "select empno as [e], deptno as d, 1 as [E] from EMP)";
insensitive.checkQuery(sql1);
sensitive.checkQuery(sql1);
}
示例10: testServerMeta
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testServerMeta() throws Exception {
GetServerMetaResp resp = client.getServerMeta().get();
assertNotNull(resp);
assertEquals(RequestStatus.OK, resp.getStatus());
assertNotNull(resp.getServerMeta());
ServerMeta serverMeta = resp.getServerMeta();
logger.trace("Server metadata: {}", serverMeta);
assertEquals(Quoting.BACK_TICK.string, serverMeta.getIdentifierQuoteString());
}
示例11: testUpdateSql
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@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 = new JavaTypeFactoryImpl();
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));
}
@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());
}
示例12: getQuotingIdentifiers
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
/**
* @return Quoting enum for current quoting identifiers character
*/
public Quoting getQuotingIdentifiers() {
String quotingIdentifiersCharacter = options.getOption(QUOTING_IDENTIFIERS);
for (Quoting value : Quoting.values()) {
if (value.string.equals(quotingIdentifiersCharacter)) {
return value;
}
}
// this is never reached
throw UserException.validationError()
.message("Unknown quoting identifier character '%s'", quotingIdentifiersCharacter)
.build(logger);
}
示例13: testBracketsForQuotingIdentifiers
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Test
public void testBracketsForQuotingIdentifiers() throws Exception {
try {
test("ALTER SESSION SET `%s` = '%s'", PlannerSettings.QUOTING_IDENTIFIERS_KEY,
Quoting.BRACKET.string);
testBuilder()
.sqlQuery("select [employee_id], [full_name] from cp.[employee.json] limit 1")
.ordered()
.baselineColumns("employee_id", "full_name")
.baselineValues(1L, "Sheri Nowmer")
.go();
} finally {
test("ALTER SESSION RESET %s", PlannerSettings.QUOTING_IDENTIFIERS_KEY);
}
}
示例14: getIdentifierQuoteString
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@Override
public String getIdentifierQuoteString() throws SQLException {
throwIfClosed();
if (!getServerMetaSupported()) {
return Quoting.BACK_TICK.string;
}
return getServerMeta().getIdentifierQuoteString();
}
示例15: parseSql
import org.apache.calcite.avatica.util.Quoting; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private T parseSql(String sql) throws SQLException {
logger.debug("[parseSql]");
try {
SqlParser sqlParser = SqlParser.create(sql, SqlParser.configBuilder()
.setParserFactory(SqlParserImpl.FACTORY)
.setUnquotedCasing(Casing.TO_LOWER)
.setQuoting(Quoting.DOUBLE_QUOTE)
.build());
return (T) sqlParser.parseStmt();
} catch (SqlParseException exc) {
throw new SQLException("Could not parse sql: " + sql, exc);
}
}