示例#1
0
    def get_json_from_physical_plan(cls, pp):
        pps = pp

        # TODO This is not correct. The first argument is the raw query string,
        # not the string representation of the logical plan
        return compile_to_json("NOT_SOURCED_FROM_LOGICAL_RA", pps, pps,
                               "myrial")
示例#2
0
    def execute_query(self, query, test_logical=False, skip_json=False,
                      output="OUTPUT", algebra=MyriaLeftDeepTreeAlgebra):
        """Run a test query against the fake database"""

        dlog = RACompiler()
        dlog.fromDatalog(query)

        assert algebra in [MyriaLeftDeepTreeAlgebra,
                           MyriaHyperCubeAlgebra]

        if test_logical:
            plan = dlog.logicalplan
        else:
            if algebra == MyriaLeftDeepTreeAlgebra:
                dlog.optimize(MyriaLeftDeepTreeAlgebra())
            else:
                dlog.optimize(MyriaHyperCubeAlgebra(FakeCatalog(64)))
            plan = dlog.physicalplan

            if not skip_json:
                # test whether we can generate json without errors
                json_string = json.dumps(compile_to_json(
                    query, dlog.logicalplan, dlog.physicalplan, "datalog"))
                assert json_string

        self.db.evaluate(plan)
        return self.db.get_table(output)
示例#3
0
    def get_json_from_physical_plan(cls, pp):
        pps = pp

        # TODO This is not correct. The first argument is the raw query string,
        # not the string representation of the logical plan
        return compile_to_json(
            "NOT_SOURCED_FROM_LOGICAL_RA", pps, pps, "myrial")
示例#4
0
    def get_json(self, **kwargs):
        lp = self.get_logical_plan()
        pps = self.get_physical_plan(**kwargs)

        # TODO This is not correct. The first argument is the raw query string,
        # not the string representation of the logical plan
        return compile_to_json(str(lp), pps, pps, "myrial")
示例#5
0
 def to_json(self):
     """ Convert this query into an optimized JSON plan """
     # TODO deep copy, since optimize mutates
     sequence = Sequence([self.query])
     optimized = compile.optimize(sequence, OptLogicalAlgebra())
     myria = compile.optimize(optimized, MyriaLeftDeepTreeAlgebra())
     return compile_to_json(str(self.query), optimized, myria)
示例#6
0
    def get_json(self, **kwargs):
        lp = self.get_logical_plan()
        pps = self.get_physical_plan(**kwargs)

        # TODO This is not correct. The first argument is the raw query string,
        # not the string representation of the logical plan
        return compile_to_json(str(lp), pps, pps, "myrial")
示例#7
0
 def to_json(self):
     """ Convert this query into an optimized JSON plan """
     # TODO deep copy, since optimize mutates
     sequence = Sequence([self.query])
     optimized = compile.optimize(sequence, OptLogicalAlgebra())
     myria = compile.optimize(optimized, MyriaLeftDeepTreeAlgebra())
     return compile_to_json(str(self.query), optimized, myria)
示例#8
0
    def test_running_mean_stateful_apply(self):
        """Calculate the mean using stateful apply"""
        scan = Scan(TestQueryFunctions.emp_key, TestQueryFunctions.emp_schema)

        initex0 = NumericLiteral(0)
        updateex0 = PLUS(NamedStateAttributeRef("count"),
                         NumericLiteral(1))

        initex1 = NumericLiteral(0)
        updateex1 = PLUS(NamedStateAttributeRef("sum"),
                         NamedAttributeRef("salary"))

        avgex = IDIVIDE(NamedStateAttributeRef("sum"),
                        NamedStateAttributeRef("count"))

        sapply = StatefulApply([("avg", avgex)],
                               [StateVar("count", initex0, updateex0),
                                StateVar("sum", initex1, updateex1)], scan)

        store = Store(RelationKey("OUTPUT"), sapply)
        result = list(self.db.evaluate(sapply))

        self.assertEqual(len(result), len(TestQueryFunctions.emp_table))
        self.assertEqual([x[0] for x in result][-1], 37857)

        # test whether we can generate json without errors
        from raco.backends.myria import (compile_to_json,
                                         MyriaLeftDeepTreeAlgebra)
        from compile import optimize
        import json
        json_string = json.dumps(compile_to_json("", None, optimize(store, MyriaLeftDeepTreeAlgebra())))  # noqa
        assert json_string
示例#9
0
    def test_running_mean_stateful_apply(self):
        """Calculate the mean using stateful apply"""
        scan = Scan(TestQueryFunctions.emp_key, TestQueryFunctions.emp_schema)

        initex0 = NumericLiteral(0)
        updateex0 = PLUS(NamedStateAttributeRef("count"), NumericLiteral(1))

        initex1 = NumericLiteral(0)
        updateex1 = PLUS(NamedStateAttributeRef("sum"),
                         NamedAttributeRef("salary"))

        avgex = IDIVIDE(NamedStateAttributeRef("sum"),
                        NamedStateAttributeRef("count"))

        sapply = StatefulApply([("avg", avgex)], [
            StateVar("count", initex0, updateex0),
            StateVar("sum", initex1, updateex1)
        ], scan)

        store = Store(RelationKey("OUTPUT"), sapply)
        result = list(self.db.evaluate(sapply))

        self.assertEqual(len(result), len(TestQueryFunctions.emp_table))
        self.assertEqual([x[0] for x in result][-1], 37857)

        # test whether we can generate json without errors
        from raco.backends.myria import (compile_to_json,
                                         MyriaLeftDeepTreeAlgebra)
        from compile import optimize
        plan = compile_to_json("", None,
                               optimize(store,
                                        MyriaLeftDeepTreeAlgebra()))  # noqa
        for op in plan['plan']['fragments'][0]['operators']:
            if op['opType'] == 'StatefulApply':
                assert not any(exp is None for exp in op['emitExpressions'])
示例#10
0
    def execute_query(self,
                      query,
                      test_logical=False,
                      skip_json=False,
                      output="OUTPUT",
                      algebra=MyriaLeftDeepTreeAlgebra):
        """Run a test query against the fake database"""

        dlog = RACompiler()
        dlog.fromDatalog(query)

        assert algebra in [MyriaLeftDeepTreeAlgebra, MyriaHyperCubeAlgebra]

        if test_logical:
            plan = dlog.logicalplan
        else:
            if algebra == MyriaLeftDeepTreeAlgebra:
                dlog.optimize(MyriaLeftDeepTreeAlgebra())
            else:
                dlog.optimize(MyriaHyperCubeAlgebra(FakeCatalog(64)))
            plan = dlog.physicalplan

            if not skip_json:
                # test whether we can generate json without errors
                json_string = json.dumps(
                    compile_to_json(query, dlog.logicalplan, dlog.physicalplan,
                                    "datalog"))
                assert json_string

        self.db.evaluate(plan)
        return self.db.get_table(output)
示例#11
0
    def compile_program(self, program, language="MyriaL", **kwargs):
        """Get a compiled plan for a given program.

        Args:
            program: a Myria program as a string.
            language: the language in which the program is written
                      (default: MyriaL).
        """
        logical = self._get_plan(program, language, 'logical', **kwargs)
        physical = self._get_plan(program, language, 'physical', **kwargs)
        compiled = compile_to_json(program, logical, physical, language)
        compiled['profilingMode'] = ["QUERY", "RESOURCE"] \
            if kwargs.get('profile', False) else []
        return compiled
示例#12
0
    def execute_query(self, query, test_logical=False, skip_json=False):
        """Run a test query against the fake database"""
        plan = self.get_plan(query, logical=test_logical)

        if not test_logical and not skip_json:
            # Test that JSON compilation runs without error
            json_string = json.dumps(
                compile_to_json("some query", "some logical plan", plan,
                                "myrial"))
            assert json_string

        self.db.evaluate(plan)

        return self.db.get_table(self.output)
示例#13
0
    def compile_program(self, program, language="MyriaL", **kwargs):
        """Get a compiled plan for a given program.

        Args:
            program: a Myria program as a string.
            language: the language in which the program is written
                      (default: MyriaL).
        """
        logical = self._get_plan(program, language, 'logical', **kwargs)
        physical = self._get_plan(program, language, 'physical', **kwargs)
        compiled = compile_to_json(program, logical, physical, language)
        compiled['profilingMode'] = ["QUERY", "RESOURCE"] \
            if kwargs.get('profile', False) else []
        return compiled
示例#14
0
    def execute_query(self, query, test_logical=False, skip_json=False,
                      output='OUTPUT'):
        """Run a test query against the fake database"""
        plan = self.get_plan(query, logical=test_logical)

        if not test_logical and not skip_json:
            # Test that JSON compilation runs without error
            # TODO: verify the JSON output somehow?
            json_string = json.dumps(compile_to_json(
                "some query", "some logical plan", plan, "myrial"))
            assert json_string

        self.db.evaluate(plan)

        return self.db.get_table(output)