|
| 1 | +# Copyright 2025 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 | +from __future__ import annotations |
| 16 | + |
| 17 | +import dataclasses |
| 18 | +from typing import ClassVar |
| 19 | + |
| 20 | +# Imports for Ibis compilation |
| 21 | +from bigframes_vendored.ibis.expr import types as ibis_types |
| 22 | + |
| 23 | +# Direct imports from bigframes |
| 24 | +from bigframes import dtypes |
| 25 | +from bigframes.core.compile.ibis_compiler import scalar_op_compiler |
| 26 | +from bigframes.operations import base_ops |
| 27 | + |
| 28 | + |
| 29 | +@dataclasses.dataclass(frozen=True) |
| 30 | +class NotNullOp(base_ops.UnaryOp): |
| 31 | + name: ClassVar[str] = "notnull" |
| 32 | + |
| 33 | + def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionType: |
| 34 | + return dtypes.BOOL_DTYPE |
| 35 | + |
| 36 | + |
| 37 | +notnull_op = NotNullOp() |
| 38 | + |
| 39 | + |
| 40 | +def _ibis_notnull_op_impl(x: ibis_types.Value): |
| 41 | + return x.notnull() |
| 42 | + |
| 43 | + |
| 44 | +scalar_op_compiler.scalar_op_compiler.register_unary_op(notnull_op)( |
| 45 | + _ibis_notnull_op_impl |
| 46 | +) |
| 47 | + |
| 48 | + |
| 49 | +__all__ = [ |
| 50 | + "NotNullOp", |
| 51 | + "notnull_op", |
| 52 | +] |
0 commit comments