Aerospike: how to bulk load a list of integers into a basket?

I am trying to use the Aerospike bulk loader to plant a cluster with data from a tab-delimited file.

The source data is as follows:

set key segments
segment 123 10,20,30,40,50
segment 234 40,50,60,70

The third column "segments" contains a list of integers, separated by commas.

I created a JSON template:

{
  "version" : "1.0",
  "input_type" : "csv",
  "csv_style": { "delimiter": " " , "n_columns_datafile": 3, "ignore_first_line": true}

  "key": {"column_name":"key", "type": "integer"},

  "set": { "column_name":"set" , "type": "string"},

  "binlist": [
    {"name": "segments",
      "value": {"column_name": "segments", "type": "list"}
    }
  ]
}

... and launched the bootloader:

java -cp aerospike-load-1.1-jar-with-dependencies.jar com.aerospike.load.AerospikeLoad -c template.json data.tsv

When I request entries in aql, they seem to be a list of strings:

aql> select * from test
+--------------------------------+
| segments                       |
+--------------------------------+
| ["10", "20", "30", "40", "50"] |
| ["40", "50", "60", "70"]       |
+--------------------------------+

The data I'm trying to save is a list of integers. Is there an easy way to convert the objects stored in this box into a list of integers (possibly Lua UDF) or, possibly, where you can configure the bulk loader template?

Update:

I tried to solve this problem by creating Lua UDF to convert a list from strings to integers:

function convert_segment_list_to_integers(rec)
    for i=1, table.maxn(rec['segments']) do
        rec['segments'][i] = math.floor(tonumber(rec['segments'][i]))
    end
    aerospike:update(rec)
end

... :

aql> register module 'convert_segment_list_to_integers.lua'

... :

aql> execute convert_segment_list_to_integers.convert_segment_list_to_integers() on test.segment

, UDF . -, a table, userdata:

Dec 04 2015 23:23:34 GMT: DEBUG (udf): (udf_rw.c:send_result:527) FAILURE when calling convert_segment_list_to_integers convert_segment_list_to_integers ...rospike/usr/udf/lua/convert_segment_list_to_integers.lua:2: bad argument #1 to 'maxn' (table expected, got userdata)
Dec 04 2015 23:23:34 GMT: DEBUG (udf): (udf_rw.c:send_udf_failure:407) Non-special LDT or General UDF Error(...rospike/usr/udf/lua/convert_segment_list_to_integers.lua:2: bad argument #1 to 'maxn' (table expected, got userdata))

, maxn userdata.

, , ?

+4
1

, udf:

function convert_segment_list_to_integers(rec)
        local list_with_ints = list()
        for value in list.iterator(rec['segments']) do
                local int_value = math.floor(tonumber(value))
                list.append(list_with_ints, int_value)
        end
        rec['segments'] = list_with_ints
        aerospike:update(rec)
end

lua, register module 'convert_segment_list_to_integers.lua'.

: / , java-:

case LIST:
    /*
     * Assumptions
     * 1. Items are separated by a colon ','
     * 2. Item value will be a string
     * 3. List will be in double quotes
     * 
     * No support for nested maps or nested lists
     * 
     */
    List<String> list = new ArrayList<String>();
    String[] listValues = binRawText.split(Constants.LIST_DELEMITER, -1);
    if (listValues.length > 0) {
        for (String value : listValues) {
            list.add(value.trim());
        }
        bin = Bin.asList(binColumn.getBinNameHeader(), list);
    } else {
        bin = null;
        log.error("Error: Cannot parse to a list: " + binRawText);
    }
    break;

Github: http://git.io/vRAQW

, , . 266 270 - (untested):

List<Integer> list = new ArrayList<Integer>(); 
list.add(Integer.parseInt(value.trim());
+2

Source: https://habr.com/ru/post/1618623/


All Articles