Error Code 204: Index error in small geo test program [SOLVED]

Hi,

I am trying a small query on geo data with my test installation (Ubuntu 3.7.3)

package de.schrell.aerospike.aerotest;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.Value.GeoJSONValue;
import com.aerospike.client.policy.Policy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.client.query.Filter;
import com.aerospike.client.query.IndexType;
import com.aerospike.client.query.RecordSet;
import com.aerospike.client.query.Statement;
import com.aerospike.client.task.IndexTask;

import java.util.UUID;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( final String[] args )
    {

        System.out.println( "Hello Aerospike!" );

        try (final AerospikeClient client = new AerospikeClient("localhost", 3000)) {

            final Key key = new Key("test", "myset", UUID.randomUUID().toString());
            final Bin bin = new Bin("mybin", new GeoJSONValue("{ \"type\": \"Point\", \"coordinates\": [50.0, 50.0] }"));

            client.put(new WritePolicy(), key, bin);

            System.out.println("creating index...");
            createIndex(client);
            System.out.println("created index.");

            final Statement stm = new Statement();
            stm.setNamespace("test");
            stm.setSetName("myset");
            stm.setFilters(Filter.geoWithinRadius("mybin", 50, 50, 100));
            stm.setIndexName("geo");

            System.out.println("XXXX");
            try (final RecordSet rs = client.query(null, stm)) {
                System.out.println("YYYYY");
                while (rs.next()) {
                    System.out.println("ZZZZ");
                    final Key k = rs.getKey();
                    System.out.println("KEY: " + k);
                    final Record record = rs.getRecord();
                    System.out.println("REC: " + record);
                    final String geo = record.getGeoJSON("mybin");
                    System.out.println("GEO in Region: " + geo);
                }

                final String geo = client.get(new Policy(), key).getGeoJSON("mybin");
                final GeoJSONValue g = new GeoJSONValue(geo);

                System.out.println("GEO: " + geo);
            }
        }
    }

    // Doesn't complain if index is already there.
    private static void createIndex(final AerospikeClient client) {
        final Policy policy = new Policy();
        policy.timeout = 0; // Do not timeout on index create.
        final String binName   = "mybin";
        final String indexName = "geo";
        try {
            final IndexTask task = client.createIndex(policy, "test", "myset", indexName, binName, IndexType.GEO2DSPHERE);
            task.waitTillComplete();
        } catch (final AerospikeException e) {
            e.printStackTrace();
        }
    }
}

at rs.next() I get an Error:

Hello Aerospike!
creating index...
created index.
XXXX
YYYYY
Exception in thread "main" com.aerospike.client.AerospikeException: Error Code 204: Index error
	at com.aerospike.client.command.MultiCommand.parseGroup(MultiCommand.java:96)
	at com.aerospike.client.command.MultiCommand.parseResult(MultiCommand.java:71)
	at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:56)
	at com.aerospike.client.query.QueryExecutor$QueryThread.run(QueryExecutor.java:137)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

I also created the index with aql, but that did not change anything. Also stm.setIndex(“geo”) did not matter.

Any hint, what I am doing wrong?

Andreas

Hi Andreas, I tried with your sample test, but didn’t see the issue you are seeing. Please let us know which version of server you are using. Also check in server logs what error is logging when you try to create index.

Hi,

sorry for the late answer. I will have access to my test system this evening again. I used Ubuntu 15.10 as OS and used aerospace in version 3.7.3. The DB ran on the same server as the test program. I did not see any problems in the log during index creation. And when I try to create the index again (aql) I get an error that it is already there.

I will try tonight again an check if I can get further information.

Thanks for your reply!

Andreas

Hi,

I did a new test and with DEBUG enabled and filtering the log with some greps I see

Feb 18 2016 20:18:13 GMT: WARNING (geo): (geospatial.cc::87) failed to parse point: failed to parse geojson: 1: invalid token near '0'
Feb 18 2016 20:18:13 GMT: WARNING (geo): (secondary_index.c::2884) failed to parse query GeoJSON
Feb 18 2016 20:18:13 GMT: DEBUG (sindex): (secondary_index.c:as_sindex_range_free:2628) as_sindex_range_free
Feb 18 2016 20:18:13 GMT: DEBUG (query): (thr_query.c:query_setup:2742) Could not instantiate index range metadata... Err, ERR GENERIC
Feb 18 2016 20:18:13 GMT: WARNING (sindex): (secondary_index.c::226) ERR GENERIC -1 Error at base/thr_query.c,2743

So it looks like my JSON point is somehow wrong:

new GeoJSONValue("{ \"type\": \"Point\", \"coordinates\": [50.0, 50] }"));

But I do not see the problem.

Andreas

Ha,

found the problem: Looks like the JAVA-Client is “language aware”. I am located in germany. If I set the environment variable LANG=C everything works fine.

So the real problem is, that the json parser scans [ 50, 50] (space is ignored) to [50,50] which is equivalent to [50.50] in other countries. And that would not be a valid point coordinate.

Bug: The pasring og JSON-Data should not obey any language specific number formats.

Andreas

Thanks for bringing this up. This does seem to be a short-coming of the jasson library which is used. Will look into improvement (AER-4807).

Greetings,

I’m currently unable to reproduce this bug.

I’m using the following code:

		String geopoint =
			"{ \"type\": \"Point\", \"coordinates\": [50,50] }";
		Bin bin3 = new Bin("bin3", Value.getAsGeoJSON(geopoint));

I’m using “export LANG=de_DE.UTF-8” on both the client and the server.

I’m not seeing the “failed to parse geojson: 1: invalid token near ‘0’”.

NOTE - when I send the value “50.50” on purpose the error message I see on the server is: Feb 25 2016 00:36:35 GMT: WARNING (geo): (geospatial.cc::87) failed to parse point: expected 2 coordinates, saw 1

This is different then the message you reported.

Could you provide more specific client-side code which sees this problem? I’d love to fix it!

Ken