Java Code Examples for org.apache.calcite.sql.SqlWriter

The following examples show how to use org.apache.calcite.sql.SqlWriter. 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: flink   Source File: SqlAlterHiveTableChangeColumn.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("ALTER TABLE");
	tableIdentifier.unparse(writer, leftPrec, rightPrec);
	SqlNodeList partitionSpec = getPartitionSpec();
	if (partitionSpec != null && partitionSpec.size() > 0) {
		writer.keyword("PARTITION");
		partitionSpec.unparse(writer, getOperator().getLeftPrec(), getOperator().getRightPrec());
	}
	writer.keyword("CHANGE COLUMN");
	getOldName().unparse(writer, leftPrec, rightPrec);
	origNewColumn.unparse(writer, leftPrec, rightPrec);
	if (isFirst()) {
		writer.keyword("FIRST");
	}
	if (getAfter() != null) {
		writer.keyword("AFTER");
		getAfter().unparse(writer, leftPrec, rightPrec);
	}
	if (cascade) {
		writer.keyword("CASCADE");
	} else {
		writer.keyword("RESTRICT");
	}
}
 
Example 2
Source Project: calcite   Source File: SqlFloorFunction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Most dialects that natively support datetime floor will use this.
 * In those cases the call will look like TRUNC(datetime, 'year').
 *
 * @param writer SqlWriter
 * @param call SqlCall
 * @param funName Name of the sql function to call
 * @param datetimeFirst Specify the order of the datetime & timeUnit
 * arguments
 */
public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call,
    String funName, Boolean datetimeFirst) {
  SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION,
      ReturnTypes.ARG0_NULLABLE_VARYING, null, null,
      SqlFunctionCategory.STRING);

  SqlCall call1;
  if (datetimeFirst) {
    call1 = call;
  } else {
    // switch order of operands
    SqlNode op1 = call.operand(0);
    SqlNode op2 = call.operand(1);

    call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1);
  }

  SqlUtil.unparseFunctionSyntax(func, writer, call1);
}
 
Example 3
Source Project: calcite   Source File: Db2SqlDialect.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparseSqlIntervalLiteral(SqlWriter writer,
    SqlIntervalLiteral literal, int leftPrec, int rightPrec) {
  // A duration is a positive or negative number representing an interval of time.
  // If one operand is a date, the other labeled duration of YEARS, MONTHS, or DAYS.
  // If one operand is a time, the other must be labeled duration of HOURS, MINUTES, or SECONDS.
  // If one operand is a timestamp, the other operand can be any of teh duration.

  SqlIntervalLiteral.IntervalValue interval =
      (SqlIntervalLiteral.IntervalValue) literal.getValue();
  if (interval.getSign() == -1) {
    writer.print("-");
  }
  writer.literal(literal.getValue().toString());
  unparseSqlIntervalQualifier(writer, interval.getIntervalQualifier(),
      RelDataTypeSystem.DEFAULT);
}
 
Example 4
Source Project: calcite   Source File: SqlOverlayFunction.java    License: 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.startFunCall(getName());
  call.operand(0).unparse(writer, leftPrec, rightPrec);
  writer.sep("PLACING");
  call.operand(1).unparse(writer, leftPrec, rightPrec);
  writer.sep("FROM");
  call.operand(2).unparse(writer, leftPrec, rightPrec);
  if (4 == call.operandCount()) {
    writer.sep("FOR");
    call.operand(3).unparse(writer, leftPrec, rightPrec);
  }
  writer.endFunCall(frame);
}
 
Example 5
Source Project: Bats   Source File: SqlExtendOperator.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
    int rightPrec) {
  final SqlOperator operator = call.getOperator();
  assert call.operandCount() == 2;
  final SqlWriter.Frame frame =
      writer.startList(SqlWriter.FrameTypeEnum.SIMPLE);
  call.operand(0).unparse(writer, leftPrec, operator.getLeftPrec());
  writer.setNeedWhitespace(true);
  writer.sep(operator.getName());
  final SqlNodeList list = call.operand(1);
  final SqlWriter.Frame frame2 = writer.startList("(", ")");
  for (Ord<SqlNode> node2 : Ord.zip(list)) {
    if (node2.i > 0 && node2.i % 2 == 0) {
      writer.sep(",");
    }
    node2.e.unparse(writer, 2, 3);
  }
  writer.endList(frame2);
  writer.endList(frame);
}
 
Example 6
Source Project: Bats   Source File: SqlCreateView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
  writer.keyword("CREATE");
  switch (SqlCreateType.valueOf(createType.toValue())) {
    case SIMPLE:
      writer.keyword("VIEW");
      break;
    case OR_REPLACE:
      writer.keyword("OR");
      writer.keyword("REPLACE");
      writer.keyword("VIEW");
      break;
    case IF_NOT_EXISTS:
      writer.keyword("VIEW");
      writer.keyword("IF");
      writer.keyword("NOT");
      writer.keyword("EXISTS");
      break;
  }
  viewName.unparse(writer, leftPrec, rightPrec);
  if (fieldList.size() > 0) {
    SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
  }
  writer.keyword("AS");
  query.unparse(writer, leftPrec, rightPrec);
}
 
Example 7
Source Project: flink   Source File: SqlAlterHiveTableSerDe.java    License: 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);
	writer.keyword("SET");
	if (serdeLib != null) {
		writer.keyword("SERDE");
		serdeLib.unparse(writer, leftPrec, rightPrec);
	}
	if (origSerDeProps != null && origSerDeProps.size() > 0) {
		if (serdeLib == null) {
			writer.keyword("SERDEPROPERTIES");
		} else {
			writer.keyword("WITH SERDEPROPERTIES");
		}
		SqlWriter.Frame withFrame = writer.startList("(", ")");
		for (SqlNode property : origSerDeProps) {
			printIndent(writer);
			property.unparse(writer, leftPrec, rightPrec);
		}
		writer.newlineAndIndent();
		writer.endList(withFrame);
	}
}
 
Example 8
Source Project: flink   Source File: SqlTableConstraint.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	if (this.constraintName != null) {
		writer.keyword("CONSTRAINT");
		this.constraintName.unparse(writer, leftPrec, rightPrec);
	}
	this.uniqueSpec.unparse(writer, leftPrec, rightPrec);
	if (isTableConstraint) {
		SqlWriter.Frame frame = writer.startList("(", ")");
		for (SqlNode column : this.columns) {
			writer.sep(",", false);
			column.unparse(writer, leftPrec, rightPrec);
		}
		writer.endList(frame);
	}
	if (this.enforcement != null) {
		this.enforcement.unparse(writer, leftPrec, rightPrec);
	}
}
 
Example 9
Source Project: Bats   Source File: SqlOverlayFunction.java    License: 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.startFunCall(getName());
  call.operand(0).unparse(writer, leftPrec, rightPrec);
  writer.sep("PLACING");
  call.operand(1).unparse(writer, leftPrec, rightPrec);
  writer.sep("FROM");
  call.operand(2).unparse(writer, leftPrec, rightPrec);
  if (4 == call.operandCount()) {
    writer.sep("FOR");
    call.operand(3).unparse(writer, leftPrec, rightPrec);
  }
  writer.endFunCall(frame);
}
 
Example 10
Source Project: Bats   Source File: SqlJsonValueFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
  assert call.operandCount() == 5 || call.operandCount() == 6;
  final SqlWriter.Frame frame = writer.startFunCall(getName());
  call.operand(0).unparse(writer, 0, 0);
  if (!returnAny) {
    writer.keyword("RETURNING");
    call.operand(5).unparse(writer, 0, 0);
  }
  unparseEnum(writer, call.operand(1));
  if (isDefaultLiteral(call.operand(1))) {
    call.operand(2).unparse(writer, 0, 0);
  }
  writer.keyword("ON");
  writer.keyword("EMPTY");
  unparseEnum(writer, call.operand(3));
  if (isDefaultLiteral(call.operand(3))) {
    call.operand(4).unparse(writer, 0, 0);
  }
  writer.keyword("ON");
  writer.keyword("ERROR");
  writer.endFunCall(frame);
}
 
Example 11
Source Project: calcite   Source File: SqlJsonArrayFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
    int rightPrec) {
  assert call.operandCount() >= 1;
  final SqlWriter.Frame frame = writer.startFunCall(getName());
  SqlWriter.Frame listFrame = writer.startList("", "");
  for (int i = 1; i < call.operandCount(); i++) {
    writer.sep(",");
    call.operand(i).unparse(writer, leftPrec, rightPrec);
  }
  writer.endList(listFrame);

  SqlJsonConstructorNullClause nullClause = getEnumValue(call.operand(0));
  switch (nullClause) {
  case ABSENT_ON_NULL:
    writer.keyword("ABSENT ON NULL");
    break;
  case NULL_ON_NULL:
    writer.keyword("NULL ON NULL");
    break;
  default:
    throw new IllegalStateException("unreachable code");
  }
  writer.endFunCall(frame);
}
 
Example 12
Source Project: kareldb   Source File: SqlAlterTableExtension.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void unparseAlterOperation(SqlWriter writer, int leftPrec, int rightPrec) {
    if (ifExists) {
        writer.keyword("IF NOT EXISTS");
    }
    name.unparse(writer, leftPrec, rightPrec);
    if (columnList != null) {
        SqlWriter.Frame frame = writer.startList("", "");
        for (int i = 0; i < columnList.size(); i++) {
            Action a = actions.get(i);
            SqlNode c = columnList.get(i);
            writer.sep(",");
            writer.keyword(a.name());
            c.unparse(writer, 0, 0);
        }
        writer.endList(frame);
    }
}
 
Example 13
Source Project: calcite   Source File: HsqldbSqlDialect.java    License: Apache License 2.0 6 votes vote down vote up
@Override public void unparseCall(SqlWriter writer, SqlCall call,
    int leftPrec, int rightPrec) {
  switch (call.getKind()) {
  case FLOOR:
    if (call.operandCount() != 2) {
      super.unparseCall(writer, call, leftPrec, rightPrec);
      return;
    }

    final SqlLiteral timeUnitNode = call.operand(1);
    final TimeUnitRange timeUnit = timeUnitNode.getValueAs(TimeUnitRange.class);

    final String translatedLit = convertTimeUnit(timeUnit);
    SqlCall call2 = SqlFloorFunction.replaceTimeUnitOperand(call, translatedLit,
        timeUnitNode.getParserPosition());
    SqlFloorFunction.unparseDatetimeFunction(writer, call2, "TRUNC", true);
    break;

  default:
    super.unparseCall(writer, call, leftPrec, rightPrec);
  }
}
 
Example 14
Source Project: dremio-oss   Source File: SqlColumnDeclaration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
  name.unparse(writer, 0, 0);
  dataType.unparse(writer, 0, 0);
  if (dataType.getNullable() != null && !dataType.getNullable()) {
    writer.keyword("NOT NULL");
  }
  if (expression != null) {
    switch (strategy) {
      case VIRTUAL:
      case STORED:
        writer.keyword("AS");
        exp(writer);
        writer.keyword(strategy.name());
        break;
      case DEFAULT:
        writer.keyword("DEFAULT");
        exp(writer);
        break;
      default:
        throw new AssertionError("unexpected: " + strategy);
    }
  }
}
 
Example 15
Source Project: flink   Source File: SqlAlterFunction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("ALTER");
	if (isTemporary) {
		writer.keyword("TEMPORARY");
	}
	if (isSystemFunction) {
		writer.keyword("SYSTEM");
	}
	writer.keyword("FUNCTION");
	if (ifExists) {
		writer.keyword("IF EXISTS");
	}
	functionIdentifier.unparse(writer, leftPrec, rightPrec);
	writer.keyword("AS");
	functionClassName.unparse(writer, leftPrec, rightPrec);
	if (functionLanguage != null) {
		writer.keyword("LANGUAGE");
		writer.keyword(functionLanguage);
	}
}
 
Example 16
Source Project: calcite   Source File: BigQuerySqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * For usage of TRIM, LTRIM and RTRIM in BQ see
 * <a href="https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#trim">
 *  BQ Trim Function</a>.
 */
private void unparseTrim(SqlWriter writer, SqlCall call, int leftPrec,
    int rightPrec) {
  final String operatorName;
  SqlLiteral trimFlag = call.operand(0);
  SqlLiteral valueToTrim = call.operand(1);
  switch (trimFlag.getValueAs(SqlTrimFunction.Flag.class)) {
  case LEADING:
    operatorName = "LTRIM";
    break;
  case TRAILING:
    operatorName = "RTRIM";
    break;
  default:
    operatorName = call.getOperator().getName();
    break;
  }
  final SqlWriter.Frame trimFrame = writer.startFunCall(operatorName);
  call.operand(2).unparse(writer, leftPrec, rightPrec);

  // If the trimmed character is a non-space character, add it to the target SQL.
  // eg: TRIM(BOTH 'A' from 'ABCD'
  // Output Query: TRIM('ABC', 'A')
  if (!valueToTrim.toValue().matches("\\s+")) {
    writer.literal(",");
    call.operand(1).unparse(writer, leftPrec, rightPrec);
  }
  writer.endFunCall(trimFrame);
}
 
Example 17
Source Project: calcite   Source File: SqlTranslate3Function.java    License: 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.startFunCall("TRANSLATE");
  for (SqlNode sqlNode : call.getOperandList()) {
    writer.sep(",");
    sqlNode.unparse(writer, leftPrec, rightPrec);
  }
  writer.endFunCall(frame);
}
 
Example 18
Source Project: dremio-oss   Source File: SqlCompactMaterialization.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
  writer.keyword("COMPACT");
  writer.keyword("REFRESH");
  materializationPath.unparse(writer, leftPrec, rightPrec);
  writer.keyword("AS");
  newMaterializationId.unparse(writer, leftPrec, rightPrec);
}
 
Example 19
Source Project: calcite   Source File: SqlBabelCreateTable.java    License: 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 20
Source Project: flink   Source File: SqlCreateHiveDatabase.java    License: 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 21
Source Project: flink   Source File: SqlRawTypeNameSpec.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword(RAW_TYPE_NAME);
	final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")");
	writer.sep(","); // configures the writer
	className.unparse(writer, leftPrec, rightPrec);
	writer.sep(",");
	serializerString.unparse(writer, leftPrec, rightPrec);
	writer.endList(frame);
}
 
Example 22
Source Project: calcite   Source File: SqlJsonArrayAggAggFunction.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void unparse(SqlWriter writer, SqlCall call, int leftPrec,
    int rightPrec) {
  assert call.operandCount() == 1;
  final SqlWriter.Frame frame = writer.startFunCall("JSON_ARRAYAGG");
  call.operand(0).unparse(writer, leftPrec, rightPrec);
  writer.keyword(nullClause.sql);
  writer.endFunCall(frame);
}
 
Example 23
Source Project: flink   Source File: RichSqlHiveInsert.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.startList(SqlWriter.FrameTypeEnum.SELECT);
	String insertKeyword = "INSERT INTO";
	if (isUpsert()) {
		insertKeyword = "UPSERT INTO";
	} else if (isOverwrite()) {
		insertKeyword = "INSERT OVERWRITE";
	}
	writer.sep(insertKeyword);
	final int opLeft = getOperator().getLeftPrec();
	final int opRight = getOperator().getRightPrec();
	getTargetTable().unparse(writer, opLeft, opRight);
	if (getTargetColumnList() != null) {
		getTargetColumnList().unparse(writer, opLeft, opRight);
	}
	writer.newlineAndIndent();
	if (allPartKeys != null && allPartKeys.size() > 0) {
		writer.keyword("PARTITION");
		SqlWriter.Frame frame = writer.startList("(", ")");
		for (SqlNode node : allPartKeys) {
			writer.sep(",", false);
			SqlIdentifier partKey = (SqlIdentifier) node;
			SqlProperty spec = partKeyToSpec.get(partKey);
			if (spec != null) {
				spec.unparse(writer, leftPrec, rightPrec);
			} else {
				partKey.unparse(writer, leftPrec, rightPrec);
			}
		}
		writer.endList(frame);
		writer.newlineAndIndent();
	}
	getSource().unparse(writer, 0, 0);
}
 
Example 24
Source Project: calcite   Source File: SqlThrowOperator.java    License: 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.startFunCall(getName());
  call.operand(0).unparse(writer, 0, 0);
  writer.endFunCall(frame);
}
 
Example 25
Source Project: calcite   Source File: SqlStdOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
public void unparse(
    SqlWriter writer,
    SqlCall call,
    int leftPrec,
    int rightPrec) {
  call.operand(0).unparse(writer, leftPrec, 0);
  writer.keyword("TABLESAMPLE");
  call.operand(1).unparse(writer, 0, rightPrec);
}
 
Example 26
Source Project: calcite   Source File: SqlOverlapsOperator.java    License: Apache License 2.0 5 votes vote down vote up
void arg(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec, int i) {
  if (SqlUtil.isCallTo(call.operand(i), SqlStdOperatorTable.ROW)) {
    SqlCall row = call.operand(i);
    writer.keyword("PERIOD");
    writer.sep("(", true);
    row.operand(0).unparse(writer, leftPrec, rightPrec);
    writer.sep(",", true);
    row.operand(1).unparse(writer, leftPrec, rightPrec);
    writer.sep(")", true);
  } else {
    call.operand(i).unparse(writer, leftPrec, rightPrec);
  }
}
 
Example 27
Source Project: calcite   Source File: SqlPrettyWriterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test void testBlackSubQueryStyle() {
  // Note that ( is at the indent, SELECT is on the same line, and ) is
  // below it.
  simple()
      .withWriter(w -> w.withSubQueryStyle(SqlWriter.SubQueryStyle.BLACK))
      .check();
}
 
Example 28
Source Project: Bats   Source File: MysqlSqlDialect.java    License: Apache License 2.0 5 votes vote down vote up
@Override public void unparseSqlIntervalQualifier(SqlWriter writer,
    SqlIntervalQualifier qualifier, RelDataTypeSystem typeSystem) {

  //  Unit Value         | Expected Format
  // --------------------+-------------------------------------------
  //  MICROSECOND        | MICROSECONDS
  //  SECOND             | SECONDS
  //  MINUTE             | MINUTES
  //  HOUR               | HOURS
  //  DAY                | DAYS
  //  WEEK               | WEEKS
  //  MONTH              | MONTHS
  //  QUARTER            | QUARTERS
  //  YEAR               | YEARS
  //  MINUTE_SECOND      | 'MINUTES:SECONDS'
  //  HOUR_MINUTE        | 'HOURS:MINUTES'
  //  DAY_HOUR           | 'DAYS HOURS'
  //  YEAR_MONTH         | 'YEARS-MONTHS'
  //  MINUTE_MICROSECOND | 'MINUTES:SECONDS.MICROSECONDS'
  //  HOUR_MICROSECOND   | 'HOURS:MINUTES:SECONDS.MICROSECONDS'
  //  SECOND_MICROSECOND | 'SECONDS.MICROSECONDS'
  //  DAY_MINUTE         | 'DAYS HOURS:MINUTES'
  //  DAY_MICROSECOND    | 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
  //  DAY_SECOND         | 'DAYS HOURS:MINUTES:SECONDS'
  //  HOUR_SECOND        | 'HOURS:MINUTES:SECONDS'

  if (!qualifier.useDefaultFractionalSecondPrecision()) {
    throw new AssertionError("Fractional second precision is not supported now ");
  }

  final String start = validate(qualifier.timeUnitRange.startUnit).name();
  if (qualifier.timeUnitRange.startUnit == TimeUnit.SECOND
      || qualifier.timeUnitRange.endUnit == null) {
    writer.keyword(start);
  } else {
    writer.keyword(start + "_" + qualifier.timeUnitRange.endUnit.name());
  }
}
 
Example 29
Source Project: flink   Source File: SqlWatermark.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
	writer.keyword("WATERMARK");
	writer.keyword("FOR");
	eventTimeColumnName.unparse(writer, leftPrec, rightPrec);
	writer.keyword("AS");
	watermarkStrategy.unparse(writer, leftPrec, rightPrec);
}
 
Example 30
Source Project: flink   Source File: SqlAlterHivePartitionRename.java    License: 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.newlineAndIndent();
	writer.keyword("RENAME TO");
	writer.newlineAndIndent();
	writer.keyword("PARTITION");
	newPartSpec.unparse(writer, getOperator().getLeftPrec(), getOperator().getRightPrec());
}