cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

List parameter in Python SQL connector 3.0.1

PetitLepton
New Contributor II

Hi,

up to recently in version of the Python SQL connector 2.9.3, I was using a list as a parameter in the cursor.execute(operation, parameters) method without any trouble. It seems that it is not possible anymore in version 3.0.1 as the parsing of parameters does not accept lists but only scalar types

    def dbsql_parameter_from_primitive(
        value: TAllowedParameterValue, name: Optional[str] = None
    ) -> "TDbsqlParameter":
        """Returns a DbsqlParameter subclass given an inferrable value
    
        This is a convenience function that can be used to create a DbsqlParameter subclass
        without having to explicitly import a subclass of DbsqlParameter.
        """
    
        # This series of type checks are required for mypy not to raise
        # havoc. We can't use TYPE_INFERRENCE_MAP because mypy doesn't trust
        # its logic
    
        if type(value) is int:
            return dbsql_parameter_from_int(value, name=name)
        elif type(value) is str:
            return StringParameter(value=value, name=name)
        elif type(value) is float:
            return FloatParameter(value=value, name=name)
        elif type(value) is datetime.datetime:
            return TimestampParameter(value=value, name=name)
        elif type(value) is datetime.date:
            return DateParameter(value=value, name=name)
        elif type(value) is bool:
            return BooleanParameter(value=value, name=name)
        elif type(value) is decimal.Decimal:
            return DecimalParameter(value=value, name=name)
        elif value is None:
            return VoidParameter(value=value, name=name)
    
        else:
>           raise NotSupportedError(
                f"Could not infer parameter type from value: {value} - {type(value)} \n"
                "Please specify the type explicitly."
            )
E           databricks.sql.exc.NotSupportedError: Could not infer parameter type from value: ['TEMPERATURE'] - <class 'list'> 
E           Please specify the type explicitly.

Did I miss something? How can I perform a request with a clause such as `WHERE metrics IN :metrics`?

Thanks in advance!

1 REPLY 1

PetitLepton
New Contributor II

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group