How to insert into a snowflake variant field using

2019-08-22 01:53发布

问题:

I have the following code:

@RegisterMapper(MyEntity.ResultMapper.class)
@UseStringTemplate3StatementLocator
public interface MyDao {

    @Transaction(TransactionIsolationLevel.SERIALIZABLE)
    @SqlBatch("INSERT INTO mySchema.myTable (" +
        " id, entity_type, entity_id, flags " +
        " ) VALUES " +
        "(" +
        " :stepId , :entityType , :entityId,parse_json(:flags) " +
        ")")
    @BatchChunkSize(500)
    Object create( @BindBean List<MyEntity> entities );
}

As you can see, I am bulk inserting a list of entities into my Snowflake table using this DAO.

The issue is that I am unable to insert into the flags columns, which is a variant. I have tried to_variant(:flags) and currently parse_json(:flags), but the JDBI keeps throwing the following error:

net.snowflake.client.jdbc.SnowflakeSQLException: SQL 
compilation error:
Invalid expression [PARSE_JSON(?)] in VALUES clause 
[statement:"INSERT INTO mySchema.myTable ( id, entity_type, 
entity_id, flags  ) VALUES ( :stepId , :entityType , :entityId,
parse_json(:flags) )", located:"null", rewritten:"null",
arguments:{ positional:{}, named:{timeStamp:'null', 
entityType:MYENTITY,
flags:'{"client":"myClient","flow":"myFlow"}',stepId:null, 
entityId:'189643357241513', class:class myOrg.MyEntity}, finder:[]}]

How should I pass the value in the flags column ? Has anyone attempted this before? The flags field in MyEntity is in my control, I can keep it as a POJO or a String, whichever helps me resolve this issue.