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

The following examples show how to use org.apache.calcite.rel.rel2sql.SqlImplementor. 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: CalciteUtls.java    From Mycat2 with 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 File: QuerySqlStatisticProvider.java    From calcite with Apache License 2.0 6 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 #3
Source File: Lattice.java    From Bats with 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 File: Lattice.java    From calcite with 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 #5
Source File: Lattice.java    From Bats with 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 File: Lattice.java    From calcite with 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));
}