Example #1
0
    def testDataModelQuery(self):
        """Test case A. note that all test method names must begin with 'test.'"""

        qm1 = query_pb2.Query.Model()
        dmq1 = qm1.model
        dmq1.name = "sunshine"
        dmq1.description = "Give me some weather data"
        dmq1.attributes.extend([
            get_attr_b("wind_stuff", "Is windy outside?"),
            get_attr_b("celsius", "Freezing or warm?"),
            get_attr_b("pascal", "Under pressure")
        ])

        qm2 = query_pb2.Query.Model()
        dmq2 = qm2.model
        dmq2.name = "novels"
        dmq2.description = "I want to read novels"
        dmq2.attributes.extend([
            get_attr_b("name", "Novel has a name"),
            get_attr_b("writer", "Somebody has written the pages"),
        ])

        print(
            "======================================QUERY WEATHER======================================"
        )
        print(dmq1)
        print(
            "======================================QUERY BOOK======================================"
        )
        print(dmq2)

        qproto = dap_interface_pb2.ConstructQueryConstraintObjectRequest()
        qproto.operator = "CLOSE_TO"
        qproto.target_table_name = "dm_store"
        qproto.target_field_name = "data_model"
        qproto.target_field_type = "data_model"
        qproto.query_field_type = "data_model"
        qproto.query_field_value.typecode = "data_model"
        qproto.query_field_value.dm.CopyFrom(dmq1)
        qproto.dap_name = "search_engine"
        memento = self.se.prepareConstraint(qproto)

        query_memento = dap_interface_pb2.DapExecute()
        query_memento.input_idents.originator = True
        query_memento.query_memento.CopyFrom(memento)

        results1 = list(self.se.execute(query_memento).identifiers)

        qproto.query_field_value.dm.CopyFrom(dmq2)
        memento = self.se.prepareConstraint(qproto)
        query_memento.query_memento.CopyFrom(memento)
        results2 = list(self.se.execute(query_memento).identifiers)

        print("Looking for weather")
        print(results1)
        print("Looking for book")
        print(results2)
        assert len(results1) == 2
        assert len(results2) == 2
        def toProto(self, dap_name):
            pb = dap_interface_pb2.ConstructQueryConstraintObjectRequest()

            v = DapInterface.encodeConstraintValue(self.query_field_value, self.query_field_type, self.log)

            pb.query_field_value.CopyFrom(v)
            pb.node_name = self.name

            pb.operator          = self.operator
            pb.query_field_type  = self.query_field_type
            pb.target_field_name = self.target_field_name

            pb.target_field_type = self.dap_field_candidates.get(dap_name, {}).get('target_field_type', "")
            pb.target_table_name = self.dap_field_candidates.get(dap_name, {}).get('target_table_name', "")

            pb.dap_name          = dap_name

            if self.name != None:
                pb.node_name = self.name
            return pb
Example #3
0
    def testStringQuery(self):
        """Test case A. note that all test method names must begin with 'test.'"""

        sq1 = "I'm looking for weather data. Sunshine or rain? Would be nice to know about" \
              " wind speed, temperature in celsius and pressure."
        sq2 = "I want to read novels. All novels has a name, and somebody who wrote it!"
        print(
            "======================================QUERY WEATHER======================================"
        )
        print(sq1)
        print(
            "======================================QUERY NOVEL======================================"
        )
        print(sq2)

        qproto = dap_interface_pb2.ConstructQueryConstraintObjectRequest()
        qproto.operator = "CLOSE_TO"
        qproto.target_table_name = "dm_store"
        qproto.target_field_name = "data_model"
        qproto.target_field_type = "data_model"
        qproto.query_field_type = "string"
        qproto.query_field_value.typecode = "string"
        qproto.query_field_value.s = sq1
        qproto.dap_name = "search_engine"
        memento = self.se.prepareConstraint(qproto)

        query_memento = dap_interface_pb2.DapExecute()
        query_memento.input_idents.originator = True
        query_memento.query_memento.CopyFrom(memento)

        results1 = list(self.se.execute(query_memento).identifiers)

        qproto.query_field_value.s = sq2
        memento = self.se.prepareConstraint(qproto)
        query_memento.query_memento.CopyFrom(memento)
        results2 = list(self.se.execute(query_memento).identifiers)

        print("Looking for weather")
        print("Looking for book")
        assert len(results1) == 2
        assert len(results2) == 2