Skip to content

refactor: move DDL gen to bigframes.session._io, add missing test #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bigframes/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import bigframes.core.guid
import bigframes.core.indexers as indexers
import bigframes.core.indexes as indexes
import bigframes.core.io
import bigframes.core.ordering as order
import bigframes.core.utils as utils
import bigframes.core.window
Expand All @@ -56,6 +55,7 @@
import bigframes.operations.aggregations as agg_ops
import bigframes.series
import bigframes.series as bf_series
import bigframes.session._io.bigquery
import third_party.bigframes_vendored.pandas.core.frame as vendored_pandas_frame
import third_party.bigframes_vendored.pandas.pandas._typing as vendored_pandas_typing

Expand Down Expand Up @@ -2201,9 +2201,9 @@ def to_csv(
raise NotImplementedError(ERROR_IO_REQUIRES_WILDCARD)

result_table = self._run_io_query(
index=index, ordering_id=bigframes.core.io.IO_ORDERING_ID
index=index, ordering_id=bigframes.session._io.bigquery.IO_ORDERING_ID
)
export_data_statement = bigframes.core.io.create_export_csv_statement(
export_data_statement = bigframes.session._io.bigquery.create_export_csv_statement(
f"{result_table.project}.{result_table.dataset_id}.{result_table.table_id}",
uri=path_or_buf,
field_delimiter=sep,
Expand Down Expand Up @@ -2243,9 +2243,9 @@ def to_json(
)

result_table = self._run_io_query(
index=index, ordering_id=bigframes.core.io.IO_ORDERING_ID
index=index, ordering_id=bigframes.session._io.bigquery.IO_ORDERING_ID
)
export_data_statement = bigframes.core.io.create_export_data_statement(
export_data_statement = bigframes.session._io.bigquery.create_export_data_statement(
f"{result_table.project}.{result_table.dataset_id}.{result_table.table_id}",
uri=path_or_buf,
format="JSON",
Expand Down Expand Up @@ -2319,9 +2319,9 @@ def to_parquet(
export_options["compression"] = compression.upper()

result_table = self._run_io_query(
index=index, ordering_id=bigframes.core.io.IO_ORDERING_ID
index=index, ordering_id=bigframes.session._io.bigquery.IO_ORDERING_ID
)
export_data_statement = bigframes.core.io.create_export_data_statement(
export_data_statement = bigframes.session._io.bigquery.create_export_data_statement(
f"{result_table.project}.{result_table.dataset_id}.{result_table.table_id}",
uri=path,
format="PARQUET",
Expand Down
2 changes: 1 addition & 1 deletion bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
import bigframes.core as core
import bigframes.core.blocks as blocks
import bigframes.core.guid as guid
import bigframes.core.io as bigframes_io
from bigframes.core.ordering import IntegerEncoding, OrderingColumnReference
import bigframes.core.utils as utils
import bigframes.dataframe as dataframe
import bigframes.formatting_helpers as formatting_helpers
from bigframes.remote_function import read_gbq_function as bigframes_rgf
from bigframes.remote_function import remote_function as bigframes_rf
import bigframes.session._io.bigquery as bigframes_io
import bigframes.session.clients
import bigframes.version

Expand Down
13 changes: 13 additions & 0 deletions bigframes/session/_io/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import google.cloud.bigquery as bigquery
import pytest

import bigframes.core.io
import bigframes.session._io.bigquery


def test_create_snapshot_sql_doesnt_timetravel_anonymous_datasets():
table_ref = bigquery.TableReference.from_string(
"my-test-project._e8166e0cdb.anonbb92cd"
)

sql = bigframes.core.io.create_snapshot_sql(
sql = bigframes.session._io.bigquery.create_snapshot_sql(
table_ref, datetime.datetime.now(datetime.timezone.utc)
)

Expand All @@ -40,7 +40,7 @@ def test_create_snapshot_sql_doesnt_timetravel_anonymous_datasets():
def test_create_snapshot_sql_doesnt_timetravel_session_datasets():
table_ref = bigquery.TableReference.from_string("my-test-project._session.abcdefg")

sql = bigframes.core.io.create_snapshot_sql(
sql = bigframes.session._io.bigquery.create_snapshot_sql(
table_ref, datetime.datetime.now(datetime.timezone.utc)
)

Expand Down Expand Up @@ -101,4 +101,5 @@ def test_create_snapshot_sql_doesnt_timetravel_session_datasets():
),
)
def test_bq_schema_to_sql(schema: Iterable[bigquery.SchemaField], expected: str):
pass
sql = bigframes.session._io.bigquery.bq_schema_to_sql(schema)
assert sql == expected