|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | + |
| 14 | +importbigframes.core.sql.io |
| 15 | + |
| 16 | + |
| 17 | +deftest_load_data_ddl(): |
| 18 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 19 | +"my-project.my_dataset.my_table", |
| 20 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 21 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 22 | + ) |
| 23 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) FROM FILES (format = 'CSV', uris = ['gs://bucket/path*'])" |
| 24 | +assertsql==expected |
| 25 | + |
| 26 | + |
| 27 | +deftest_load_data_ddl_overwrite(): |
| 28 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 29 | +"my-project.my_dataset.my_table", |
| 30 | +write_disposition="OVERWRITE", |
| 31 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 32 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 33 | + ) |
| 34 | +expected="LOAD DATA OVERWRITE my-project.my_dataset.my_table (col1 INT64, col2 STRING) FROM FILES (format = 'CSV', uris = ['gs://bucket/path*'])" |
| 35 | +assertsql==expected |
| 36 | + |
| 37 | + |
| 38 | +deftest_load_data_ddl_with_partition_columns(): |
| 39 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 40 | +"my-project.my_dataset.my_table", |
| 41 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 42 | +with_partition_columns={"part1": "DATE", "part2": "STRING"}, |
| 43 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 44 | + ) |
| 45 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) FROM FILES (format = 'CSV', uris = ['gs://bucket/path*']) WITH PARTITION COLUMNS (part1 DATE, part2 STRING)" |
| 46 | +assertsql==expected |
| 47 | + |
| 48 | + |
| 49 | +deftest_load_data_ddl_connection(): |
| 50 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 51 | +"my-project.my_dataset.my_table", |
| 52 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 53 | +connection_name="my-connection", |
| 54 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 55 | + ) |
| 56 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) FROM FILES (format = 'CSV', uris = ['gs://bucket/path*']) WITH CONNECTION `my-connection`" |
| 57 | +assertsql==expected |
| 58 | + |
| 59 | + |
| 60 | +deftest_load_data_ddl_partition_by(): |
| 61 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 62 | +"my-project.my_dataset.my_table", |
| 63 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 64 | +partition_by=["date_col"], |
| 65 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 66 | + ) |
| 67 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) PARTITION BY date_col FROM FILES (format = 'CSV', uris = ['gs://bucket/path*'])" |
| 68 | +assertsql==expected |
| 69 | + |
| 70 | + |
| 71 | +deftest_load_data_ddl_cluster_by(): |
| 72 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 73 | +"my-project.my_dataset.my_table", |
| 74 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 75 | +cluster_by=["cluster_col"], |
| 76 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 77 | + ) |
| 78 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) CLUSTER BY cluster_col FROM FILES (format = 'CSV', uris = ['gs://bucket/path*'])" |
| 79 | +assertsql==expected |
| 80 | + |
| 81 | + |
| 82 | +deftest_load_data_ddl_table_options(): |
| 83 | +sql=bigframes.core.sql.io.load_data_ddl( |
| 84 | +"my-project.my_dataset.my_table", |
| 85 | +columns={"col1": "INT64", "col2": "STRING"}, |
| 86 | +table_options={"description": "my table"}, |
| 87 | +from_files_options={"format": "CSV", "uris": ["gs://bucket/path*"]}, |
| 88 | + ) |
| 89 | +expected="LOAD DATA INTO my-project.my_dataset.my_table (col1 INT64, col2 STRING) OPTIONS (description = 'my table') FROM FILES (format = 'CSV', uris = ['gs://bucket/path*'])" |
| 90 | +assertsql==expected |
0 commit comments