• 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, BinaryProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20from python.generators.diff_tests.testing import PrintProfileProto
21from google.protobuf import text_format
22
23
24class PerfettoTableFunction(TestSuite):
25
26  def test_create_table_function(self):
27    return DiffTestBlueprint(
28        trace=TextProto(""),
29        query="""
30        CREATE PERFETTO FUNCTION f(x INT) RETURNS TABLE(y INT) AS SELECT $x + 1 as y;
31
32        SELECT * FROM f(5);
33      """,
34        out=Csv("""
35        "y"
36        6
37      """))
38
39  def test_replace_table_function(self):
40    return DiffTestBlueprint(
41        trace=TextProto(""),
42        query="""
43        CREATE PERFETTO FUNCTION f(x INT) RETURNS TABLE(y INT) AS SELECT $x + 1 as y;
44        CREATE OR REPLACE PERFETTO FUNCTION f(x INT) RETURNS TABLE(y INT) AS SELECT $x + 2 as y;
45
46        SELECT * FROM f(5);
47      """,
48        out=Csv("""
49        "y"
50        7
51      """))
52
53  def test_legacy_create_view_function(self):
54    return DiffTestBlueprint(
55        trace=TextProto(""),
56        query="""
57        SELECT create_view_function('f(x INT)', 'result INT', 'SELECT $x + 1 as result');
58
59        SELECT * FROM f(5);
60      """,
61        out=Csv("""
62        "result"
63        6
64      """))
65
66  def test_legacy_table_function_drop_partial(self):
67    return DiffTestBlueprint(
68        trace=TextProto(""),
69        query="""
70          CREATE TABLE bar AS SELECT 1;
71
72          CREATE OR REPLACE PERFETTO FUNCTION foo()
73          RETURNS TABLE(x INT) AS
74          SELECT 1 AS x
75          UNION
76          SELECT * FROM bar;
77
78          CREATE TABLE res AS SELECT * FROM foo() LIMIT 1;
79
80          DROP TABLE bar;
81        """,
82        out=Csv(""))
83