Last active
June 25, 2024 21:26
-
-
Save bearloga/b0ca0b3ebd7ca427beeb68fe920a66e7 to your computer and use it in GitHub Desktop.
T368326: Data modeling multiple experiments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Usage: spark3-sql -f demo_data.sql -d db=bearloga | |
| DROP TABLE IF EXISTS ${db}.demo_data_v1; | |
| CREATE TABLE IF NOT EXISTS ${db}.demo_data_v1 ( | |
| user_id int, | |
| action string, | |
| experiments array<map<string, string>> | |
| ) | |
| LOCATION '/tmp/${db}/demo_data_v1'; | |
| INSERT INTO ${db}.demo_data_v1 (user_id, action, experiments) VALUES | |
| (1, 'click', ARRAY(MAP('name', 'test1', 'group', 'a'), MAP('name', 'test2', 'group', 'b'))), | |
| (2, 'click', ARRAY()), | |
| (3, 'click', ARRAY(MAP('name', 'test2', 'group', 'a'))), | |
| (4, 'click', ARRAY(MAP('name', 'test1', 'group', 'b'), MAP('name', 'test2', 'group', 'a'))) | |
| ; | |
| DROP TABLE IF EXISTS ${db}.demo_data_v2; | |
| CREATE TABLE IF NOT EXISTS ${db}.demo_data_v2 ( | |
| user_id int, | |
| action string, | |
| experiments struct<enrolled:array<string>, assigned:map<string, string>> | |
| ) | |
| LOCATION '/tmp/${db}/demo_data_v2'; | |
| INSERT INTO ${db}.demo_data_v2 (user_id, action, experiments) VALUES | |
| (1, 'click', NAMED_STRUCT('enrolled', ARRAY('test1', 'test2'), 'assigned', MAP('test1', 'a', 'test2', 'b'))), | |
| (2, 'click', NAMED_STRUCT('enrolled', ARRAY(), 'assigned', NULL)), | |
| (3, 'click', NAMED_STRUCT('enrolled', ARRAY('test2'), 'assigned', MAP('test2', 'a'))), | |
| (4, 'click', NAMED_STRUCT('enrolled', ARRAY('test1', 'test2'), 'assigned', MAP('test1', 'b', 'test2', 'a'))) | |
| ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment