从Oracle NOSQL检索批量数据时,获取类型无法创建Double:类oracle.kv.impl.api.table.IntegerDefImpl

时间:2019-05-12 04:08:07

标签: java nosql oracle-nosql

我正在尝试使用Java类从Oracle NoSQL表检索批量数据。

//Connection part omitted
public static void main(String args[]) {
            try {
                LoadBulkData runLoader = new LoadBulkData();
                runLoader.run();
            } catch (Exception e) {
                System.err.print("Error: " + e.getMessage());
            }
        }



        void run() {
            Integer[] myId = {100,101};
            List keys =
                    new ArrayList(myId.length);

            TableAPI tableAPI = store.getTableAPI();
            Table myTable = tableAPI.getTable(tableName);
            if (myTable == null) {
                throw new IllegalArgumentException("Table not found: " + tableName);
            }

            for (Integer id : myId) {
                PrimaryKey pk = myTable.createPrimaryKey();
                pk.put("UID", id);
                keys.add(pk);
            }   
            FieldRange range = myTable.createFieldRange("myId");
            range.setStart(100d, true).setEnd(500d, true);
            MultiRowOptions mro = new MultiRowOptions(range, null, null);

            int batchResultsSize = 200;
            int parallalism = 9;
            TableIteratorOptions tio =
                    new TableIteratorOptions(Direction.UNORDERED ,
                            null ,
                            0 ,
                            null,
                            parallalism,
                            batchResultsSize);

            TableIterator itr = null;
            int count = 0;
            try {
                itr = tableAPI.tableIterator(keys.iterator(), mro, tio);
                while (itr.hasNext()) {
                    Row myRow = (Row) itr.next();
                    System.out.println(myRow.toJsonString(false));
                    count++;
                    /* ... */
                }
                System.out.println(count + " rows to print.");
            } catch (StoreIteratorException sie) {

            } finally {
                if (itr != null) {
                    itr.close();
                }
            }
        }
    }

下面是表格结构

->show table -name SampleTable
  {
      "json_version" : 1,
      "type" : "table",
      "name" : "SampleTable",
      "owner" : "root(id:u1)",
      "shardKey" : [ "myId" ],
      "primaryKey" : [ "myId" ],
      "fields" : [ {
        "name" : "myId",
        "type" : "INTEGER",
        "nullable" : false,
        "default" : null
      }, {
        "name" : "myString",
        "type" : "STRING",
        "nullable" : true,
        "default" : null
      } ]
    }

在运行此代码时,出现以下错误:-

Type无法创建Double:类oracle.kv.impl.api.table.IntegerDefImpl

有人可以帮忙吗?我是NoSQL的新手,非常感谢。

1 个答案:

答案 0 :(得分:0)

这是由于投放错误。您正在尝试将双精度值插入需要整数的字段中。

您需要使用:

public FieldRange setStart(int value,boolean isInclusive)