本文整理汇总了Java中org.apache.calcite.sql.SqlDialect类的典型用法代码示例。如果您正苦于以下问题:Java SqlDialect类的具体用法?Java SqlDialect怎么用?Java SqlDialect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlDialect类属于org.apache.calcite.sql包,在下文中一共展示了SqlDialect类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public static JournalledJdbcSchema create(
SchemaPlus parentSchema,
String name,
Map<String, Object> operand
) {
DataSource dataSource;
try {
dataSource = parseDataSource(operand);
} catch (Exception e) {
throw new IllegalArgumentException("Error while reading dataSource", e);
}
String catalog = (String) operand.get("jdbcCatalog");
String schema = (String) operand.get("jdbcSchema");
Expression expression = null;
if (parentSchema != null) {
expression = Schemas.subSchemaExpression(parentSchema, name, JdbcSchema.class);
}
final SqlDialect dialect = createDialect(dataSource);
final JdbcConvention convention = JdbcConvention.of(dialect, expression, name);
return new JournalledJdbcSchema(dataSource, dialect, convention, catalog, schema, operand);
}
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:22,代码来源:JournalledJdbcSchema.java
示例2: JdbcPrel
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public JdbcPrel(RelOptCluster cluster, RelTraitSet traitSet, JdbcIntermediatePrel prel) {
super(cluster, traitSet);
final RelNode input = prel.getInput();
rows = input.getRows();
convention = (DrillJdbcConvention) input.getTraitSet().getTrait(ConventionTraitDef.INSTANCE);
// generate sql for tree.
final SqlDialect dialect = convention.getPlugin().getDialect();
final JdbcImplementor jdbcImplementor = new JdbcImplementor(
dialect,
(JavaTypeFactory) getCluster().getTypeFactory());
final JdbcImplementor.Result result =
jdbcImplementor.visitChild(0, input.accept(new SubsetRemover()));
sql = result.asQuery().toSqlString(dialect).getSql();
rowType = input.getRowType();
}
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:JdbcPrel.java
示例3: stripNamespace
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
/**
* Strips namespace from identifiers of sql
*
* @param node
* @param namespace
* @param dialect
* @return
*/
private String stripNamespace(final SqlNode node,
final String namespace,
final SqlDialect dialect) {
final SqlNode transformedNode = node.accept(
new SqlShuttle() {
@Override
public SqlNode visit(SqlIdentifier id) {
if (id.names.size() > 1
&& id.names.get(0).toUpperCase().equals(namespace.toUpperCase())) {
return id.getComponent(1, id.names.size());
} else {
return id;
}
}
});
String result = transformedNode.toSqlString(dialect).toString();
return result.replace("\n", " ");
}
开发者ID:qubole,项目名称:quark,代码行数:27,代码来源:SqlQueryParser.java
示例4: getParsedSql
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public static String getParsedSql(RelNode relNode, SqlDialect dialect) throws SQLException {
if (dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.HIVE) {
final HepProgram program = new HepProgramBuilder()
.addRuleInstance(JoinCalcTransposeRule.LEFT_CALC)
.addRuleInstance(JoinCalcTransposeRule.RIGHT_CALC)
.addRuleInstance(CalcMergeRule.INSTANCE)
.build();
final RelOptPlanner planner = relNode.getCluster().getPlanner();
final HepPlanner hepPlanner =
new HepPlanner(program, planner.getContext());
hepPlanner.setRoot(relNode);
relNode = hepPlanner.findBestExp();
}
RelToSqlConverter relToSqlConverter = new RelToSqlConverter(dialect);
RelToSqlConverter.Result res = relToSqlConverter.visitChild(0, relNode);
SqlNode sqlNode = res.asQuery();
String result = sqlNode.toSqlString(dialect, false).getSql();
return result.replace("\n", " ");
}
开发者ID:qubole,项目名称:quark,代码行数:20,代码来源:ResultProcessor.java
示例5: testHiveSelectQueryWithOrderByDescAndHighNullsWithVersionGreaterThanOrEq21
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Test public void testHiveSelectQueryWithOrderByDescAndHighNullsWithVersionGreaterThanOrEq21() {
final HiveSqlDialect hive2_1Dialect =
new HiveSqlDialect(SqlDialect.EMPTY_CONTEXT
.withDatabaseMajorVersion(2)
.withDatabaseMinorVersion(1)
.withNullCollation(NullCollation.LOW));
final HiveSqlDialect hive2_2_Dialect =
new HiveSqlDialect(SqlDialect.EMPTY_CONTEXT
.withDatabaseMajorVersion(2)
.withDatabaseMinorVersion(2)
.withNullCollation(NullCollation.LOW));
final String query = "select \"product_id\" from \"product\"\n"
+ "order by \"product_id\" desc nulls first";
final String expected = "SELECT product_id\n"
+ "FROM foodmart.product\n"
+ "ORDER BY product_id DESC NULLS FIRST";
sql(query).dialect(hive2_1Dialect).ok(expected);
sql(query).dialect(hive2_2_Dialect).ok(expected);
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:RelToSqlConverterTest.java
示例6: DrillJdbcConvention
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public DrillJdbcConvention(SqlDialect dialect, String name) {
super(dialect, ConstantUntypedNull.INSTANCE, name);
// build rules for this convention.
ImmutableSet.Builder<RelOptRule> builder = ImmutableSet.builder();
builder.add(JDBC_PRULE_INSTANCE);
builder.add(new JdbcDrelConverterRule(this));
builder.add(new DrillJdbcProjectRule(this));
builder.add(new DrillJdbcFilterRule(this));
outside: for (RelOptRule rule : JdbcRules.rules(this)) {
final String description = rule.toString();
// we want to black list some rules but the parent Calcite package is all or none.
// Therefore, we remove rules with names we don't like.
for(String black : RULES_TO_AVOID){
if(description.equals(black)){
continue outside;
}
}
builder.add(rule);
}
builder.add(FilterSetOpTransposeRule.INSTANCE);
builder.add(ProjectRemoveRule.INSTANCE);
rules = builder.build();
}
开发者ID:skhalifa,项目名称:QDrill,代码行数:33,代码来源:JdbcStoragePlugin.java
示例7: CalciteHelper
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
/**
* Initialize the helper with a datasource and it's schema.
*
* @param dataSource The datasource to make connections with.
*
* @throws SQLException if failed while making a connection to the database.
*/
public CalciteHelper(DataSource dataSource) throws SQLException {
this.dataSource = dataSource;
try (Connection connection = getConnection()) {
this.dialect = SqlDialect.create(connection.getMetaData());
}
}
开发者ID:yahoo,项目名称:fili,代码行数:15,代码来源:CalciteHelper.java
示例8: CursorHive
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public CursorHive(CachedStatement cachedStatement, String name,
FormatCode[] paramFormats, byte[][] paramValues,
FormatCode[] resultFormats, String dataSourceName) {
super(cachedStatement, name, paramFormats, paramValues, resultFormats);
sessionId = Session.currentSession().getId();
this.dataSourceName = dataSourceName;
/*
* NOTE: Deep-copy validatedQuery because TableNameTranslator.toDSN()
* changes identifiers of validatedQuery itself.
* When this Portal runs again without copied one,
* the by-pass test in processBind() which uses the validatedQuery
* will produce an error.
* To reduce number of copies, cache queryString.
*/
CachedStatement cStmt = (CachedStatement) getCachedQuery();
SqlNode cloned = cStmt.getValidatedQuery().accept(new SqlShuttle() {
@Override
public SqlNode visit(SqlIdentifier id) {
return id.clone(id.getParserPosition());
}
});
TableNameTranslator.toDSN(cloned);
SqlDialect.DatabaseProduct dp = SqlDialect.DatabaseProduct.HIVE;
queryString = cloned.toSqlString(dp.getDialect()).getSql();
}
开发者ID:bitnine-oss,项目名称:octopus,代码行数:28,代码来源:CursorHive.java
示例9: generateSql
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
private String generateSql(SqlDialect dialect) {
final JdbcImplementor jdbcImplementor =
new JdbcImplementor(dialect,
(JavaTypeFactory) getCluster().getTypeFactory());
final JdbcImplementor.Result result =
jdbcImplementor.visitChild(0, getInput());
return result.asQuery().toSqlString(dialect).getSql();
}
开发者ID:bitnine-oss,项目名称:octopus,代码行数:9,代码来源:JdbcToEnumerableConverter.java
示例10: of
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
static CalendarPolicy of(SqlDialect dialect) {
switch (dialect.getDatabaseProduct()) {
case MYSQL:
return SHIFT;
case HSQLDB:
default:
// NULL works for hsqldb-2.3; nothing worked for hsqldb-1.8.
return NULL;
}
}
开发者ID:bitnine-oss,项目名称:octopus,代码行数:11,代码来源:JdbcToEnumerableConverter.java
示例11: canImplement
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
/**
* Returns whether this JDBC data source can implement a given aggregate
* function.
*/
private boolean canImplement(SqlAggFunction aggregation,
SqlDialect sqlDialect) {
switch (sqlDialect.getDatabaseProduct()) {
case MYSQL:
return MYSQL_AGG_FUNCS.contains(aggregation);
default:
return AGG_FUNCS.contains(aggregation);
}
}
开发者ID:bitnine-oss,项目名称:octopus,代码行数:14,代码来源:JdbcRules.java
示例12: executeCreateView
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public int executeCreateView(SqlCreateQuarkView sqlNode) throws SQLException {
DBI dbi = getDbi();
List<String> tableNameList = sqlNode.getTableName().names;
String dataSourceName = tableNameList.get(0);
ViewDAO viewDAO = dbi.onDemand(ViewDAO.class);
JdbcSourceDAO jdbcDAO = dbi.onDemand(JdbcSourceDAO.class);
QuboleDbSourceDAO quboleDAO = dbi.onDemand(QuboleDbSourceDAO.class);
DataSource dataSource = jdbcDAO.findByName(dataSourceName,
connection.getDSSet().getId());
if (dataSource == null) {
dataSource = quboleDAO.findByName(dataSourceName, connection.getDSSet().getId());
}
if (dataSource == null) {
throw new SQLException("DataSource with name '" + dataSourceName + "' not found");
}
SqlPrettyWriter writer = new SqlPrettyWriter(SqlDialect.CALCITE);
writer.setAlwaysUseParentheses(false);
writer.setSelectListItemsOnSeparateLines(false);
writer.setIndentation(0);
writer.setQuoteAllIdentifiers(true);
sqlNode.getQuery().unparse(writer, 0, 0);
final String sql = writer.toString();
LOG.debug(sql);
return viewDAO.insert(sqlNode.getName(),
"No Description", sql,
0L, dataSource.getId(),
tableNameList.get(1), tableNameList.get(2),
connection.getDSSet().getId());
}
开发者ID:qubole,项目名称:quark,代码行数:35,代码来源:QuarkDDLExecutor.java
示例13: testOptWithJoin
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Test
public void testOptWithJoin() throws Exception {
String sql = "select\n" +
"qh.created_at as dt, \n" +
"count(qh.id) as num_queries\n" +
"\n" +
"from test_hist qh\n" +
"join uinfo ui\n" +
" on qh.qbol_user_id = ui.qu_id\n" +
"join acc externals\n" +
" on externals.id = ui.a_id\n" +
"\n" +
"where qh.timeout >= 350\n" +
"and command_type = 'HiveCommand'\n" +
"and qlog like '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%'\n" +
"and customer_name like 'amogh'\n" +
"\n" +
"group by \n" +
"qh.created_at\n" +
"\n" +
"order by dt asc";
SqlQueryParser parser = new SqlQueryParser(connInfo);
final SqlQueryParser.SqlQueryParserResult result = parser.parse(sql);
final String hiveQuery = ResultProcessor.getParsedSql(result.getRelNode(),
SqlDialect.DatabaseProduct.HIVE.getDialect());
assertEquals("SELECT CREATED_AT, COUNT(ID) NUM_QUERIES FROM " +
"PUBLIC.TEST_HIST_PARTITION INNER JOIN H2.PUBLIC.UINFO " +
"ON TEST_HIST_PARTITION.QBOL_USER_ID = UINFO.QU_ID " +
"INNER JOIN H2.PUBLIC.ACC ON UINFO.A_ID = ACC.ID " +
"WHERE ACC.CUSTOMER_NAME LIKE 'amogh' AND " +
"(TEST_HIST_PARTITION.TIMEOUT >= 350 " +
"AND TEST_HIST_PARTITION.COMMAND_TYPE = 'HiveCommand' " +
"AND TEST_HIST_PARTITION.QLOG " +
"LIKE '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%') " +
"GROUP BY CREATED_AT ORDER BY CREATED_AT", hiveQuery);
}
开发者ID:qubole,项目名称:quark,代码行数:37,代码来源:MaterializedViewJoinTest.java
示例14: testNoOptWeakerFilter
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Ignore
@Test
public void testNoOptWeakerFilter() throws Exception {
String sql = "select\n" +
"qh.created_at as dt, \n" +
"count(qh.id) as num_queries\n" +
"\n" +
"from test_hist qh\n" +
"join uinfo ui\n" +
" on qh.qbol_user_id = ui.qu_id\n" +
"join acc externals\n" +
" on externals.id = ui.a_id\n" +
"\n" +
"where qh.timeout >= 200\n" +
"and command_type = 'HiveCommand'\n" +
"and qlog like '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%'\n" +
"and customer_name like 'amogh'\n" +
"\n" +
"group by \n" +
"qh.created_at\n" +
"\n" +
"order by dt asc";
SqlQueryParser parser = new SqlQueryParser(connInfo);
final SqlQueryParser.SqlQueryParserResult result = parser.parse(sql);
final String hiveQuery = ResultProcessor.getParsedSql(result.getRelNode(),
SqlDialect.DatabaseProduct.HIVE.getDialect());
assertEquals("SELECT CREATED_AT, COUNT(ID) NUM_QUERIES FROM " +
"H2.PUBLIC.TEST_HIST INNER JOIN H2.PUBLIC.UINFO " +
"ON TEST_HIST.QBOL_USER_ID = UINFO.QU_ID " +
"INNER JOIN H2.PUBLIC.ACC ON UINFO.A_ID = ACC.ID " +
"WHERE ACC.CUSTOMER_NAME LIKE 'amogh' AND " +
"(TEST_HIST.TIMEOUT >= 200 " +
"AND TEST_HIST.COMMAND_TYPE = 'HiveCommand' " +
"AND TEST_HIST.QLOG " +
"LIKE '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%') " +
"GROUP BY CREATED_AT ORDER BY CREATED_AT", hiveQuery);
}
开发者ID:qubole,项目名称:quark,代码行数:38,代码来源:MaterializedViewJoinTest.java
示例15: testMVOptWithJoinAndhiveOp
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Ignore
@Test
public void testMVOptWithJoinAndhiveOp() throws Exception {
String sql = "select\n" +
"to_date(qh.created_at) as dt, \n" +
"count(qh.id) as num_queries\n" +
"\n" +
"from test_hist qh\n" +
"join uinfo ui\n" +
" on qh.qbol_user_id = ui.qu_id\n" +
"join acc externals\n" +
" on externals.id = ui.a_id\n" +
"\n" +
"where to_date(qh.created_at) >= date_sub(from_unixtime(unix_timestamp()),30)\n" +
"and command_type = 'HiveCommand'\n" +
"and qlog like '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%'\n" +
"and customer_name like 'amogh'\n" +
"\n" +
"group by \n" +
"to_date(qh.created_at)\n" +
"\n" +
"order by dt asc";
SqlQueryParser parser = new SqlQueryParser(connInfo);
final SqlQueryParser.SqlQueryParserResult result = parser.parse(sql);
final String hiveQuery = ResultProcessor.getParsedSql(result.getRelNode(),
SqlDialect.DatabaseProduct.HIVE.getDialect());
assertEquals("SELECT TO_DATE(TEST_HIST_PARTITION1.CREATED_AT) DT, "
+ "COUNT(TEST_HIST_PARTITION1.ID) NUM_QUERIES "
+ "FROM PUBLIC.TEST_HIST_PARTITION1 INNER JOIN H2.PUBLIC.UINFO "
+ "ON TEST_HIST_PARTITION1.QBOL_USER_ID = UINFO.QU_ID INNER JOIN H2.PUBLIC.ACC "
+ "ON UINFO.A_ID = ACC.ID "
+ "WHERE ACC.CUSTOMER_NAME LIKE 'amogh' AND "
+ "(TO_DATE(TEST_HIST_PARTITION1.CREATED_AT) >= "
+ "DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP()), 30) "
+ "AND TEST_HIST_PARTITION1.COMMAND_TYPE = 'HiveCommand' "
+ "AND TEST_HIST_PARTITION1.QLOG LIKE '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%') "
+ "GROUP BY TO_DATE(TEST_HIST_PARTITION1.CREATED_AT) "
+ "ORDER BY DT", hiveQuery);
}
开发者ID:qubole,项目名称:quark,代码行数:40,代码来源:MaterializedViewJoinTest.java
示例16: testNoOptWithHiveOp
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Ignore
@Test
public void testNoOptWithHiveOp() throws Exception {
String sql = "select\n" +
"to_date(qh.created_at) as dt, \n" +
"count(qh.id) as num_queries\n" +
"\n" +
"from test_hist qh\n" +
"join uinfo ui\n" +
" on qh.qbol_user_id = ui.qu_id\n" +
"join acc externals\n" +
" on externals.id = ui.a_id\n" +
"\n" +
"where to_date(qh.created_at) >= date_sub(from_unixtime(unix_timestamp()),150)\n" +
"and command_type = 'HiveCommand'\n" +
"and qlog like '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%'\n" +
"and customer_name like 'amogh'\n" +
"\n" +
"group by \n" +
"to_date(qh.created_at)\n" +
"\n" +
"order by dt asc";
SqlQueryParser parser = new SqlQueryParser(connInfo);
final SqlQueryParser.SqlQueryParserResult result = parser.parse(sql);
final String hiveQuery = ResultProcessor.getParsedSql(result.getRelNode(),
SqlDialect.DatabaseProduct.HIVE.getDialect());
assertEquals("SELECT TO_DATE(TEST_HIST.CREATED_AT) DT, "
+ "COUNT(TEST_HIST.ID) NUM_QUERIES "
+ "FROM H2.PUBLIC.TEST_HIST INNER JOIN H2.PUBLIC.UINFO "
+ "ON TEST_HIST.QBOL_USER_ID = UINFO.QU_ID INNER JOIN H2.PUBLIC.ACC "
+ "ON UINFO.A_ID = ACC.ID "
+ "WHERE ACC.CUSTOMER_NAME LIKE 'amogh' AND "
+ "(TO_DATE(TEST_HIST.CREATED_AT) >= "
+ "DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP()), 150) "
+ "AND TEST_HIST.COMMAND_TYPE = 'HiveCommand' "
+ "AND TEST_HIST.QLOG LIKE '%\\\"HIVE_VERSION\\\":\\\"1.2\\\"%') "
+ "GROUP BY TO_DATE(TEST_HIST.CREATED_AT) "
+ "ORDER BY DT", hiveQuery);
}
开发者ID:qubole,项目名称:quark,代码行数:40,代码来源:MaterializedViewJoinTest.java
示例17: testSqlParsingOfLimitClauseForRedShift
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Test
public void testSqlParsingOfLimitClauseForRedShift() throws QuarkException, SQLException, SqlParseException {
String query = "select product_id from product limit 100 offset 10";
final SqlDialect redshiftDialect =
SqlDialect.getProduct("REDSHIFT", null).getDialect();
QuarkTestUtil.checkSqlParsing(
query,
info,
"SELECT \"PRODUCT_ID\" "
+ "FROM \"PRODUCT\" "
+ "LIMIT 100 OFFSET 10",
redshiftDialect);
}
开发者ID:qubole,项目名称:quark,代码行数:14,代码来源:RelToSqlConverterTest.java
示例18: checkSqlParsing
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
public static void checkSqlParsing(String sql, Properties info, String expectedSql,
SqlDialect dialect)
throws QuarkException, SqlParseException {
SqlQueryParser parser = new SqlQueryParser(info);
SqlParser sqlParser = parser.getSqlParser(sql);
SqlNode sqlNode = sqlParser.parseQuery();
String finalQuery = sqlNode.toSqlString(dialect).getSql();
assertEquals(expectedSql, finalQuery.replace("\n", " "));
}
开发者ID:qubole,项目名称:quark,代码行数:10,代码来源:QuarkTestUtil.java
示例19: getSqlDialect
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
@Override
public SqlDialect getSqlDialect() {
String type = this.getProductName();
final SqlDialect dialect;
switch (type.toUpperCase()) {
case "HIVE":
dialect = SqlDialect.getProduct("Hive", null).getDialect();
break;
case "REDSHIFT":
dialect = SqlDialect.getProduct("REDSHIFT", null).getDialect();
break;
case "SQLSERVER":
case "MYSQL":
dialect = SqlDialect.getProduct("MySQL", null).getDialect();
break;
case "POSTGRESQL":
dialect = SqlDialect.getProduct("PostgreSQL", null).getDialect();
break;
case "VERTICA":
dialect = SqlDialect.getProduct("Vertica", null).getDialect();
break;
default:
dialect = SqlDialect.getProduct("UNKNOWN", null).getDialect();
break;
}
return dialect;
}
开发者ID:qubole,项目名称:quark,代码行数:28,代码来源:DbTapDb.java
示例20: generateSql
import org.apache.calcite.sql.SqlDialect; //导入依赖的package包/类
private String generateSql(SqlDialect dialect) {
final JdbcImplementor jdbcImplementor =
new JdbcImplementor(dialect,
(JavaTypeFactory) getCluster().getTypeFactory());
final JdbcImplementor.Result result =
jdbcImplementor.visitChild(0, getInput());
return result.asStatement().toSqlString(dialect).getSql();
}
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:JdbcToSparkConverter.java
注:本文中的org.apache.calcite.sql.SqlDialect类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论