Search in sources :

Example 1 with SqlJsonConstructorNullClause

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);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause)

Example 2 with SqlJsonConstructorNullClause

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);
}
Also used : SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause) LinkedList(java.util.LinkedList) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with SqlJsonConstructorNullClause

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);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause)

Example 4 with SqlJsonConstructorNullClause

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);
}
Also used : SqlWriter(org.apache.calcite.sql.SqlWriter) SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause)

Example 5 with SqlJsonConstructorNullClause

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);
}
Also used : TableException(org.apache.flink.table.api.TableException) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) SqlJsonConstructorNullClause(org.apache.calcite.sql.SqlJsonConstructorNullClause) LinkedList(java.util.LinkedList) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

SqlJsonConstructorNullClause (org.apache.calcite.sql.SqlJsonConstructorNullClause)6 SqlWriter (org.apache.calcite.sql.SqlWriter)3 LinkedList (java.util.LinkedList)2 RexNode (org.apache.calcite.rex.RexNode)2 HazelcastLikeOperator (com.hazelcast.jet.sql.impl.validate.operators.string.HazelcastLikeOperator)1 CaseExpression (com.hazelcast.sql.impl.expression.CaseExpression)1 CastExpression (com.hazelcast.sql.impl.expression.CastExpression)1 ConstantExpression (com.hazelcast.sql.impl.expression.ConstantExpression)1 Expression (com.hazelcast.sql.impl.expression.Expression)1 SearchableExpression (com.hazelcast.sql.impl.expression.SearchableExpression)1 SymbolExpression (com.hazelcast.sql.impl.expression.SymbolExpression)1 ExtractField (com.hazelcast.sql.impl.expression.datetime.ExtractField)1 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)1 TimeUnitRange (org.apache.calcite.avatica.util.TimeUnitRange)1 SqlFunction (org.apache.calcite.sql.SqlFunction)1 SqlJsonQueryEmptyOrErrorBehavior (org.apache.calcite.sql.SqlJsonQueryEmptyOrErrorBehavior)1 SqlJsonQueryWrapperBehavior (org.apache.calcite.sql.SqlJsonQueryWrapperBehavior)1 SqlJsonValueEmptyOrErrorBehavior (org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 SqlTrimFunction (org.apache.calcite.sql.fun.SqlTrimFunction)1