Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f29823

Browse filesBrowse files
authored
feat: add bigframes.bigquery.bit_count and conversion scalar function (#17433)
🦕
1 parent f006770 commit 7f29823
Copy full SHA for 7f29823

10 files changed

+868-3Lines changed: 868 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/bigframes/bigframes/bigquery/__init__.py‎

Copy file name to clipboardExpand all lines: packages/bigframes/bigframes/bigquery/__init__.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@
114114
flatten,
115115
generate_array,
116116
)
117+
from bigframes.operations.googlesql.global_namespace.bit import (
118+
bit_count,
119+
)
120+
from bigframes.operations.googlesql.global_namespace.conversion import (
121+
bool_,
122+
double,
123+
float64,
124+
int64,
125+
parse_bignumeric,
126+
parse_numeric,
127+
string,
128+
)
117129

118130
_functions = [
119131
# approximate aggregate ops
@@ -134,6 +146,16 @@
134146
array_to_string,
135147
flatten,
136148
generate_array,
149+
# bit ops
150+
bit_count,
151+
# conversion ops
152+
bool_,
153+
double,
154+
float64,
155+
int64,
156+
parse_bignumeric,
157+
parse_numeric,
158+
string,
137159
# datetime ops
138160
unix_micros,
139161
unix_millis,
@@ -208,6 +230,16 @@
208230
"array_to_string",
209231
"flatten",
210232
"generate_array",
233+
# bit ops
234+
"bit_count",
235+
# conversion ops
236+
"bool_",
237+
"double",
238+
"float64",
239+
"int64",
240+
"parse_bignumeric",
241+
"parse_numeric",
242+
"string",
211243
# datetime ops
212244
"unix_micros",
213245
"unix_millis",
Collapse file

‎packages/bigframes/bigframes/extensions/core/series_accessor.py‎

Copy file name to clipboardExpand all lines: packages/bigframes/bigframes/extensions/core/series_accessor.py
+154Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,160 @@ def flatten(
598598
)
599599
return self._to_series(cast(series.Series, result))
600600

601+
def bool_(
602+
self,
603+
*,
604+
session: Optional[bigframes.session.Session] = None,
605+
) -> S:
606+
"""Converts a JSON boolean to a SQL BOOL value."""
607+
from bigframes.operations.googlesql.global_namespace.conversion import (
608+
bool_ as bool__impl,
609+
)
610+
611+
bf_series = self._bf_from_series(session)
612+
result = bool__impl(
613+
bf_series,
614+
)
615+
return self._to_series(cast(series.Series, result))
616+
617+
def double(
618+
self,
619+
wide_number_mode: Union[
620+
series.Series,
621+
bigframes.core.col.Expression,
622+
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
623+
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
624+
*,
625+
session: Optional[bigframes.session.Session] = None,
626+
) -> S:
627+
"""Converts a JSON number to a SQL FLOAT64 value."""
628+
from bigframes.operations.googlesql.global_namespace.conversion import (
629+
double as double_impl,
630+
)
631+
632+
# Resolve session from other arguments if not passed
633+
if session is None:
634+
import bigframes.core.googlesql as googlesql
635+
636+
session = googlesql._find_session(
637+
wide_number_mode,
638+
)
639+
640+
bf_series = self._bf_from_series(session)
641+
result = double_impl(
642+
bf_series,
643+
wide_number_mode,
644+
)
645+
return self._to_series(cast(series.Series, result))
646+
647+
def float64(
648+
self,
649+
wide_number_mode: Union[
650+
series.Series,
651+
bigframes.core.col.Expression,
652+
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
653+
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
654+
*,
655+
session: Optional[bigframes.session.Session] = None,
656+
) -> S:
657+
"""Converts a JSON number to a SQL FLOAT64 value."""
658+
from bigframes.operations.googlesql.global_namespace.conversion import (
659+
float64 as float64_impl,
660+
)
661+
662+
# Resolve session from other arguments if not passed
663+
if session is None:
664+
import bigframes.core.googlesql as googlesql
665+
666+
session = googlesql._find_session(
667+
wide_number_mode,
668+
)
669+
670+
bf_series = self._bf_from_series(session)
671+
result = float64_impl(
672+
bf_series,
673+
wide_number_mode,
674+
)
675+
return self._to_series(cast(series.Series, result))
676+
677+
def int64(
678+
self,
679+
*,
680+
session: Optional[bigframes.session.Session] = None,
681+
) -> S:
682+
"""Converts a JSON number to a SQL INT64 value."""
683+
from bigframes.operations.googlesql.global_namespace.conversion import (
684+
int64 as int64_impl,
685+
)
686+
687+
bf_series = self._bf_from_series(session)
688+
result = int64_impl(
689+
bf_series,
690+
)
691+
return self._to_series(cast(series.Series, result))
692+
693+
def parse_bignumeric(
694+
self,
695+
*,
696+
session: Optional[bigframes.session.Session] = None,
697+
) -> S:
698+
"""Converts a STRING to a BIGNUMERIC value."""
699+
from bigframes.operations.googlesql.global_namespace.conversion import (
700+
parse_bignumeric as parse_bignumeric_impl,
701+
)
702+
703+
bf_series = self._bf_from_series(session)
704+
result = parse_bignumeric_impl(
705+
bf_series,
706+
)
707+
return self._to_series(cast(series.Series, result))
708+
709+
def parse_numeric(
710+
self,
711+
*,
712+
session: Optional[bigframes.session.Session] = None,
713+
) -> S:
714+
"""Converts a STRING to a NUMERIC value."""
715+
from bigframes.operations.googlesql.global_namespace.conversion import (
716+
parse_numeric as parse_numeric_impl,
717+
)
718+
719+
bf_series = self._bf_from_series(session)
720+
result = parse_numeric_impl(
721+
bf_series,
722+
)
723+
return self._to_series(cast(series.Series, result))
724+
725+
def string(
726+
self,
727+
timezone: Union[
728+
series.Series,
729+
bigframes.core.col.Expression,
730+
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
731+
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
732+
*,
733+
session: Optional[bigframes.session.Session] = None,
734+
) -> S:
735+
"""Converts a value to a STRING value."""
736+
from bigframes.operations.googlesql.global_namespace.conversion import (
737+
string as string_impl,
738+
)
739+
740+
# Resolve session from other arguments if not passed
741+
if session is None:
742+
import bigframes.core.googlesql as googlesql
743+
744+
session = googlesql._find_session(
745+
timezone,
746+
)
747+
748+
bf_series = self._bf_from_series(session)
749+
result = string_impl(
750+
bf_series,
751+
timezone,
752+
)
753+
return self._to_series(cast(series.Series, result))
754+
601755

602756
class AeadSeriesAccessor(AbstractBigQuerySeriesAccessor[S]):
603757
"""Series accessor for BigQuery aead functions."""
Collapse file
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# DO NOT MODIFY THIS FILE DIRECTLY.
16+
# This file was generated from: scripts/data/sql-functions/global_namespace/bit.yaml
17+
# by the script: scripts/generate_bigframes_bigquery.py
18+
19+
from __future__ import annotations
20+
21+
from typing import Any, Literal, Union
22+
23+
import bigframes.core.col
24+
import bigframes.core.googlesql
25+
import bigframes.core.sentinels as sentinels
26+
import bigframes.series as series
27+
from bigframes import dtypes
28+
from bigframes.operations import googlesql
29+
30+
_BIT_COUNT_OP = googlesql.GoogleSqlScalarOp(
31+
"BIT_COUNT",
32+
args=(googlesql.ArgSpec(),),
33+
signature=lambda *args: dtypes.INT_DTYPE,
34+
)
35+
36+
37+
def bit_count(
38+
expression: Union[
39+
series.Series,
40+
bigframes.core.col.Expression,
41+
Union[Any, Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, int],
42+
],
43+
) -> Union[series.Series, bigframes.core.col.Expression]:
44+
"""The input, `expression`, must be an integer or `BYTES`. Returns the number of bits that are set in the input expression. For signed integers, this is the number of bits in two's complement form."""
45+
return bigframes.core.googlesql.apply_googlesql_scalar_op(
46+
_BIT_COUNT_OP,
47+
expression,
48+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.