本文介绍了如何使用DAO插入雪花变体字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

@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 );
}

如您所见,我正在使用此DAO将实体列表批量插入到Snowflake表中.

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

问题是我无法插入标志列,这是一个变体.我已经尝试过to_variant(:flags)和当前的parse_json(:flags),但是JDBI不断抛出以下错误:

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:[]}]

我应该如何在flags列中传递值?有人尝试过吗? MyEntity中的flags字段处于我的控制范围内,我可以将其保留为POJO或字符串,以帮助解决此问题的方式为准.

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.

推荐答案

请参见,用于回答:

INSERT INTO T SELECT parse_json(:flag);

这篇关于如何使用DAO插入雪花变体字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 09:07