示例#1
0
    def toPFA(self, options, context):
        expressions = [x for x in self.children if isinstance(x, Expression)]

        params = []
        for parameterField in self.ParameterField:
            if parameterField.dataType is None:
                raise TypeError("parameter field dataType needed for field \"{0}\" of function \"{1}\"".format(parameterField.name, self.name))
            params.append(parameterField.toPFA(options, context))

        symbolTable = {}
        for p in params:
            n = p.keys()[0]
            v = p.values()[0]
            symbolTable[n] = v

        expr = expressions[0].toPFA(options, context.copy(scope=symbolTable))

        inferred = ast.inferType(expr, symbolTable, fcns=context.fcns)

        if self.dataType is not None:
            declared = context.avroTypeBuilder.resolveOneType(json.dumps(self.pmmlTypeToAvro()))

            if not declared.accepts(inferred):
                raise TypeError("DefineFunction {0} has inferred type {1} and declared type {2}".format(self.name, repr(inferred), repr(declared)))

            ret = declared

            if not inferred.accepts(declared):
                expr = ast.Upcast(expr, context.avroTypeBuilder.makePlaceholder(json.dumps(self.pmmlTypeToAvro())))

        else:
            ret = inferred

        return self.name, ast.FcnDef(params, ret, [expr])
示例#2
0
    def toPFA(self, options, context):
        for child in self.children:
            if isinstance(child, Expression):
                expr = child.toPFA(options, context)
                inferred = ast.inferType(expr, context.symbolTable(), fcns=context.fcns)

                if self.dataType is not None:
                    declared = context.avroTypeBuilder.resolveOneType(json.dumps(self.pmmlTypeToAvro()))
                    if not declared.accepts(inferred):
                        raise TypeError("DerivedField {0} has inferred type {1} and declared type {2}".format(self.name, repr(inferred), repr(declared)))

                    context.scope[self.name] = declared

                    if not inferred.accepts(declared):
                        expr = ast.Upcast(expr, context.avroTypeBuilder.makePlaceholder(json.dumps(self.pmmlTypeToAvro())))

                else:
                    context.scope[self.name] = inferred

                return self.name, expr
示例#3
0
 def argTypes(self, args, context):
     return [ast.inferType(x, context.symbolTable(), fcns=context.fcns) for x in args]