在BinaryObjects的Ignite缓存上执行SQL [英] Execute SQL on Ignite cache of BinaryObjects

查看:45
本文介绍了在BinaryObjects的Ignite缓存上执行SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Spark数据帧创建BinaryObject的缓存,然后我想在该点火缓存上执行SQL.

I am creating a cache of BinaryObject from spark a dataframe and then I want to perform SQL on that ignite cache.

这是我的代码,其中 bank 是包含三个字段(id,name和age)的数据框:

Here is my code where bank is the dataframe which contains three fields (id,name and age):

    val ic = new IgniteContext(sc, () => new IgniteConfiguration()) 
    val cacheConfig = new CacheConfiguration[BinaryObject, BinaryObject]()
    cacheConfig.setName("test123")
    cacheConfig.setStoreKeepBinary(true)
    cacheConfig.setIndexedTypes(classOf[BinaryObject], classOf[BinaryObject])

    val qe = new QueryEntity()
    qe.setKeyType(TestKey)
    qe.setValueType(TestValue)
    val fields = new java.util.LinkedHashMap[String, String]()
    fields.put("id", "java.lang.Long")
    fields.put("name", "java.lang.String")
    fields.put("age", "java.lang.Int")
    qe.setFields(fields)
    val qes = new java.util.ArrayList[QueryEntity]()
    qes.add(qe)

    cacheConfig.setQueryEntities(qes)

    val cache = ic.fromCache[BinaryObject, BinaryObject](cacheConfig)

    cache.savePairs(bank.rdd, (row: Bank, iContext: IgniteContext) => {
        val keyBuilder = iContext.ignite().binary().builder("TestKey");
        keyBuilder.setField("id", row.id);
        val key = keyBuilder.build();

        val valueBuilder = iContext.ignite().binary().builder("TestValue");
        valueBuilder.setField("name", row.name);
        valueBuilder.setField("age", row.age);
        val value = valueBuilder.build();
        (key, value);        
    }, true)

现在,我正在尝试执行这样的SQL查询:

Now I am trying to execute an SQL query like this:

cache.sql("select age from TestValue")

失败的原因如下:

Caused by: org.h2.jdbc.JdbcSQLException: Column "AGE" not found; SQL statement:
select age from TestValue [42122-191]
  at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
  at org.h2.message.DbException.get(DbException.java:179)
  at org.h2.message.DbException.get(DbException.java:155)
  at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:147)
  at org.h2.command.dml.Select.prepare(Select.java:852) 

我在做什么错了?

推荐答案

age 字段的类型不正确,应为以下内容:

The type of field age is incorrect, it should be the following:

fields.put("age", "java.lang.Integer")

这篇关于在BinaryObjects的Ignite缓存上执行SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆