示例#1
0
    def test_context_lookup_type_error(self):
        # type: () -> None
        ec = EvaluationContext(self.table_context)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table2')),
            EMPTY_NODE)

        path = ('my_table2', 'b')
        error = (
            r"path \('my_table2', 'b'\) \(canonicalized to key 'my_table2.b'\) "
            r"not present in type dict; columns available: \['my_table2.a'\]")

        # Delete the type mapping for this column to test the error
        del ec.canonical_column_to_type['my_table2.b']
        with self.assertRaisesRegexp(KeyError, error):
            ec.lookup(path)
示例#2
0
    def test_context_lookup_key_error(self):
        # type: () -> None
        ec = EvaluationContext(self.table_context)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table')),
            EMPTY_NODE)

        path = ('my_table', 'c')
        error = (
            r"path \('my_table', 'c'\) \(canonicalized to key 'my_table.c'\) "
            r"not present in table; columns available: \['my_table.a'\]")

        # Fake in an entry to the column -> table mapping to test the error
        ec.column_to_table_ids['c'] = ['my_table']
        with self.assertRaisesRegexp(KeyError, error):
            ec.lookup(path)
示例#3
0
    def test_context_lookup_success(self):
        # type: () -> None
        ec = EvaluationContext(self.table_context)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table')),
            EMPTY_NODE)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table2')),
            EMPTY_NODE)

        path = ('b', )
        result = ec.lookup(path)
        self.assertEqual(list(result.series), [2, 4])
        self.assertEqual(result.type_, BQScalarType.INTEGER)
示例#4
0
    def test_subcontext_lookup_success(self, path, expected_result):
        # type: (Tuple[str, ...], List[int]) -> None
        ec = EvaluationContext(self.table_context)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table')),
            EMPTY_NODE)
        ec.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table2')),
            EMPTY_NODE)
        subcontext = EvaluationContext(self.table_context)
        subcontext.add_table_from_node(
            TableReference(('my_project', 'my_dataset', 'my_table3')),
            EMPTY_NODE)
        ec.add_subcontext(subcontext)

        result = ec.lookup(path)
        self.assertEqual(list(result.series), expected_result)
        self.assertEqual(result.type_, BQScalarType.INTEGER)