Skip to content
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
32 changes: 32 additions & 0 deletions packages/bigframes/bigframes/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
flatten,
generate_array,
)
from bigframes.operations.googlesql.global_namespace.bit import (
bit_count,
)
from bigframes.operations.googlesql.global_namespace.conversion import (
bool_,
double,
float64,
int64,
parse_bignumeric,
parse_numeric,
string,
)

_functions = [
# approximate aggregate ops
Expand All @@ -134,6 +146,16 @@
array_to_string,
flatten,
generate_array,
# bit ops
bit_count,
# conversion ops
bool_,
double,
float64,
int64,
parse_bignumeric,
parse_numeric,
string,
# datetime ops
unix_micros,
unix_millis,
Expand Down Expand Up @@ -208,6 +230,16 @@
"array_to_string",
"flatten",
"generate_array",
# bit ops
"bit_count",
# conversion ops
"bool_",
"double",
"float64",
"int64",
"parse_bignumeric",
"parse_numeric",
"string",
# datetime ops
"unix_micros",
"unix_millis",
Expand Down
154 changes: 154 additions & 0 deletions packages/bigframes/bigframes/extensions/core/series_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,160 @@ def flatten(
)
return self._to_series(cast(series.Series, result))

def bool_(
self,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a JSON boolean to a SQL BOOL value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
bool_ as bool__impl,
)

bf_series = self._bf_from_series(session)
result = bool__impl(
bf_series,
)
return self._to_series(cast(series.Series, result))

def double(
self,
wide_number_mode: Union[
series.Series,
bigframes.core.col.Expression,
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a JSON number to a SQL FLOAT64 value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
double as double_impl,
)

# Resolve session from other arguments if not passed
if session is None:
import bigframes.core.googlesql as googlesql

session = googlesql._find_session(
wide_number_mode,
)

bf_series = self._bf_from_series(session)
result = double_impl(
bf_series,
wide_number_mode,
)
return self._to_series(cast(series.Series, result))

def float64(
self,
wide_number_mode: Union[
series.Series,
bigframes.core.col.Expression,
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a JSON number to a SQL FLOAT64 value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
float64 as float64_impl,
)

# Resolve session from other arguments if not passed
if session is None:
import bigframes.core.googlesql as googlesql

session = googlesql._find_session(
wide_number_mode,
)

bf_series = self._bf_from_series(session)
result = float64_impl(
bf_series,
wide_number_mode,
)
return self._to_series(cast(series.Series, result))

def int64(
self,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a JSON number to a SQL INT64 value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
int64 as int64_impl,
)

bf_series = self._bf_from_series(session)
result = int64_impl(
bf_series,
)
return self._to_series(cast(series.Series, result))

def parse_bignumeric(
self,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a STRING to a BIGNUMERIC value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
parse_bignumeric as parse_bignumeric_impl,
)

bf_series = self._bf_from_series(session)
result = parse_bignumeric_impl(
bf_series,
)
return self._to_series(cast(series.Series, result))

def parse_numeric(
self,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a STRING to a NUMERIC value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
parse_numeric as parse_numeric_impl,
)

bf_series = self._bf_from_series(session)
result = parse_numeric_impl(
bf_series,
)
return self._to_series(cast(series.Series, result))

def string(
self,
timezone: Union[
series.Series,
bigframes.core.col.Expression,
Union[Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], str],
] = sentinels.Sentinel.ARGUMENT_DEFAULT,
*,
session: Optional[bigframes.session.Session] = None,
) -> S:
"""Converts a value to a STRING value."""
from bigframes.operations.googlesql.global_namespace.conversion import (
string as string_impl,
)

# Resolve session from other arguments if not passed
if session is None:
import bigframes.core.googlesql as googlesql

session = googlesql._find_session(
timezone,
)

bf_series = self._bf_from_series(session)
result = string_impl(
bf_series,
timezone,
)
return self._to_series(cast(series.Series, result))


class AeadSeriesAccessor(AbstractBigQuerySeriesAccessor[S]):
"""Series accessor for BigQuery aead functions."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.
#
# DO NOT MODIFY THIS FILE DIRECTLY.
# This file was generated from: scripts/data/sql-functions/global_namespace/bit.yaml
# by the script: scripts/generate_bigframes_bigquery.py

from __future__ import annotations

from typing import Any, Literal, Union

import bigframes.core.col
import bigframes.core.googlesql
import bigframes.core.sentinels as sentinels
import bigframes.series as series
from bigframes import dtypes
from bigframes.operations import googlesql

_BIT_COUNT_OP = googlesql.GoogleSqlScalarOp(
"BIT_COUNT",
args=(googlesql.ArgSpec(),),
signature=lambda *args: dtypes.INT_DTYPE,
)


def bit_count(
expression: Union[
series.Series,
bigframes.core.col.Expression,
Union[Any, Literal[sentinels.Sentinel.ARGUMENT_DEFAULT], bytes, int],
],
) -> Union[series.Series, bigframes.core.col.Expression]:
"""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."""
return bigframes.core.googlesql.apply_googlesql_scalar_op(
_BIT_COUNT_OP,
expression,
)
Loading
Loading