Skip to content

Commit

Permalink
[#5200]Update the Column data type for python client (#5354)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
1. Implement type.java as type.py in Python client
2.  Implement types.java as types.py in Python client
3.  Create a test_types.py in unit tests.

### Why are the changes needed?
We need to support the column data type in python client

Fix: #5200

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Need to add the unit tests

---------

Co-authored-by: Xun <[email protected]>
  • Loading branch information
SophieTech88 and xunliu authored Nov 6, 2024
1 parent 919dcac commit fabdbc9
Show file tree
Hide file tree
Showing 5 changed files with 1,483 additions and 1 deletion.
180 changes: 180 additions & 0 deletions clients/client-python/gravitino/api/type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 abc import ABC, abstractmethod
from enum import Enum


class Name(Enum):
"""
The root type name of this type, representing all data types supported.
"""

BOOLEAN = "BOOLEAN"
""" The boolean type. """

BYTE = "BYTE"
""" The byte type. """

SHORT = "SHORT"
""" The short type. """

INTEGER = "INTEGER"
""" The integer type. """

LONG = "LONG"
""" The long type. """

FLOAT = "FLOAT"
""" The float type. """

DOUBLE = "DOUBLE"
""" The double type. """

DECIMAL = "DECIMAL"
""" The decimal type. """

DATE = "DATE"
""" The date type. """

TIME = "TIME"
""" The time type. """

TIMESTAMP = "TIMESTAMP"
""" The timestamp type. """

INTERVAL_YEAR = "INTERVAL_YEAR"
""" The interval year type. """

INTERVAL_DAY = "INTERVAL_DAY"
""" The interval day type. """

STRING = "STRING"
""" The string type. """

VARCHAR = "VARCHAR"
""" The varchar type. """

FIXEDCHAR = "FIXEDCHAR"
""" The char type with fixed length. """

UUID = "UUID"
""" The UUID type. """

FIXED = "FIXED"
""" The binary type with fixed length. """

BINARY = "BINARY"
""" The binary type with variable length. The length is specified in the type itself. """

STRUCT = "STRUCT"
"""
The struct type.
A struct type is a complex type that contains a set of named fields, each with a type,
and optionally a comment.
"""

LIST = "LIST"
"""
The list type.
A list type is a complex type that contains a set of elements, each with the same type.
"""

MAP = "MAP"
"""
The map type.
A map type is a complex type that contains a set of key-value pairs, each with a key type
and a value type.
"""

UNION = "UNION"
"""
The union type.
A union type is a complex type that contains a set of types.
"""

NULL = "NULL"
""" The null type. A null type represents a value that is null. """

UNPARSED = "UNPARSED"
""" The unparsed type. An unparsed type represents an unresolvable type. """

EXTERNAL = "EXTERNAL"
""" The external type. An external type represents a type that is not supported. """


# Define the Type interface (abstract base class)
class Type(ABC):
@abstractmethod
def name(self) -> Name:
"""Returns the generic name of the type."""
pass

@abstractmethod
def simple_string(self) -> str:
"""Returns a readable string representation of the type."""
pass


# Define base classes
class PrimitiveType(Type, ABC):
"""Base class for all primitive types."""

pass


class NumericType(PrimitiveType, ABC):
"""Base class for all numeric types."""

pass


class DateTimeType(PrimitiveType, ABC):
"""Base class for all date/time types."""

pass


class IntervalType(PrimitiveType, ABC):
"""Base class for all interval types."""

pass


class ComplexType(Type, ABC):
"""Base class for all complex types, including struct, list, map, and union."""

pass


class IntegralType(NumericType, ABC):
"""Base class for all integral types."""

_signed: bool

def __init__(self, signed: bool):
self._signed = signed

def signed(self) -> bool:
"""Returns True if the integer type is signed, False otherwise."""
return self._signed


class FractionType(NumericType, ABC):
"""Base class for all fractional types."""

pass
Loading

0 comments on commit fabdbc9

Please sign in to comment.