1

I am trying to do a like query on a socrata dataset using the soda-java api with this code

Soda2Consumer consumer = Soda2Consumer.newConsumer("https://data.cityofboston.gov");
SoqlQuery   departmentOfStateQuery = new SoqlQueryBuilder()
                .addSelectPhrase("entered")
                .addSelectPhrase("vendor_name")
                .addSelectPhrase("account_descr")
                .addSelectPhrase("dept_name")
                .setWhereClause("vendor_name like'IBM%'")
                .build();
consumer.query("gqai-h7bg",departmentOfStateQuery,Nomination.LIST_TYPE);

But i am getting an error Exception in thread "main" com.socrata.exceptions.MalformedQueryError: Error: function #LIKE is not defined in SoQL.: Error: function #LIKE is not defined in SoQL. Using a browser is working fine with this

https://data.cityofboston.gov/resource/gd7m-xsim.json?$where=vendor_name like 'IBM%' even though FF is translating it to https://data.cityofboston.gov/resource/gd7m-xsim.json?$where=vendor_name%20like%20%27IBM%%27 which encoding I did use with the same result.

Skaros Ilias
  • 1,008
  • 12
  • 40

1 Answers1

0

LIKE is only supported on Version 2.1 API endpoints: https://dev.socrata.com/docs/functions/like.html

Fortunately, a 2.1 endpoint exists for that dataset: https://dev.socrata.com/foundry/data.cityofboston.gov/gd7m-xsim

I was able to get your LIKE query working with the following code:

    Soda2Consumer consumer = Soda2Consumer.newConsumer("https://data.cityofboston.gov");
    SoqlQuery query = new SoqlQueryBuilder()
            .addSelectPhrase("entered")
            .addSelectPhrase("vendor_name")
            .addSelectPhrase("account_descr")
            .addSelectPhrase("dept_name")
            .setWhereClause("vendor_name LIKE 'IBM%'")
            .build();

    System.out.println(query.toString());
    ClientResponse response = consumer.query("gd7m-xsim", HttpLowLevel.JSON_TYPE, query);
    String payload = response.getEntity(String.class);
    System.out.println(payload);
chrismetcalf
  • 1,556
  • 1
  • 8
  • 7
  • thanks for that. I saw that like is available for 2.1 and above, but didnt know the dataset wasnt a 2.1. how can i tell if a dataset is v2.1 or not? I am specially intrested for datasets that got from the dataset catalog – Skaros Ilias Aug 10 '16 at 20:03
  • The best way to tell is by clicking the "API Docs" link from either the data catalog or from the "Export" -> "SODA API" sidebar in the dataset itself. It'll automatically make sure you're looking at the docs for the latest version. – chrismetcalf Aug 12 '16 at 21:03