sql-mock icon indicating copy to clipboard operation
sql-mock copied to clipboard

Create a column type for StringArray

Open amane-toda opened this issue 1 year ago • 0 comments

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

amane-toda avatar Apr 25 '24 09:04 amane-toda