Package org.eigenbase.sql

Examples of org.eigenbase.sql.SqlNode


  @Override
  public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
    SqlSetOption option = unwrap(sqlNode, SqlSetOption.class);
    String scope = option.getScope();
    String name = option.getName();
    SqlNode value = option.getValue();
    if(value instanceof SqlLiteral){
      switch(scope.toLowerCase()){
      case "session":
        context.getOptions().setOption(option.getName(), (SqlLiteral) value);
        break;
View Full Code Here


  /** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.`TABLES` ... */
  @Override
  public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException{
    SqlShowTables node = unwrap(sqlNode, SqlShowTables.class);
    List<SqlNode> selectList = Lists.newArrayList();
    SqlNode fromClause;
    SqlNode where;

    // create select columns
    selectList.add(new SqlIdentifier("TABLE_SCHEMA", SqlParserPos.ZERO));
    selectList.add(new SqlIdentifier("TABLE_NAME", SqlParserPos.ZERO));

    fromClause = new SqlIdentifier(ImmutableList.of("INFORMATION_SCHEMA", "TABLES"), SqlParserPos.ZERO);

    final SqlIdentifier db = node.getDb();
    String tableSchema;
    if (db != null) {
      tableSchema = db.toString();
    } else {
      // If no schema is given in SHOW TABLES command, list tables from current schema
      SchemaPlus schema = context.getNewDefaultSchema();

      if (isRootSchema(schema)) {
        // If the default schema is a root schema, throw an error to select a default schema
        throw new RelConversionException("No schema selected. Select a schema using 'USE schema' command");
      }

      AbstractSchema drillSchema;

      try {
        drillSchema = getDrillSchema(schema);
      } catch(Exception ex) {
        throw new RelConversionException("Error while rewriting SHOW TABLES query: " + ex.getMessage(), ex);
      }

      tableSchema = drillSchema.getFullSchemaName();
    }

    where = DrillParserUtil.createCondition(
        new SqlIdentifier("TABLE_SCHEMA", SqlParserPos.ZERO),
        SqlStdOperatorTable.EQUALS,
        SqlLiteral.createCharString(tableSchema, CHARSET, SqlParserPos.ZERO));

    SqlNode filter = null;
    final SqlNode likePattern = node.getLikePattern();
    if (likePattern != null) {
      filter = DrillParserUtil.createCondition(
          new SqlIdentifier("TABLE_NAME", SqlParserPos.ZERO),
          SqlStdOperatorTable.LIKE,
          likePattern);
View Full Code Here

          workspaceSchemaPath = getDrillSchema(defaultSchema).getSchemaPath();
        }

        String viewSql = createView.getQuery().toString();

        SqlNode validatedQuery = planner.validate(createView.getQuery());
        RelNode validatedRelNode = planner.convert(validatedQuery);

        // If view's field list is specified then its size should match view's query field list size.
        RelDataType queryRowType = validatedRelNode.getRowType();
View Full Code Here

          break;
        case ENABLE:
          enableComplex = true;
        }
      }
      SqlNode newOperand = operand.accept(CompoundIdentifierConverter.this);
      enableComplex = localEnableComplex;
      if (newOperand != operand) {
        update = true;
      }
      clonedOperands[i] = newOperand;
View Full Code Here

    if(ids.size() == 1){
      return new SqlIdentifier(Collections.singletonList(ids.get(0).value), ids.get(0).parserPos);
    }

    int startIndex;
    SqlNode node;

    if(ids.get(1).isArray()){
      // handle everything post zero index as item operator.
      startIndex = 1;
      node = new SqlIdentifier( //
View Full Code Here

  public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
    SqlCreateTable sqlCreateTable = unwrap(sqlNode, SqlCreateTable.class);

    try {
      // Convert the query in CTAS statement into a RelNode
      SqlNode validatedQuery = validateNode(sqlCreateTable.getQuery());
      RelNode relQuery = convertToRel(validatedQuery);

      List<String> tblFiledNames = sqlCreateTable.getFieldNames();
      RelDataType queryRowType = relQuery.getRowType();
View Full Code Here

  public PhysicalPlan getPlan(String sql) throws SqlParseException, ValidationException, RelConversionException, IOException{
    return getPlan(sql, null);
  }

  public PhysicalPlan getPlan(String sql, Pointer<String> textPlan) throws SqlParseException, ValidationException, RelConversionException, IOException{
    SqlNode sqlNode = planner.parse(sql);

    AbstractSqlHandler handler;

    // TODO: make this use path scanning or something similar.
    switch(sqlNode.getKind()){
    case EXPLAIN:
      handler = new ExplainHandler(planner, context);
      break;
    case SET_OPTION:
      handler = new SetOptionHandler(context);
View Full Code Here

        .defaultSchema(SimpleOptiqSchema.createRootSchema(false)) //
        .convertletTable(new DrillConvertletTable()) //
        .build();
    Planner planner = Frameworks.getPlanner(config);

    SqlNode node = planner.parse(""
        + "select a[4].c \n"
        + "from x.y.z \n"
        + "where a.c.b = 5 and x[2] = 7 \n"
        + "group by d \n"
        + "having a.c < 5 \n"
        + "order by x.a.a.a.a.a");

    String expected = "SELECT `a`[4]['c']\n" +
        "FROM `x`.`y`.`z`\n" +
        "WHERE `a`.`c`['b'] = 5 AND `x`[2] = 7\n" +
        "GROUP BY `d`\n" +
        "HAVING `a`.`c` < 5\n" +
        "ORDER BY `x`.`a`['a']['a']['a']['a']";


    SqlNode rewritten = node.accept(new CompoundIdentifierConverter());
    String rewrittenQuery = rewritten.toString();

    DrillAssert.assertMultiLineStringEquals(expected, rewrittenQuery);
  }
View Full Code Here

  @Override
  public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException{
    SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
    List<SqlNode> selectList = ImmutableList.of((SqlNode) new SqlIdentifier("SCHEMA_NAME", SqlParserPos.ZERO));

    SqlNode fromClause = new SqlIdentifier(
        ImmutableList.of("INFORMATION_SCHEMA", "SCHEMATA"), null, SqlParserPos.ZERO, null);

    SqlNode where = null;
    final SqlNode likePattern = node.getLikePattern();
    if (likePattern != null) {
      where = DrillParserUtil.createCondition(new SqlIdentifier("SCHEMA_NAME", SqlParserPos.ZERO),
          SqlStdOperatorTable.LIKE, likePattern);
    } else if (node.getWhereClause() != null) {
      where = node.getWhereClause();
View Full Code Here

  /** Populates a materialization record, converting a table path
   * (essentially a list of strings, like ["hr", "sales"]) into a table object
   * that can be used in the planning process. */
  void populate(Materialization materialization) {
    SqlParser parser = SqlParser.create(materialization.sql);
    SqlNode node;
    try {
      node = parser.parseStmt();
    } catch (SqlParseException e) {
      throw new RuntimeException("parse failed", e);
    }
View Full Code Here

TOP

Related Classes of org.eigenbase.sql.SqlNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.