Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

Java, Azure Cosmos Query on 'null' value is not supported

I am querying on NULL value in java (on cosmos document db) but its throwing error, below is the Syntax:

import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.spring.data.cosmos.core.generator.FindQuerySpecGenerator;
import com.azure.cosmos.models.SqlQuerySpec;
import com.azure.spring.data.cosmos.core.query.CosmosQuery;
import com.azure.spring.data.cosmos.core.query.Criteria;
import com.azure.spring.data.cosmos.core.query.CriteriaType;
import org.springframework.data.repository.query.parser.Part;
import java.util.Arrays;

Criteria criteria = Criteria.getInstance(CriteriaType.IS_EQUAL,
                "tripId",
                new ArrayList(Arrays.asList(null)),
                Part.IgnoreCaseType.NEVER);

CosmosQuery documentQuery = new CosmosQuery(criteria);
SqlQuerySpec sqlQuerySpec = new FindQuerySpecGenerator().generateCosmos(documentQuery);
    

Here is the Exception: Exception in thread "main" java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Arrays$ArrayList.(Arrays.java:3813) at java.util.Arrays.asList(Arrays.java:3800)

question from:https://stackoverflow.com/questions/65843885/java-azure-cosmos-query-on-null-value-is-not-supported

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the Solution:

ArrayList<Object> emptyList= new ArrayList<Object>();
Criteria criteria = Criteria.getInstance(CriteriaType.IS_NULL,
                        "tripId",
                        emptyList,
                        Part.IgnoreCaseType.NEVER);
    
CosmosQuery documentQuery = new CosmosQuery(criteria);
SqlQuerySpec sqlQuerySpec = new FindQuerySpecGenerator().generateCosmos(documentQuery);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...