public Result visitSort(Sort e) { final Result x = visitChild(0, e.getInput()); final Builder builder = x.builder(e, Clause.ORDER_BY); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation fieldCollation : e.getCollation().getFieldCollations()) { if (fieldCollation.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED && dialect.getDatabaseProduct() == SqlDialect.DatabaseProduct.MYSQL) { orderByList.add( ISNULL_FUNCTION.createCall(POS, builder.context.field(fieldCollation.getFieldIndex()))); fieldCollation = new RelFieldCollation(fieldCollation.getFieldIndex(), fieldCollation.getDirection()); } orderByList.add(builder.context.toSql(fieldCollation)); } builder.setOrderBy(new SqlNodeList(orderByList, POS)); return builder.result(); }
switch (sqlDialect.getDatabaseProduct()) { case MYSQL: case HSQLDB: selectList.add(nullLiteral); final SqlNode unionOperand; switch (sqlDialect.getDatabaseProduct()) { case MYSQL: wrappedOperand = operand; + sqlDialect.getDatabaseProduct()); return aggCall;
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", " "); } }
private SqlNode toSql(RelDataType type) { switch (dialect.getDatabaseProduct()) { case MYSQL: switch (type.getSqlTypeName()) { case VARCHAR: // MySQL doesn't have a VARCHAR type, only CHAR. return new SqlDataTypeSpec(new SqlIdentifier("CHAR", POS), type.getPrecision(), -1, null, null, POS); case INTEGER: return new SqlDataTypeSpec(new SqlIdentifier("_UNSIGNED", POS), type.getPrecision(), -1, null, null, POS); } break; } if (type instanceof BasicSqlType) { return new SqlDataTypeSpec( new SqlIdentifier(type.getSqlTypeName().name(), POS), type.getPrecision(), type.getScale(), type.getCharset() != null && dialect.supportsCharSet() ? type.getCharset().name() : null, null, POS); } return SqlTypeUtil.convertTypeToSpec(type); //throw new AssertionError(type); // TODO: implement }
final String viewSql = createView.getQuery().toSqlString(new SqlDialect(SqlDialect.CALCITE.getDatabaseProduct(), SqlDialect.CALCITE.getDatabaseProduct().name(), ParserConfig.QUOTING.string)).getSql(); final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, createView.getQuery()); final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();