Skip to content

Commit 4fb3a0d

Browse files
committed
NETFLIX-BUILD: Update integration tests for new DDL.
1 parent 623e501 commit 4fb3a0d

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

netflix/integration_tests.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import traceback
55
import unittest
66
import random
7+
import re
78
from pyspark.sql.utils import AnalysisException
89
from pyspark.sql import SparkSession
910
from pyspark.sql.functions import *
@@ -85,8 +86,11 @@ def __exit__(self, etype, evalue, traceback):
8586
sql("DROP TABLE IF EXISTS {0}".format(self.table_name))
8687
return False # don't suppress exceptions
8788

89+
def sort_by(col_name, rows):
90+
return sorted(rows, cmp = lambda a, b: cmp(a[col_name], b[col_name]))
91+
8892
def sort_by_id(rows):
89-
return sorted(rows, cmp = lambda a, b: cmp(a['id'], b['id']))
93+
return sort_by('id', rows)
9094

9195
def collect(df):
9296
return list(map(lambda r: r.asDict(), df.collect()))
@@ -176,6 +180,50 @@ class IcebergDDLTest(unittest.TestCase):
176180
# {'id': 3, 'data': 'c'}
177181
# ])
178182

183+
def test_show_create_table(self):
184+
with temp_table("test_show_create") as t:
185+
sql("CREATE TABLE {0} (id bigint, data string) USING iceberg", t)
186+
create_sql = collect(sql("SHOW CREATE TABLE {0}", t))[0]['create_statement']
187+
188+
quoted = '.'.join([ "`" + part + "`" for part in t.split('.') ])
189+
expected = "CREATE TABLE {0} ( id bigint, data string) USING iceberg".format(quoted)
190+
self.assertEqual(expected, re.sub(r"[\s]+", ' ', create_sql))
191+
192+
def test_create_table_like(self):
193+
with temp_table("test_source") as source:
194+
sql("CREATE TABLE {0} (id bigint, data string) USING iceberg", source)
195+
with temp_table("test_copy") as copy:
196+
sql("CREATE TABLE {0} LIKE {1}", copy, source)
197+
create_sql = collect(sql("SHOW CREATE TABLE {0}", copy))[0]['create_statement']
198+
199+
quoted = '.'.join([ "`" + part + "`" for part in copy.split('.') ])
200+
expected = "CREATE TABLE {0} ( id bigint, data string) USING iceberg".format(quoted)
201+
self.assertEqual(expected, re.sub(r"[\s]+", ' ', create_sql))
202+
203+
def test_alter_table_properties(self):
204+
with temp_table("test_table_properties") as t:
205+
sql("CREATE TABLE {0} (id bigint, data string) USING iceberg", t)
206+
rows = collect(sql("SHOW TBLPROPERTIES {0}", t))
207+
self.assertEqual(sort_by('property', rows), [
208+
{'property': 'provider', 'value': 'iceberg'}
209+
])
210+
211+
sql("ALTER TABLE {0} SET TBLPROPERTIES ('aa'='AA', 'zz'='ZZ')", t)
212+
213+
# test all table properties
214+
rows = collect(sql("SHOW TBLPROPERTIES {0}", t))
215+
self.assertEqual(sort_by('property', rows), [
216+
{'property': 'aa', 'value': 'AA'},
217+
{'property': 'provider', 'value': 'iceberg'},
218+
{'property': 'zz', 'value': 'ZZ'}
219+
])
220+
221+
# test single property lookup
222+
rows = collect(sql("SHOW TBLPROPERTIES {0} ('provider')", t))
223+
self.assertEqual(sort_by('property', rows), [
224+
{'property': 'provider', 'value': 'iceberg'}
225+
])
226+
179227
def test_alter_table_add_columns(self):
180228
with temp_table("test_add_columns") as t:
181229
sql("CREATE TABLE {0} (id bigint, data string) USING iceberg", t)

0 commit comments

Comments
 (0)