Java Code Examples for org.apache.calcite.rel.rel2sql.SqlImplementor

The following examples show how to use org.apache.calcite.rel.rel2sql.SqlImplementor. These examples are extracted from open source projects. 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 Project: Mycat2   Source File: CalciteUtls.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String getFilterSQLText(List<SimpleColumnInfo> rawColumns, String schemaName, String tableName, List<RexNode> filters) {
    if (filters == null || filters.isEmpty()) {
        return "";
    }
    RexNode rexNode = RexUtil.composeConjunction(MycatCalciteSupport.INSTANCE.RexBuilder, filters);
    SqlImplementor.Context context = new SqlImplementor.Context(MysqlSqlDialect.DEFAULT, rawColumns.size()) {
        @Override
        public SqlNode field(int ordinal) {
            String fieldName = rawColumns.get(ordinal).getColumnName();
            return new SqlIdentifier(ImmutableList.of(schemaName, tableName, fieldName),
                    SqlImplementor.POS);
        }
    };
    try {
        return " where " + context.toSql(null, rexNode).toSqlString(MysqlSqlDialect.DEFAULT).getSql();
    } catch (Exception e) {
        LOGGER.warn("不能生成对应的sql", e);
    }
    return "";
}
 
Example 2
Source Project: Bats   Source File: Lattice.java    License: Apache License 2.0 5 votes vote down vote up
SqlWriter(Lattice lattice, SqlDialect dialect, StringBuilder buf,
    SqlImplementor.SimpleContext context) {
  this.lattice = lattice;
  this.context = context;
  this.buf = buf;
  this.dialect = dialect;
}
 
Example 3
Source Project: calcite   Source File: Lattice.java    License: Apache License 2.0 5 votes vote down vote up
SqlWriter(Lattice lattice, SqlDialect dialect, StringBuilder buf,
    SqlImplementor.SimpleContext context) {
  this.lattice = lattice;
  this.context = context;
  this.buf = buf;
  this.dialect = dialect;
}
 
Example 4
Source Project: calcite   Source File: QuerySqlStatisticProvider.java    License: Apache License 2.0 5 votes vote down vote up
protected String toSql(RelNode rel, SqlDialect dialect) {
  final RelToSqlConverter converter = new RelToSqlConverter(dialect);
  SqlImplementor.Result result = converter.visitChild(0, rel);
  final SqlNode sqlNode = result.asStatement();
  final String sql = sqlNode.toSqlString(dialect).getSql();
  sqlConsumer.accept(sql);
  return sql;
}
 
Example 5
Source Project: Bats   Source File: Lattice.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a context to which SQL can be generated. */
public SqlWriter createSqlWriter(SqlDialect dialect, StringBuilder buf,
    IntFunction<SqlNode> field) {
  return new SqlWriter(this, dialect, buf,
      new SqlImplementor.SimpleContext(dialect, field));
}
 
Example 6
Source Project: calcite   Source File: Lattice.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a context to which SQL can be generated. */
public SqlWriter createSqlWriter(SqlDialect dialect, StringBuilder buf,
    IntFunction<SqlNode> field) {
  return new SqlWriter(this, dialect, buf,
      new SqlImplementor.SimpleContext(dialect, field));
}