Skip to content

Create a column type for StringArray #58

@amane-toda

Description

@amane-toda

Context:
My team are using Clickhouse, and integrate sql-mock into it.

Problem:
While we are able to support most column types, I am currently writing a custom object to handle StringArrays.

class StringArray(col.ClickhouseColumnMock):
    dtype = "Array(String)"

    def to_sql(self, column_name: str, value=NO_INPUT) -> str:
        # Note: Compare against NO_INPUT instead of checking for None since None could be a valid input for nullable columns
        val = value if not isinstance(value, NoInput) else self.default
        # In case the val is None, we convert it to NULL
        if val is None:
            return f"cast(NULL AS {self.dtype}) AS {column_name}"
        return f"cast({val} AS {self.dtype}) AS {column_name}" 

Proposal:
Would it be possible to write this directly into the sql-mock object, similar to how I can call col.String or col.Decimal. Would be great if I could call col.StringArray

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions