Exemplo n.º 1
0
 def test_transformed_field_values(self):
     expr = proto_test_util._get_expression_from_session_empty_user_info()
     reversed_events_expr = proto.create_transformed_field(
         expr, path.Path(["event"]), "reversed_event", _reverse_values)
     result = expression_test_util.calculate_list_map(
         reversed_events_expr.project(["reversed_event.action.doc_id"]),
         self)
     self.assertAllEqual(
         result["reversed_event.action.doc_id"],
         [[[[b"h"], [b"i"], [b"j"]], [[b"g"]], [[b"e"], [b"f"]]],
          [[[b"c"], []], [[b"a"], [b"b"]]]])
Exemplo n.º 2
0
 def test_transformed_field_values_with_transformed_parent(
     self, use_string_view):
   expr = proto_test_util._get_expression_from_session_empty_user_info()
   first_reversed_expr = proto.create_transformed_field(
       expr, path.Path(["event"]), "reversed_event", _reverse_values)
   second_reversed_expr = proto.create_transformed_field(
       first_reversed_expr, path.Path(["reversed_event", "action"]),
       "reversed_action", _reverse_values)
   result = expression_test_util.calculate_list_map(
       second_reversed_expr.project(["reversed_event.reversed_action.doc_id"]),
       self,
       options=self._get_calculate_options(use_string_view))
   self.assertAllEqual(result["reversed_event.reversed_action.doc_id"],
                       [[[[b"b"], [b"a"], []], [[b"c"]], [[b"f"], [b"e"]]],
                        [[[b"g"], [b"j"]], [[b"i"], [b"h"]]]])
   if use_string_view:
     self._check_string_view()
Exemplo n.º 3
0
  def test_project_proto_map(self, use_string_view):
    examples = [
        """
        features {
          feature {
            key: "feature1"
            value { bytes_list { value: ["hello", "world"] } }
          }
          feature {
            key: "feature2"
            value { float_list { value: 8.0 } }
          }
        }
        """, """
        features {
          feature {
            key: "feature1"
            value { bytes_list { value: "deadbeef" } }
          }
          feature {
            key: "feature3"
            value { int64_list { value: [123, 456] } }
          }
        }
        """
    ]
    expr = proto_test_util.text_to_expression(examples, tf.train.Example)
    result = expression_test_util.calculate_list_map(
        expr.project([
            "features.feature[feature1].bytes_list.value",
            "features.feature[feature2].float_list.value",
            "features.feature[feature3].int64_list.value",
        ]),
        self,
        options=self._get_calculate_options(use_string_view))

    feature1 = result["features.feature[feature1].bytes_list.value"]
    feature2 = result["features.feature[feature2].float_list.value"]
    feature3 = result["features.feature[feature3].int64_list.value"]
    self.assertAllEqual(feature1,
                        [[[[[b"hello", b"world"]]]], [[[[b"deadbeef"]]]]])
    self.assertAllEqual(feature2, [[[[[8.0]]]], [[]]])
    self.assertAllEqual(feature3, [[[]], [[[[123, 456]]]]])
    if use_string_view:
      self._check_string_view()
Exemplo n.º 4
0
    def test_project_proto_map_leaf_value(self):
        protos = [
            """
            int32_string_map {
              key: 222
              value: "2"
            }
            """
        ]

        expr = proto_test_util.text_to_expression(protos,
                                                  test_map_pb2.MessageWithMap)
        result = expression_test_util.calculate_list_map(
            expr.project([
                "int32_string_map[222]",
                "int32_string_map[223]",
            ]), self)
        self.assertLen(result, 2)
        self.assertAllEqual(result["int32_string_map[222]"], [[b"2"]])
        self.assertAllEqual(result["int32_string_map[223]"], [[]])