Search in sources :

Example 1 with UpdateAction

use of org.apache.spark.sql.execution.command.mutation.merge.UpdateAction in project carbondata by apache.

the class CarbonAntlrSqlVisitor method visitCarbonAssignmentList.

public MergeAction visitCarbonAssignmentList(CarbonSqlBaseParser.AssignmentListContext ctx) throws MalformedCarbonCommandException {
    // UPDATE SET assignmentList
    Map<Column, Column> map = new HashMap<>();
    for (int currIdx = 0; currIdx < ctx.getChildCount(); currIdx++) {
        if (ctx.getChild(currIdx) instanceof CarbonSqlBaseParser.AssignmentContext) {
            // Assume the actions are all use to pass value
            String left = ctx.getChild(currIdx).getChild(0).getText();
            if (left.split("\\.").length > 1) {
                left = left.split("\\.")[1];
            }
            String right = ctx.getChild(currIdx).getChild(2).getText();
            Column rightColumn = null;
            try {
                Expression expression = sparkParser.parseExpression(right);
                rightColumn = new Column(expression);
            } catch (Exception e) {
                throw new MalformedCarbonCommandException("Parse failed: " + e.getMessage());
            }
            map.put(new Column(left), rightColumn);
        }
    }
    return new UpdateAction(SparkUtil.convertMap(map), false);
}
Also used : HashMap(java.util.HashMap) Expression(org.apache.spark.sql.catalyst.expressions.Expression) CarbonJoinExpression(org.apache.spark.sql.merge.model.CarbonJoinExpression) UpdateAction(org.apache.spark.sql.execution.command.mutation.merge.UpdateAction) MalformedCarbonCommandException(org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException) ParseException(org.apache.spark.sql.catalyst.parser.ParseException) MalformedCarbonCommandException(org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException)

Aggregations

HashMap (java.util.HashMap)1 MalformedCarbonCommandException (org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException)1 Expression (org.apache.spark.sql.catalyst.expressions.Expression)1 ParseException (org.apache.spark.sql.catalyst.parser.ParseException)1 UpdateAction (org.apache.spark.sql.execution.command.mutation.merge.UpdateAction)1 CarbonJoinExpression (org.apache.spark.sql.merge.model.CarbonJoinExpression)1