use of org.apache.calcite.sql.SqlJsonConstructorNullClause in project flink by apache.
the class SqlJsonObjectFunction method unparse.
@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
assert call.operandCount() % 2 == 1;
final SqlWriter.Frame frame = writer.startFunCall(getName());
SqlWriter.Frame listFrame = writer.startList("", "");
for (int i = 1; i < call.operandCount(); i += 2) {
writer.sep(",");
writer.keyword("KEY");
call.operand(i).unparse(writer, leftPrec, rightPrec);
writer.keyword("VALUE");
call.operand(i + 1).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);
}
use of org.apache.calcite.sql.SqlJsonConstructorNullClause in project flink by apache.
the class JsonArrayConverter method convert.
@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
checkArgument(call, call.getChildren().size() >= 1);
final List<RexNode> operands = new LinkedList<>();
final SqlJsonConstructorNullClause onNull = JsonConverterUtil.getOnNullArgument(call, 0);
operands.add(context.getRelBuilder().getRexBuilder().makeFlag(onNull));
for (int i = 1; i < call.getChildren().size(); i++) {
operands.add(context.toRexNode(call.getChildren().get(i)));
}
return context.getRelBuilder().getRexBuilder().makeCall(FlinkSqlOperatorTable.JSON_ARRAY, operands);
}
use of org.apache.calcite.sql.SqlJsonConstructorNullClause in project hazelcast by hazelcast.
the class HazelcastJsonArrayFunction method unparse.
@Override
public void unparse(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) {
final SqlWriter.Frame frame = writer.startFunCall(this.getName());
if (call.operandCount() == 1) {
writer.endFunCall(frame);
return;
}
for (int i = 1; i < call.operandCount(); i++) {
writer.sep(",");
call.operand(i).unparse(writer, leftPrec, rightPrec);
}
final SqlJsonConstructorNullClause nullClause = (SqlJsonConstructorNullClause) ((SqlLiteral) call.operand(0)).getValue();
switch(nullClause) {
case ABSENT_ON_NULL:
writer.keyword("ABSENT ON NULL");
break;
case NULL_ON_NULL:
writer.keyword("NULL ON NULL");
break;
default:
throw QueryException.error("Unknown SqlJsonConstructorNullClause constant: " + nullClause);
}
writer.endFunCall(frame);
}
use of org.apache.calcite.sql.SqlJsonConstructorNullClause in project hazelcast by hazelcast.
the class HazelcastJsonObjectFunction method unparse.
@Override
public void unparse(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) {
final SqlWriter.Frame frame = writer.startFunCall(this.getName());
if (call.operandCount() == 1) {
writer.endFunCall(frame);
return;
}
for (int i = 1; i < call.operandCount(); i += 2) {
writer.sep(",");
writer.keyword("KEY");
call.operand(i).unparse(writer, leftPrec, rightPrec);
writer.keyword("VALUE");
call.operand(i + 1).unparse(writer, leftPrec, rightPrec);
}
final SqlJsonConstructorNullClause nullClause = (SqlJsonConstructorNullClause) ((SqlLiteral) call.operand(0)).getValue();
switch(nullClause) {
case ABSENT_ON_NULL:
writer.keyword("ABSENT ON NULL");
break;
case NULL_ON_NULL:
writer.keyword("NULL ON NULL");
break;
default:
throw QueryException.error("Unknown SqlJsonConstructorNullClause constant: " + nullClause);
}
writer.endFunCall(frame);
}
use of org.apache.calcite.sql.SqlJsonConstructorNullClause in project flink by apache.
the class JsonObjectConverter method convert.
@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
checkArgument(call, (call.getChildren().size() - 1) % 2 == 0);
final List<RexNode> operands = new LinkedList<>();
final SqlJsonConstructorNullClause onNull = JsonConverterUtil.getOnNullArgument(call, 0);
operands.add(context.getRelBuilder().getRexBuilder().makeFlag(onNull));
for (int i = 1; i < call.getChildren().size(); i++) {
final Expression operand = call.getChildren().get(i);
if (i % 2 == 1 && !(operand instanceof ValueLiteralExpression)) {
throw new TableException(String.format("Argument at position %s must be a string literal.", i));
}
operands.add(context.toRexNode(operand));
}
return context.getRelBuilder().getRexBuilder().makeCall(FlinkSqlOperatorTable.JSON_OBJECT, operands);
}
Aggregations