Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Community is experiencing an influx of spam. As we work toward a solution, please use the 'Notify Moderator' option on the ellipsis menu to flag inappropriate posts.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Write to SNOWFLAKE VARIANT column

md000
5 - Atom

First of all - I am unsure how to turn this into a reproducible example as my issue is the connection to snowflake 

 

What I am attempting to do: Write a (JSON) string generated within python to a Snowflake VARIANT column (using the output tool).  Note: On my local machine, I use python to write the data to snowflake (using the snowflake.connector library) however this is not available to me on the server due to authentication requirements.

 

md000_0-1631582824816.png

 

 

 

Method:

(1) The python code contains the following: 

 

df_out = df_in[cols1]
df_out['FEATURES'] = df_in[cols2].apply(lambda x: x.to_json(), axis=1)

 

(2) Python Output #1: Pandas dataframe (df_out) with example value within the Features column as follows

{"X1":0.1304007565,"X2":0.0,"X3":0.0,"X5":0.233,"Z":0}

 

(3) Output Data tool:

The Snowflake table SANDPIT.CUST_BH_SEG.MODEL_TAGS_20210914 has a column FEATURES which is type VARIANT.

The following image shows how it is configured.

This is the error message I receive: Error: Output Data (73): Error SQLPrepare: SQL compilation error:
Expression type does not match column data type, expecting VARIANT but got VARCHAR(2) for column FEATURES

 

md000_0-1631583070777.png

 

Any advice on how to configure this Alteryx flow so that I can write the data to Snowflake would be much appreciated !

 

 

EDIT: Note as a work-around, I have done the following:

  • Created an intermediate/"staging" table MY_INT_TABLE with the same definition as the final table, "SANDPIT.CUST_BH_SEG.MODEL_TAGS_20210914" but replaced the datatype of FEATURES as varchar (instead of VARIANT)
  • Within the Output Data tool
    • Change the 3. Output Options to Delete Data and Append
    • In the 6. Post Create SQL Statement field I have the following 

 

INSERT INTO SANDPIT.CUST_BH_SEG.MODEL_TAGS_20210914 (..., FEATURES)
SELECT ...,TO_VARIANT(FEATURES)
FROM MY_INT_TABLE;

 

 

 

 

0 REPLIES 0
Labels
Top Solution Authors