• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 2023 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License a
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from python.generators.diff_tests.testing import Path, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class SpanJoinLeftJoin(TestSuite):
23
24  def test_span_left_join(self):
25    return DiffTestBlueprint(
26        trace=Path('../../common/synth_1.py'),
27        query=Path('span_left_join_test.sql'),
28        out=Path('span_left_join.out'))
29
30  def test_span_left_join_unpartitioned(self):
31    return DiffTestBlueprint(
32        trace=Path('../../common/synth_1.py'),
33        query=Path('span_left_join_unpartitioned_test.sql'),
34        out=Path('span_left_join_unpartitioned.out'))
35
36  def test_span_left_join_left_unpartitioned(self):
37    return DiffTestBlueprint(
38        trace=Path('../../common/synth_1.py'),
39        query=Path('span_left_join_left_unpartitioned_test.sql'),
40        out=Path('span_left_join_left_unpartitioned.out'))
41
42  def test_span_left_join_left_partitioned(self):
43    return DiffTestBlueprint(
44        trace=Path('../../common/synth_1.py'),
45        query=Path('span_left_join_left_partitioned_test.sql'),
46        out=Path('span_left_join_left_partitioned.out'))
47
48  def test_span_left_join_empty_right(self):
49    return DiffTestBlueprint(
50        trace=Path('../../common/synth_1.py'),
51        query="""
52        CREATE TABLE t1(
53          ts BIGINT,
54          dur BIGINT,
55          part BIGINT,
56          PRIMARY KEY (part, ts)
57        ) WITHOUT ROWID;
58
59        CREATE TABLE t2(
60          ts BIGINT,
61          dur BIGINT,
62          part BIGINT,
63          PRIMARY KEY (part, ts)
64        ) WITHOUT ROWID;
65
66        INSERT INTO t1(ts, dur, part)
67        VALUES
68        (500, 500, 100);
69
70        CREATE VIRTUAL TABLE sp USING span_left_join(t1 PARTITIONED part,
71                                                     t2 PARTITIONED part);
72
73        SELECT * FROM sp;
74        """,
75        out=Csv("""
76        "ts","dur","part"
77        500,500,100
78        """))
79
80  def test_span_left_join_unordered_android_sched_and_ps(self):
81    return DiffTestBlueprint(
82        trace=Path('../../common/synth_1.py'),
83        query="""
84        CREATE TABLE t1(
85          ts BIGINT,
86          dur BIGINT,
87          part BIGINT,
88          PRIMARY KEY (part, ts)
89        ) WITHOUT ROWID;
90
91        CREATE TABLE t2(
92          ts BIGINT,
93          dur BIGINT,
94          part BIGINT,
95          PRIMARY KEY (part, ts)
96        ) WITHOUT ROWID;
97
98        INSERT INTO t1(ts, dur, part)
99        VALUES (500, 100, 10);
100
101        INSERT INTO t2(ts, dur, part)
102        VALUES (500, 100, 5);
103
104        CREATE VIRTUAL TABLE sp USING span_left_join(t1 PARTITIONED part,
105                                                     t2 PARTITIONED part);
106
107        SELECT * FROM sp;
108        """,
109        out=Csv("""
110        "ts","dur","part"
111        500,100,10
112        """))
113