Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c2009ed
docs: link to ML.EVALUATE BQML page for score() methods
ashleyxuu Oct 24, 2023
09ad5e4
feat: label query job with bigframes-api-xx using decorator
ashleyxuu Oct 25, 2023
4f4eb9b
reorganize the commit
ashleyxuu Oct 25, 2023
9ee937c
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Oct 26, 2023
272f0af
test: Log slowest tests durations (#146)
shobsi Oct 26, 2023
0e4c49c
docs: link to ML.EVALUATE BQML page for score() methods (#137)
ashleyxuu Oct 26, 2023
aad2c1a
feat: populate ibis version in user agent (#140)
ashleyxuu Oct 26, 2023
1043d6d
fix: don't override the global logging config (#138)
tswast Oct 26, 2023
1f49ef9
fix: use indexee's session for loc listlike cases (#152)
milkshakeiii Oct 26, 2023
c4c1e6e
feat: add pandas.qcut (#104)
TrevorBergeron Oct 26, 2023
4a27f44
feat: add unstack to series, add level param (#115)
TrevorBergeron Oct 26, 2023
fface57
feat: add `DataFrame.to_pandas_batches()` to download large `DataFram…
tswast Oct 26, 2023
bbc3c69
fix: resolve plotly rendering issue by using ipython html for job pro…
orrbradford Oct 26, 2023
a99d62c
refactor: ArrayValue is now a tree that defers conversion to ibis (#110)
TrevorBergeron Oct 27, 2023
f37d0b0
fix: fix bug with column names under repeated column assignment (#150)
milkshakeiii Oct 27, 2023
aba301c
test: refactor remote function tests (#147)
shobsi Oct 27, 2023
53bb2cd
feat: add dataframe melt (#116)
TrevorBergeron Oct 28, 2023
2bf4bcc
docs: add artithmetic df sample code (#153)
ashleyxuu Oct 30, 2023
343414a
feat: Implement operator `@` for `DataFrame.dot` (#139)
shobsi Oct 30, 2023
4eac10d
fix: fix typo and address comments
ashleyxuu Oct 30, 2023
868d2ad
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Oct 30, 2023
c03a8d9
Merge branch 'main' into ashleyxu-add-api-methods
tswast Nov 2, 2023
39321e4
fix: address comments
ashleyxuu Nov 3, 2023
aebcf11
Remove utils folder and refactor it in core directory
ashleyxuu Nov 3, 2023
72217c2
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 3, 2023
ec526b5
Remove utils folder and refactor it in core directory
ashleyxuu Nov 3, 2023
9edfe31
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 3, 2023
4baa373
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 3, 2023
3a94c23
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Nov 3, 2023
d84c569
fix merge conflicts
ashleyxuu Nov 3, 2023
308c9a7
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 3, 2023
4618107
commit the conflicts
ashleyxuu Nov 13, 2023
a87bcb8
redesign the log adapter
ashleyxuu Nov 14, 2023
cf97f8b
resolve conflicts and merge remote-tracking branch 'origin/main' into…
ashleyxuu Nov 14, 2023
53a99f9
Make the global _api_methods and lock threads
ashleyxuu Nov 14, 2023
3cc3599
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 14, 2023
1c3deb5
Make the global _api_methods and lock threads
ashleyxuu Nov 14, 2023
99f423b
merge conflicts
ashleyxuu Nov 14, 2023
115de27
address comments
ashleyxuu Nov 14, 2023
b0adf27
address comments
ashleyxuu Nov 14, 2023
b4ea9e3
Merge remote-tracking branch 'origin/ashleyxu-add-api-methods' into a…
ashleyxuu Nov 14, 2023
df9c9c0
fix error
ashleyxuu Nov 14, 2023
00bb6de
fix None job_config error
ashleyxuu Nov 14, 2023
36fea06
address comments
ashleyxuu Nov 14, 2023
e872d18
Merge branch 'main' into ashleyxu-add-api-methods
ashleyxuu Nov 14, 2023
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
Prev Previous commit
Next Next commit
redesign the log adapter
  • Loading branch information
ashleyxuu committed Nov 14, 2023
commit a87bcb85dd19f71b6e3a59a715d8e57c7e1cbf21
3 changes: 0 additions & 3 deletions bigframes/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import bigframes.core.compile.compiled as compiled
import bigframes.core.compile.compiler as compiler
import bigframes.core.guid
from bigframes.core.log_adapter import class_logger, method_logger
import bigframes.core.nodes as nodes
from bigframes.core.ordering import OrderingColumnReference
import bigframes.core.ordering as orderings
Expand All @@ -42,8 +41,6 @@
ORDER_ID_COLUMN = "bigframes_ordering_id"
PREDICATE_COLUMN = "bigframes_predicate"

__all__ = ["class_logger", "method_logger"]


@dataclass(frozen=True)
class ArrayValue:
Expand Down
64 changes: 49 additions & 15 deletions bigframes/core/log_adapter.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
import functools
# 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.

from loguru import logger
import functools
import threading

_log_file_path = None
_logger = logger
_api_methods = []
_lock = threading.Lock()
MAX_LABELS_COUNT = 64


def class_logger(decorated_cls):
def class_logger(api_methods=None):
"""Decorator that adds logging functionality to each method of the class."""
for attr_name, attr_value in decorated_cls.__dict__.items():
if callable(attr_value):
setattr(decorated_cls, attr_name, method_logger(attr_value))
return decorated_cls

def decorator(decorated_cls):
for attr_name, attr_value in decorated_cls.__dict__.items():
if callable(attr_value):
setattr(decorated_cls, attr_name, method_logger(attr_value))

# Initialize or extend _api_methods attribute
decorated_cls._api_methods = getattr(decorated_cls, "_api_methods", [])
if api_methods:
decorated_cls._api_methods.extend(api_methods)

return decorated_cls

def method_logger(method):
return decorator


def method_logger(method, cls):
"""Decorator that adds logging functionality to a method."""

@functools.wraps(method)
def wrapper(*args, **kwargs):
api_method_name = str(method.__name__)
# Track regular and "dunder" methods
if api_method_name.startswith("__") or not api_method_name.startswith("_"):
add_api_method(api_method_name)
add_api_method(api_method_name, cls)
try:
result = method(*args, **kwargs)
return result
Expand All @@ -33,6 +55,18 @@ def wrapper(*args, **kwargs):
return wrapper


def add_api_method(method: str):
global _api_methods
_api_methods.append(method)
def add_api_method(api_method_name, cls):
global _lock
with _lock:
# Push the method to the front of the _api_methods list
cls._api_methods.insert(0, api_method_name)
# Keep the list length within the maximum limit (adjust MAX_LABELS_COUNT as needed)
cls._api_methods = cls._api_methods[:MAX_LABELS_COUNT]


def get_and_reset_api_methods(cls):
global _lock
with _lock:
previous_api_methods = list(cls._api_methods)
cls._api_methods.clear()
return previous_api_methods
1 change: 1 addition & 0 deletions bigframes/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 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.

from __future__ import annotations

from dataclasses import dataclass, field
Expand Down
4 changes: 1 addition & 3 deletions bigframes/session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,14 +1365,12 @@ def _start_query(
"""
Starts query job and waits for results.
"""
api_methods = log_adapter._api_methods
api_methods = log_adapter.get_and_reset_api_methods(self)
job_config = self._prepare_job_config(job_config)
job_config.labels = bigframes_io.create_job_configs_labels(
job_configs_labels=job_config.labels, api_methods=api_methods
)
query_job = self.bqclient.query(sql, job_config=job_config)
# Clear out the global api logger
log_adapter._api_methods = []

opts = bigframes.options.display
if opts.progress_bar is not None and not query_job.configuration.dry_run:
Expand Down
2 changes: 1 addition & 1 deletion bigframes/session/_io/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_job_configs_labels(
labels = list(
itertools.chain(
job_configs_labels.keys(),
(f"bigframes-api-{i}" for i in range(len(api_methods))),
(f"recent-bigframes-api-{i}" for i in range(len(api_methods))),
)
)
values = list(itertools.chain(job_configs_labels.values(), api_methods))
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"sqlalchemy >=1.4,<3.0dev",
"ipywidgets >=7.7.1",
"humanize >= 4.6.0",
"loguru >=0.6.0",
]
extras = {
# Optional test dependencies packages. If they're missed, may skip some tests.
Expand Down
1 change: 0 additions & 1 deletion testing/constraints-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pytest-xdist==3.2.1
python-dateutil==2.8.2
pytz==2023.3
PyYAML==6.0
loguru==0.6.0
readme-renderer==37.3
requests==2.27.1
requests-oauthlib==1.3.1
Expand Down
Loading