-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore(bigframes): refactor "generate_bigframes_bigquery.py" #17904
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
Open
sycai
wants to merge
29
commits into
main
Choose a base branch
from
sycai_generator_refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b7e5a06
checkpoint: add logic for rendering signature template
sycai cc3288e
checkpoint: impl operator definition gen
sycai 8019f08
checkout: impl test generation
sycai 310a93a
checkpoint: refactor arg rendering
sycai 5ba9eb3
finish refactoring
sycai ab100cb
make old script still runnable
sycai f85141a
fix script reference
sycai 0e6d04a
fix lint
sycai 9353f35
Update packages/bigframes/scripts/bigquery_generator/__main__.py
sycai 78041aa
Update packages/bigframes/scripts/bigquery_generator/file_generator.py
sycai 4fd77b8
Update packages/bigframes/scripts/bigquery_generator/file_generator.py
sycai aa24eb9
Update packages/bigframes/scripts/bigquery_generator/file_generator.py
sycai 393010b
Update packages/bigframes/scripts/bigquery_generator/template_rendere…
sycai f1fea76
Update packages/bigframes/scripts/bigquery_generator/yaml_parser.py
sycai 70e9091
Update packages/bigframes/scripts/bigquery_generator/yaml_parser.py
sycai e1b8a37
Update packages/bigframes/scripts/bigquery_generator/yaml_parser.py
sycai aa1b51b
Update packages/bigframes/scripts/generate_bigframes_bigquery.py
sycai aa74300
Update packages/bigframes/scripts/bigquery_generator/template_rendere…
sycai dcbd2ea
Update packages/bigframes/scripts/bigquery_generator/template_rendere…
sycai a048b0c
fix lint
sycai e3fb8fd
fix import
sycai 3049a97
fix format
sycai 83b22f0
fix lint
sycai 4653ca0
Merge branch 'main' into sycai_generator_refactor
sycai 0eb0aef
Merge branch 'main' into sycai_generator_refactor
sycai ddc6d4c
update script path
sycai 8ef98b9
remove __main__.py from package
sycai bd136c6
update template loading and module-level docstrings
sycai 9ea30b8
fix format
sycai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2026 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. |
194 changes: 194 additions & 0 deletions
194
packages/bigframes/scripts/bigquery_generator/constants.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| # Copyright 2026 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. | ||
|
|
||
| import pathlib | ||
|
|
||
| import jinja2 | ||
|
|
||
| SCRIPTS_DIRECTORY = pathlib.Path(__file__).parent.parent.absolute() | ||
| PACKAGE_ROOT = SCRIPTS_DIRECTORY.parent | ||
| CODE_ROOT = PACKAGE_ROOT / "bigframes" | ||
| SCRIPT_PATH_RELATIVE = ( | ||
| pathlib.Path(__file__).relative_to(PACKAGE_ROOT).parent.parent | ||
| / "generate_bigframes_bigquery.py" | ||
| ) | ||
|
|
||
|
|
||
| # Directory containing the YAML files | ||
| DATA_DIR = SCRIPTS_DIRECTORY / "data" / "sql-functions" | ||
| # Directory where the generated Python files will be placed | ||
| OUTPUT_DIR = CODE_ROOT / "operations" / "googlesql" | ||
| # Directory where the generated test files will be placed | ||
| TEST_OUTPUT_DIR = PACKAGE_ROOT / "tests" / "unit" / "bigquery" / "generated" | ||
| # Directory containing the Jinja2 templates | ||
| TEMPLATE_DIR = SCRIPTS_DIRECTORY / "templates" | ||
|
|
||
| PYTHON_BUILTINS = { | ||
| "abs", | ||
| "all", | ||
| "any", | ||
| "ascii", | ||
| "bin", | ||
| "bool", | ||
| "breakpoint", | ||
| "bytearray", | ||
| "bytes", | ||
| "callable", | ||
| "chr", | ||
| "classmethod", | ||
| "compile", | ||
| "complex", | ||
| "delattr", | ||
| "dict", | ||
| "dir", | ||
| "divmod", | ||
| "enumerate", | ||
| "eval", | ||
| "exec", | ||
| "filter", | ||
| "float", | ||
| "format", | ||
| "frozenset", | ||
| "getattr", | ||
| "globals", | ||
| "hasattr", | ||
| "hash", | ||
| "help", | ||
| "hex", | ||
| "id", | ||
| "input", | ||
| "int", | ||
| "isinstance", | ||
| "issubclass", | ||
| "iter", | ||
| "len", | ||
| "list", | ||
| "locals", | ||
| "map", | ||
| "max", | ||
| "memoryview", | ||
| "min", | ||
| "next", | ||
| "object", | ||
| "oct", | ||
| "open", | ||
| "ord", | ||
| "pow", | ||
| "print", | ||
| "property", | ||
| "range", | ||
| "repr", | ||
| "reversed", | ||
| "round", | ||
| "set", | ||
| "setattr", | ||
| "slice", | ||
| "sorted", | ||
| "staticmethod", | ||
| "str", | ||
| "sum", | ||
| "super", | ||
| "tuple", | ||
| "type", | ||
| "vars", | ||
| "zip", | ||
| } | ||
|
|
||
| DTYPE_MAP = { | ||
| "binary": "dtypes.BYTES_DTYPE", | ||
| "string": "dtypes.STRING_DTYPE", | ||
| "int64": "dtypes.INT_DTYPE", | ||
| "i64": "dtypes.INT_DTYPE", | ||
| "float64": "dtypes.FLOAT_DTYPE", | ||
| "fp64": "dtypes.FLOAT_DTYPE", | ||
| "bool": "dtypes.BOOL_DTYPE", | ||
| "boolean": "dtypes.BOOL_DTYPE", | ||
| "geography": "dtypes.GEO_DTYPE", | ||
| "json": "dtypes.JSON_DTYPE", | ||
| "date": "dtypes.DATE_DTYPE", | ||
| "time": "dtypes.TIME_DTYPE", | ||
| "datetime": "dtypes.DATETIME_DTYPE", | ||
| "timestamp": "dtypes.TIMESTAMP_DTYPE", | ||
| "decimal<38,9>": "dtypes.NUMERIC_DTYPE", | ||
| "decimal<76,38>": "dtypes.BIGNUMERIC_DTYPE", | ||
| } | ||
|
|
||
| PY_TYPE_MAP = { | ||
| "binary": "bytes", | ||
| "string": "str", | ||
| "int64": "int", | ||
| "i64": "int", | ||
| "float64": "float", | ||
| "fp64": "float", | ||
| "bool": "bool", | ||
| "boolean": "bool", | ||
| "geography": "Any", | ||
| "json": "Any", | ||
| "date": "datetime.date", | ||
| "time": "datetime.time", | ||
| "datetime": "datetime.datetime", | ||
| "timestamp": "datetime.datetime", | ||
| "struct": "dict", | ||
| "decimal<38,9>": "decimal.Decimal", | ||
| "decimal<76,38>": "decimal.Decimal", | ||
| "interval_day": "datetime.timedelta", | ||
| } | ||
|
|
||
| RUFF_COMMON_ARGS = [ | ||
| "--target-version=py310", | ||
| "--line-length=88", | ||
| ] | ||
| RUFF_CHECK_ARGS = [ | ||
| "check", | ||
| "--select", | ||
| "I,F", | ||
| "--fix", | ||
| ] + RUFF_COMMON_ARGS | ||
| RUFF_FORMAT_ARGS = [ | ||
| "format", | ||
| ] + RUFF_COMMON_ARGS | ||
|
|
||
|
|
||
| def _load_templates() -> dict[str, jinja2.Template]: | ||
| env = jinja2.Environment( | ||
| loader=jinja2.FileSystemLoader(TEMPLATE_DIR), | ||
| trim_blocks=True, | ||
| lstrip_blocks=True, | ||
| ) | ||
| return { | ||
| "operation": env.get_template("operation.py.j2"), | ||
| "test_operation": env.get_template("test_operation.py.j2"), | ||
| "license": env.get_template("license.py.j2"), | ||
| "signature_def": env.get_template("signature_def.py.j2"), | ||
| "core_series_accessor": env.get_template("core_series_accessor.py.j2"), | ||
| "bigframes_series_accessor": env.get_template( | ||
| "bigframes_series_accessor.py.j2" | ||
| ), | ||
| "pandas_series_accessor": env.get_template("pandas_series_accessor.py.j2"), | ||
| } | ||
|
|
||
|
|
||
| TEMPLATES: dict[str, jinja2.Template] = _load_templates() | ||
|
|
||
|
|
||
| def __getattr__(name: str): | ||
| global _templates | ||
|
|
||
| if name != "TEMPLATES": | ||
| raise AttributeError(f"module '{__name__}' has no attribute '{name}'") | ||
|
|
||
| if _templates is None: | ||
| _templates = _load_templates() | ||
|
|
||
| return _templates |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (Optional): We don't have to put all constants here. I would prefer that they be defined closer to where they are used or in a purpose-specific module, such as with the templates logic or list of Python built-ins, but that's mostly just a personal preference.