Home > Net >  Azure blob storage - findBlobsByTags always fails with error Error parsing query at or near characte
Azure blob storage - findBlobsByTags always fails with error Error parsing query at or near characte

Time:04-19

I am using Azure Blob storage. While persisting blobs, I have persisted index tags. I am able to see index tags when I download the blobs through Microsoft Azure storage explorer. Programatically, I am trying to filter the tags(using azure-storage-blob version 12.15.0)

I am using this api to get details from DB - findBlobsByTags

This is the code I am trying

    FindBlobsOptions findByTags = new FindBlobsOptions(searchExpression));
    findByTags.setMaxResultsPerPage(100);
    PagedIterable<TaggedBlobItem> blobsByTags = blobContainerClient.findBlobsByTags(findByTags, Duration.ofSeconds(30), Context.NONE);

I have tried following queries

 1.   String searchExpression = "where=@container = 'container-name' AND \"field\" = \'value\'";
 2. String searchExpression = "where=field=value";
 3. String searchExpression = "where=\"field\" =\'value\'";
     String escapeJava = StringEscapeUtils.escapeJava(searchExpression);
 4. String searchExpression = "&where=\"trackingId\"=\'TA00965650\'";

and I am getting this exception.

[Request processing failed; nested exception is com.azure.storage.blob.models.BlobStorageException: Status code 400, "

InvalidQueryParameterValueError parsing query at or near character position 1: unexpected '1' RequestId:78043a6d-901e-00de-0797-510acf000000 Time:2022-04-16T13:42:00.7475672Zwherewhere="field"='value'This query parameter value is invalid."] with root cause com.azure.storage.blob.models.BlobStorageException: Status code 400, "

InvalidQueryParameterValueError parsing query at or near character position 1: unexpected '1' RequestId:78043a6d-901e-00de-0797-510acf000000 Time:2022-04-16T13:42:00.7475672Zwherewhere="trackingId"='TA00965650'This query parameter value is invalid." at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.azure.core.http.rest.RestProxy.instantiateUnexpectedException(RestProxy.java:390) at

From the exception log it looks like the query I am passing to the findBlobsByTags method has issues in parsing. Please let me know what I am doing wrong. If some escaping/encoding needs to be done

CodePudding user response:

As mentioned in comments, please remove where= from your search expression. Documentation seems to be incorrect. You may want to create an issue here: https://github.com/Azure/azure-sdk-for-java/issues so that the documentation can be corrected.

You can see working code here: https://github.com/Azure/azure-sdk-for-java/blob/azure-storage-blob_12.16.0/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAPITest.groovy.

  • Related