Module ksqldb_confluent.row

Expand source code
# Copyright 2022 Confluent Inc.
#
# 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.
#
# Refer to LICENSE for more information.

from dataclasses import dataclass


@dataclass
class Row:
    values: list

    @property
    def is_tombstone(self) -> bool:
        """
        Returns if the given row represents a tombstone.

        Returns:
            bool: True if the row is a tombstone, false otherwise
        """
        return not self.values

    def is_none(self, column_index: int) -> bool:
        """
        Checks if the column_number element is None.

        Args:
            column_index: The column number

        Returns:
            bool: True, if the column_index element is None, False otherwise.
        """
        return self.values[column_index] is None

    def get_value(self, column_index: int) -> object:
        """
        Gets the column value in its native type, without any attempt at conversion.

        Args:
            column_index: The column number

        Returns:
            object: The value of the given column number
        """
        return self.values[column_index]

    def get_string(self, column_index: int) -> str:
        """
        Gets the column value as a string, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            str: The string value of the given column number
        """
        return str(self.values[column_index])

    def get_integer(self, column_index: int) -> int:
        """
        Gets the column value as an integer, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            int: The integer value of the given column number
        """
        return int(self.values[column_index])

    def get_float(self, column_index: int) -> float:
        """
        Gets the column value as a float, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            float: The float value of the given column number
        """
        return float(self.values[column_index])

    def get_bool(self,  column_index: int) -> bool:
        """
        Gets the column value as a boolean, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            bool: The boolean value of the given column number
        """
        return bool(self.values[column_index])

    def get_ksql_object(self, column_index: int) -> object:
        """
        Gets the column value as an object.
        This is appropriate for ksqlDB List, Map and Struct types.

        Args:
            column_index: The column number

        Returns:
            object: The value of the given column number
        """
        return self.values[column_index]

    def __repr__(self):
        return f'RowImpl{{values={self.values}, is_tombstone={self.is_tombstone}}}'

Classes

class Row (values: list)

Row(values: list)

Expand source code
@dataclass
class Row:
    values: list

    @property
    def is_tombstone(self) -> bool:
        """
        Returns if the given row represents a tombstone.

        Returns:
            bool: True if the row is a tombstone, false otherwise
        """
        return not self.values

    def is_none(self, column_index: int) -> bool:
        """
        Checks if the column_number element is None.

        Args:
            column_index: The column number

        Returns:
            bool: True, if the column_index element is None, False otherwise.
        """
        return self.values[column_index] is None

    def get_value(self, column_index: int) -> object:
        """
        Gets the column value in its native type, without any attempt at conversion.

        Args:
            column_index: The column number

        Returns:
            object: The value of the given column number
        """
        return self.values[column_index]

    def get_string(self, column_index: int) -> str:
        """
        Gets the column value as a string, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            str: The string value of the given column number
        """
        return str(self.values[column_index])

    def get_integer(self, column_index: int) -> int:
        """
        Gets the column value as an integer, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            int: The integer value of the given column number
        """
        return int(self.values[column_index])

    def get_float(self, column_index: int) -> float:
        """
        Gets the column value as a float, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            float: The float value of the given column number
        """
        return float(self.values[column_index])

    def get_bool(self,  column_index: int) -> bool:
        """
        Gets the column value as a boolean, possibly converting if necessary.

        Args:
            column_index: The column number

        Returns:
            bool: The boolean value of the given column number
        """
        return bool(self.values[column_index])

    def get_ksql_object(self, column_index: int) -> object:
        """
        Gets the column value as an object.
        This is appropriate for ksqlDB List, Map and Struct types.

        Args:
            column_index: The column number

        Returns:
            object: The value of the given column number
        """
        return self.values[column_index]

    def __repr__(self):
        return f'RowImpl{{values={self.values}, is_tombstone={self.is_tombstone}}}'

Class variables

var values : list

Instance variables

var is_tombstone : bool

Returns if the given row represents a tombstone.

Returns

bool
True if the row is a tombstone, false otherwise
Expand source code
@property
def is_tombstone(self) -> bool:
    """
    Returns if the given row represents a tombstone.

    Returns:
        bool: True if the row is a tombstone, false otherwise
    """
    return not self.values

Methods

def get_bool(self, column_index: int) ‑> bool

Gets the column value as a boolean, possibly converting if necessary.

Args

column_index
The column number

Returns

bool
The boolean value of the given column number
Expand source code
def get_bool(self,  column_index: int) -> bool:
    """
    Gets the column value as a boolean, possibly converting if necessary.

    Args:
        column_index: The column number

    Returns:
        bool: The boolean value of the given column number
    """
    return bool(self.values[column_index])
def get_float(self, column_index: int) ‑> float

Gets the column value as a float, possibly converting if necessary.

Args

column_index
The column number

Returns

float
The float value of the given column number
Expand source code
def get_float(self, column_index: int) -> float:
    """
    Gets the column value as a float, possibly converting if necessary.

    Args:
        column_index: The column number

    Returns:
        float: The float value of the given column number
    """
    return float(self.values[column_index])
def get_integer(self, column_index: int) ‑> int

Gets the column value as an integer, possibly converting if necessary.

Args

column_index
The column number

Returns

int
The integer value of the given column number
Expand source code
def get_integer(self, column_index: int) -> int:
    """
    Gets the column value as an integer, possibly converting if necessary.

    Args:
        column_index: The column number

    Returns:
        int: The integer value of the given column number
    """
    return int(self.values[column_index])
def get_ksql_object(self, column_index: int) ‑> object

Gets the column value as an object. This is appropriate for ksqlDB List, Map and Struct types.

Args

column_index
The column number

Returns

object
The value of the given column number
Expand source code
def get_ksql_object(self, column_index: int) -> object:
    """
    Gets the column value as an object.
    This is appropriate for ksqlDB List, Map and Struct types.

    Args:
        column_index: The column number

    Returns:
        object: The value of the given column number
    """
    return self.values[column_index]
def get_string(self, column_index: int) ‑> str

Gets the column value as a string, possibly converting if necessary.

Args

column_index
The column number

Returns

str
The string value of the given column number
Expand source code
def get_string(self, column_index: int) -> str:
    """
    Gets the column value as a string, possibly converting if necessary.

    Args:
        column_index: The column number

    Returns:
        str: The string value of the given column number
    """
    return str(self.values[column_index])
def get_value(self, column_index: int) ‑> object

Gets the column value in its native type, without any attempt at conversion.

Args

column_index
The column number

Returns

object
The value of the given column number
Expand source code
def get_value(self, column_index: int) -> object:
    """
    Gets the column value in its native type, without any attempt at conversion.

    Args:
        column_index: The column number

    Returns:
        object: The value of the given column number
    """
    return self.values[column_index]
def is_none(self, column_index: int) ‑> bool

Checks if the column_number element is None.

Args

column_index
The column number

Returns

bool
True, if the column_index element is None, False otherwise.
Expand source code
def is_none(self, column_index: int) -> bool:
    """
    Checks if the column_number element is None.

    Args:
        column_index: The column number

    Returns:
        bool: True, if the column_index element is None, False otherwise.
    """
    return self.values[column_index] is None