Search in sources :

Example 1 with TableValuedFunctionProto

use of com.google.zetasql.FunctionProtos.TableValuedFunctionProto in project beam by apache.

the class TVFScanConverter method getInputs.

@Override
public List<ResolvedNode> getInputs(ResolvedTVFScan zetaNode) {
    List<ResolvedNode> inputs = new ArrayList();
    if (zetaNode.getTvf() != null && context.getUserDefinedTableValuedFunctions().containsKey(zetaNode.getTvf().getNamePath())) {
        inputs.add(context.getUserDefinedTableValuedFunctions().get(zetaNode.getTvf().getNamePath()));
    }
    for (ResolvedFunctionArgument argument : zetaNode.getArgumentList()) {
        if (argument.getScan() != null) {
            inputs.add(argument.getScan());
        }
    }
    // Extract ResolvedArguments for solving ResolvedArgumentRef in later conversion.
    if (zetaNode.getTvf() instanceof FixedOutputSchemaTVF) {
        FileDescriptorSetsBuilder temp = new FileDescriptorSetsBuilder();
        // TODO: migrate to public Java API to retrieve FunctionSignature.
        TableValuedFunctionProto tableValuedFunctionProto = zetaNode.getTvf().serialize(temp);
        for (int i = 0; i < tableValuedFunctionProto.getSignature().getArgumentList().size(); i++) {
            String argumentName = tableValuedFunctionProto.getSignature().getArgument(i).getOptions().getArgumentName();
            if (zetaNode.getArgumentList().get(i).nodeKind() == ResolvedNodeKind.RESOLVED_FUNCTION_ARGUMENT) {
                ResolvedFunctionArgument resolvedTVFArgument = zetaNode.getArgumentList().get(i);
                if (resolvedTVFArgument.getExpr().nodeKind() == ResolvedNodeKind.RESOLVED_LITERAL) {
                    ResolvedLiteral literal = (ResolvedLiteral) resolvedTVFArgument.getExpr();
                    context.addToFunctionArgumentRefMapping(argumentName, getExpressionConverter().convertResolvedLiteral(literal));
                }
            }
        }
    }
    return inputs;
}
Also used : FixedOutputSchemaTVF(com.google.zetasql.TableValuedFunction.FixedOutputSchemaTVF) TableValuedFunctionProto(com.google.zetasql.FunctionProtos.TableValuedFunctionProto) FileDescriptorSetsBuilder(com.google.zetasql.FileDescriptorSetsBuilder) ResolvedNode(com.google.zetasql.resolvedast.ResolvedNode) ArrayList(java.util.ArrayList) ResolvedLiteral(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedLiteral) ResolvedFunctionArgument(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedFunctionArgument)

Aggregations

FileDescriptorSetsBuilder (com.google.zetasql.FileDescriptorSetsBuilder)1 TableValuedFunctionProto (com.google.zetasql.FunctionProtos.TableValuedFunctionProto)1 FixedOutputSchemaTVF (com.google.zetasql.TableValuedFunction.FixedOutputSchemaTVF)1 ResolvedNode (com.google.zetasql.resolvedast.ResolvedNode)1 ResolvedFunctionArgument (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedFunctionArgument)1 ResolvedLiteral (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedLiteral)1 ArrayList (java.util.ArrayList)1