Java Code Examples for org.apache.calcite.sql.SqlWriter#endList()

The following examples show how to use org.apache.calcite.sql.SqlWriter#endList() . 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: SqlAddReplaceColumns.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	super.unparse(writer, leftPrec, rightPrec);
	if (replace) {
		writer.keyword("REPLACE");
	} else {
		writer.keyword("ADD");
	}
	writer.keyword("COLUMNS");
	SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.create("sds"), "(", ")");
	for (SqlNode column : newColumns) {
		printIndent(writer);
		column.unparse(writer, leftPrec, rightPrec);
	}
	writer.newlineAndIndent();
	writer.endList(frame);
}
 
Example 2
Source File: SqlPosixRegexOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame = writer.startList("", "");
  call.operand(0).unparse(writer, getLeftPrec(), getRightPrec());

  if (this.negated) {
    writer.print("!");
  }
  writer.print("~");
  if (!this.caseSensitive) {
    writer.print("*");
  }
  writer.print(" ");

  call.operand(1).unparse(writer, getLeftPrec(), getRightPrec());
  writer.endList(frame);
}
 
Example 3
Source File: SqlCreateCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("CREATE CATALOG");
	catalogName.unparse(writer, leftPrec, rightPrec);

	if (this.propertyList.size() > 0) {
		writer.keyword("WITH");
		SqlWriter.Frame withFrame = writer.startList("(", ")");
		for (SqlNode property : propertyList) {
			printIndent(writer);
			property.unparse(writer, leftPrec, rightPrec);
		}
		writer.newlineAndIndent();
		writer.endList(withFrame);
	}
}
 
Example 4
Source File: SqlMapTypeNameSpec.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("MAP");
	SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "<", ">");
	writer.sep(","); // configures the writer
	keyType.unparse(writer, leftPrec, rightPrec);
	// Default is nullable.
	if (!keyType.getNullable()) {
		writer.keyword("NOT NULL");
	}
	writer.sep(",");
	valType.unparse(writer, leftPrec, rightPrec);
	// Default is nullable.
	if (!valType.getNullable()) {
		writer.keyword("NOT NULL");
	}
	writer.endList(frame);
}
 
Example 5
Source File: SqlCreateTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
  writer.keyword("CREATE");
  writer.keyword("TABLE");
  if (ifNotExists) {
    writer.keyword("IF NOT EXISTS");
  }
  name.unparse(writer, leftPrec, rightPrec);
  if (columnList != null) {
    SqlWriter.Frame frame = writer.startList("(", ")");
    for (SqlNode c : columnList) {
      writer.sep(",");
      c.unparse(writer, 0, 0);
    }
    writer.endList(frame);
  }
  if (query != null) {
    writer.keyword("AS");
    writer.newlineAndIndent();
    query.unparse(writer, 0, 0);
  }
}
 
Example 6
Source File: SqlLikeOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame = writer.startList("", "");
  call.operand(0).unparse(writer, getLeftPrec(), getRightPrec());
  writer.sep(getName());

  call.operand(1).unparse(writer, getLeftPrec(), getRightPrec());
  if (call.operandCount() == 3) {
    writer.sep("ESCAPE");
    call.operand(2).unparse(writer, getLeftPrec(), getRightPrec());
  }
  writer.endList(frame);
}
 
Example 7
Source File: SqlUploadJarNode.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override protected void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec) {
  writer.keyword("UPLOAD");
  writer.keyword("JAR");
  SqlWriter.Frame frame = writer.startList("", "");
  for (SqlNode jarPath : jarPaths) {
    jarPath.unparse(writer, leftPrec, rightPrec);
  }
  writer.endList(frame);
}
 
Example 8
Source File: SqlItemOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override public void unparse(
    SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
  call.operand(0).unparse(writer, leftPrec, 0);
  final SqlWriter.Frame frame = writer.startList("[", "]");
  call.operand(1).unparse(writer, 0, 0);
  writer.endList(frame);
}
 
Example 9
Source File: SqlAlterHiveTableProps.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	super.unparse(writer, leftPrec, rightPrec);
	writer.keyword("SET TBLPROPERTIES");
	SqlWriter.Frame withFrame = writer.startList("(", ")");
	for (SqlNode property : origProps) {
		printIndent(writer);
		property.unparse(writer, leftPrec, rightPrec);
	}
	writer.newlineAndIndent();
	writer.endList(withFrame);
}
 
Example 10
Source File: SqlCreateHiveView.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("CREATE VIEW");
	if (isIfNotExists()) {
		writer.keyword("IF NOT EXISTS");
	}
	getViewName().unparse(writer, leftPrec, rightPrec);
	if (getFieldList().size() > 0) {
		getFieldList().unparse(writer, 1, rightPrec);
	}
	getComment().ifPresent(c -> {
		writer.newlineAndIndent();
		writer.keyword("COMMENT");
		c.unparse(writer, leftPrec, rightPrec);
	});
	if (originPropList.size() > 0) {
		writer.newlineAndIndent();
		writer.keyword("TBLPROPERTIES");
		SqlWriter.Frame withFrame = writer.startList("(", ")");
		for (SqlNode property : originPropList) {
			printIndent(writer);
			property.unparse(writer, leftPrec, rightPrec);
		}
		writer.newlineAndIndent();
		writer.endList(withFrame);
	}
	writer.newlineAndIndent();
	writer.keyword("AS");
	writer.newlineAndIndent();
	getQuery().unparse(writer, leftPrec, rightPrec);
}
 
Example 11
Source File: SqlBetweenOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame =
      writer.startList(FRAME_TYPE, "", "");
  call.operand(VALUE_OPERAND).unparse(writer, getLeftPrec(), 0);
  writer.sep(super.getName());
  writer.sep(flag.name());

  // If the expression for the lower bound contains a call to an AND
  // operator, we need to wrap the expression in parentheses to prevent
  // the AND from associating with BETWEEN. For example, we should
  // unparse
  //    a BETWEEN b OR (c AND d) OR e AND f
  // as
  //    a BETWEEN (b OR c AND d) OR e) AND f
  // If it were unparsed as
  //    a BETWEEN b OR c AND d OR e AND f
  // then it would be interpreted as
  //    (a BETWEEN (b OR c) AND d) OR (e AND f)
  // which would be wrong.
  final SqlNode lower = call.operand(LOWER_OPERAND);
  final SqlNode upper = call.operand(UPPER_OPERAND);
  int lowerPrec = new AndFinder().containsAnd(lower) ? 100 : 0;
  lower.unparse(writer, lowerPrec, lowerPrec);
  writer.sep("AND");
  upper.unparse(writer, 0, getRightPrec());
  writer.endList(frame);
}
 
Example 12
Source File: SqlOverlapsOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame =
      writer.startList(SqlWriter.FrameTypeEnum.SIMPLE);
  arg(writer, call, leftPrec, rightPrec, 0);
  writer.sep(getName());
  arg(writer, call, leftPrec, rightPrec, 1);
  writer.endList(frame);
}
 
Example 13
Source File: SqlColumnListConstructor.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  writer.keyword("ROW");
  final SqlWriter.Frame frame = writer.startList("(", ")");
  for (SqlNode operand : call.getOperandList()) {
    writer.sep(",");
    operand.unparse(writer, leftPrec, rightPrec);
  }
  writer.endList(frame);
}
 
Example 14
Source File: MssqlSqlDialect.java    From calcite with Apache License 2.0 5 votes vote down vote up
private void unparseFloorWithUnit(SqlWriter writer, SqlCall call, int charLen,
    String offset) {
  writer.print("CONVERT");
  SqlWriter.Frame frame = writer.startList("(", ")");
  writer.print("DATETIME, CONVERT(VARCHAR(" + charLen + "), ");
  call.operand(0).unparse(writer, 0, 0);
  writer.print(", 126)");

  if (offset.length() > 0) {
    writer.print("+'" + offset + "'");
  }
  writer.endList(frame);
}
 
Example 15
Source File: SqlBabelCreateTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
  writer.keyword("CREATE");
  switch (tableCollectionType) {
  case SET:
    writer.keyword("SET");
    break;
  case MULTISET:
    writer.keyword("MULTISET");
    break;
  default:
    break;
  }
  if (volatile_) {
    writer.keyword("VOLATILE");
  }
  writer.keyword("TABLE");
  if (ifNotExists) {
    writer.keyword("IF NOT EXISTS");
  }
  name.unparse(writer, leftPrec, rightPrec);
  if (columnList != null) {
    SqlWriter.Frame frame = writer.startList("(", ")");
    for (SqlNode c : columnList) {
      writer.sep(",");
      c.unparse(writer, 0, 0);
    }
    writer.endList(frame);
  }
  if (query != null) {
    writer.keyword("AS");
    writer.newlineAndIndent();
    query.unparse(writer, 0, 0);
  }
}
 
Example 16
Source File: SqlCreateDatabase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(
		SqlWriter writer,
		int leftPrec,
		int rightPrec) {
	writer.keyword("CREATE DATABASE");
	if (isIfNotExists()) {
		writer.keyword("IF NOT EXISTS");
	}
	databaseName.unparse(writer, leftPrec, rightPrec);

	if (comment != null) {
		writer.newlineAndIndent();
		writer.keyword("COMMENT");
		comment.unparse(writer, leftPrec, rightPrec);
	}

	if (this.propertyList.size() > 0) {
		writer.keyword("WITH");
		SqlWriter.Frame withFrame = writer.startList("(", ")");
		for (SqlNode property : propertyList) {
			printIndent(writer);
			property.unparse(writer, leftPrec, rightPrec);
		}
		writer.newlineAndIndent();
		writer.endList(withFrame);
	}
}
 
Example 17
Source File: SqlMultisetValueConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  writer.keyword(getName()); // "MULTISET" or "ARRAY"
  final SqlWriter.Frame frame = writer.startList("[", "]");
  for (SqlNode operand : call.getOperandList()) {
    writer.sep(",");
    operand.unparse(writer, leftPrec, rightPrec);
  }
  writer.endList(frame);
}
 
Example 18
Source File: SqlCreateHiveDatabase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("CREATE DATABASE");
	if (isIfNotExists()) {
		writer.keyword("IF NOT EXISTS");
	}
	getDatabaseName().unparse(writer, leftPrec, rightPrec);

	if (getComment().isPresent()) {
		writer.newlineAndIndent();
		writer.keyword("COMMENT");
		getComment().get().unparse(writer, leftPrec, rightPrec);
	}

	if (location != null) {
		writer.newlineAndIndent();
		writer.keyword("LOCATION");
		location.unparse(writer, leftPrec, rightPrec);
	}

	if (originPropList.size() > 0) {
		writer.keyword("WITH DBPROPERTIES");
		SqlWriter.Frame withFrame = writer.startList("(", ")");
		for (SqlNode property : originPropList) {
			printIndent(writer);
			property.unparse(writer, leftPrec, rightPrec);
		}
		writer.newlineAndIndent();
		writer.endList(withFrame);
	}
}
 
Example 19
Source File: SqlAlterHiveDatabaseProps.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	super.unparse(writer, leftPrec, rightPrec);
	writer.keyword("DBPROPERTIES");
	SqlWriter.Frame withFrame = writer.startList("(", ")");
	for (SqlNode property : originPropList) {
		printIndent(writer);
		property.unparse(writer, leftPrec, rightPrec);
	}
	writer.newlineAndIndent();
	writer.endList(withFrame);
}
 
Example 20
Source File: SqlLiteralChainOperator.java    From calcite with Apache License 2.0 4 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  final SqlWriter.Frame frame = writer.startList("", "");
  SqlCollation collation = null;
  for (Ord<SqlNode> operand : Ord.zip(call.getOperandList())) {
    SqlLiteral rand = (SqlLiteral) operand.e;
    if (operand.i > 0) {
      // SQL:2003 says there must be a newline between string
      // fragments.
      writer.newlineAndIndent();
    }
    if (rand instanceof SqlCharStringLiteral) {
      NlsString nls = ((SqlCharStringLiteral) rand).getNlsString();
      if (operand.i == 0) {
        collation = nls.getCollation();

        // print with prefix
        writer.literal(nls.asSql(true, false, writer.getDialect()));
      } else {
        // print without prefix
        writer.literal(nls.asSql(false, false, writer.getDialect()));
      }
    } else if (operand.i == 0) {
      // print with prefix
      rand.unparse(writer, leftPrec, rightPrec);
    } else {
      // print without prefix
      if (rand.getTypeName() == SqlTypeName.BINARY) {
        BitString bs = (BitString) rand.getValue();
        writer.literal("'" + bs.toHexString() + "'");
      } else {
        writer.literal("'" + rand.toValue() + "'");
      }
    }
  }
  if (collation != null) {
    collation.unparse(writer);
  }
  writer.endList(frame);
}