Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a column type for StringArray #58

Open
amane-toda opened this issue Apr 25, 2024 · 0 comments
Open

Create a column type for StringArray #58

amane-toda opened this issue Apr 25, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@amane-toda
Copy link

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

@Somtom Somtom added enhancement New feature or request good first issue Good for newcomers labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants