当前位置: 首页 > 知识库问答 >
问题:

在clientmode中运行Apache Ignite中的SQL扫描查询时出现的问题

邹山
2023-03-14
    public void testSQLDatabase(){
        CacheConfiguration<Long, Person> cacheCfg = new CacheConfiguration<>();
        cacheCfg.setName("mycache");
        cacheCfg.setCacheMode(CacheMode.PARTITIONED);
        cacheCfg.setIndexedTypes(Long.class, Person.class);

// Setting up query entity.
        QueryEntity queryEntity = new QueryEntity();

        queryEntity.setKeyType(Long.class.getName());
        queryEntity.setValueType(Person.class.getName());

// Listing query fields.
        LinkedHashMap<String, String> fields = new LinkedHashMap();

        fields.put("id", Long.class.getName());
        fields.put("orgId", Long.class.getName());
        fields.put("firstName", String.class.getName());
        fields.put("lastName", String.class.getName());
        fields.put("resume", String.class.getName());
        fields.put("salary", Double.class.getName());

        queryEntity.setFields(fields);

// Listing indexes.
        Collection<QueryIndex> indexes = new ArrayList<>(3);

        indexes.add(new QueryIndex("id"));
        indexes.add(new QueryIndex("orgId"));
        indexes.add(new QueryIndex("salary"));

        queryEntity.setIndexes(indexes);
        cacheCfg.setQueryEntities(Arrays.asList(queryEntity));

        IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheCfg);
        cache.clear();

        for(long iCount = 0; iCount < 10000; iCount++) {
            Person person = new Person();
            person.setValues(iCount, 0, "a", "a", "asdf", iCount*100);
            cache.put(iCount, person);
            System.out.println("Got back " + cache.get(iCount).toString());
        }

        IgniteBiPredicate<Long, Person> filter = new IgniteBiPredicate<Long, Person>() {
            @Override public boolean apply(Long key, Person p) {
                return p.getSalary() > 10000d;
            }
        };

        try (QueryCursor cursor = cache.query(new ScanQuery(filter))) {
            System.out.println(cursor.toString());
            for (Object p : cursor)
                System.out.println(p.toString());
        }
    }

   public class Person implements Serializable {
        /**
         * Person ID (indexed).
         */
        @QuerySqlField(index = true)
        private long id;

        /**
         * Organization ID (indexed).
         */
        @QuerySqlField(index = true)
        private long orgId;

        /**
         * First name (not-indexed).
         */
        @QuerySqlField
        private String firstName;

        /**
         * Last name (not indexed).
         */
        @QuerySqlField
        private String lastName;

        /**
         * Resume text (create LUCENE-based TEXT index for this field).
         */
        @QueryTextField
        private String resume;

        /**
         * Salary (indexed).
         */
        @QuerySqlField(index = true)
        private double salary;

        public void setValues(long id, long orgId, String firstName, String lastName, String resume, double salary){
            this.id = id;
            this.orgId = orgId;
            this.firstName = firstName;
            this.lastName = lastName;
            this.resume = resume;
            this.salary = salary;
        }

        public long getId() {
            return id;
        }

        public void setId(long id) {
            this.id = id;
        }

        public long getOrgId() {
            return orgId;
        }

        public void setOrgId(long orgId) {
            this.orgId = orgId;
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public String getResume() {
            return resume;
        }

        public void setResume(String resume) {
            this.resume = resume;
        }

        public double getSalary() {
            return salary;
        }

        public void setSalary(double salary) {
            this.salary = salary;
        }
    }
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=co.near.ignite.MainExperiment$1@4c1d79bc, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ca184604-5d57-4549-a2a2-b8601d9062ab, taskHash=0], rdc=null, trans=null]
        at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1618)
        ... 6 more
Caused by: class org.apache.ignite.IgniteCheckedException: Query execution failed: GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=co.near.ignite.MainExperiment$1@4c1d79bc, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ca184604-5d57-4549-a2a2-b8601d9062ab, taskHash=0], rdc=null, trans=null]
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.checkError(GridCacheQueryFutureAdapter.java:267)
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.internalIterator(GridCacheQueryFutureAdapter.java:325)
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.next(GridCacheQueryFutureAdapter.java:171)
        ... 11 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to execute query on node [query=GridCacheQueryBean [qry=GridCacheQueryAdapter [type=SCAN, clsName=null, clause=null, filter=co.near.ignite.MainExperiment$1@4c1d79bc, part=null, incMeta=false, metrics=GridCacheQueryMetricsAdapter [minTime=0, maxTime=0, sumTime=0, avgTime=0.0, execs=0, completed=0, fails=0], pageSize=1024, timeout=0, keepAll=true, incBackups=false, dedup=false, prj=null, keepBinary=false, subjId=ca184604-5d57-4549-a2a2-b8601d9062ab, taskHash=0], rdc=null, trans=null], nodeId=06118f33-33b0-4483-bab2-fcc2306a4053]
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryFutureAdapter.onPage(GridCacheQueryFutureAdapter.java:390)
        at org.apache.ignite.internal.managers.communication.GridIoManager.access$1800(GridIoManager.java:103)
        at org.apache.ignite.internal.managers.communication.GridIoManager$6.run(GridIoManager.java:972)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        ... 1 more
Caused by: class org.apache.ignite.IgniteCheckedException: co.near.ignite.MainExperiment$Person
        at org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7005)
        at org.apache.ignite.internal.util.future.GridFutureAdapter.get0(GridFutureAdapter.java:166)
        at org.apache.ignite.internal.util.future.GridFutureAdapter.get(GridFutureAdapter.java:115)
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager$CachedResult.iterator(GridCacheQueryManager.java:2825)
        at org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager.runQuery(GridCacheQueryManager.java:1390)
        ... 3 more
Caused by: java.lang.ClassNotFoundException: co.near.ignite.MainExperiment$Person
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        ... 14 more

由于我刚刚开始尝试Apache Ignite,我肯定做了一些明显错误的事情。如果你能让我知道怎么解决这个问题就太好了。

另外,我是在客户机模式下运行这段代码,而不是作为服务器。一个3节点群集单独运行。

共有1个答案

澹台宾白
2023-03-14

您正在运行一个基于谓词的扫描查询。该查询调用在服务器节点上提供的筛选器,以便只返回您感兴趣的数据。您的实现希望Person类在那里,所以您得到了这个错误。有两种方法可以修复它:

  • (推荐)使用WithKeepBinary()标志和BinaryObject而不是Person对象。有关示例,请参见[1]中的ScanQuery()方法。
  • Person类添加到所有服务器节点的类路径中。

[1]https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/cacheQueryExample.java

 类似资料:
  • DynamoDb文档中指定的查询操作: 查询操作仅搜索主键属性值,并支持对键属性值的比较运算符子集以优化搜索过程。 和扫描操作: 扫描操作扫描整个表。您可以指定要应用于结果的过滤器,以在完成扫描后优化返回给您的值。 这是基于性能和成本考虑的最佳选择。

  • 用户实体类: 感谢任何帮助。多谢了。

  • 问题内容: 说我长时间运行更新查询 some_table中的modification_time的值是什么?它们是相同还是不同(例如,执行查询花了2天的时间)。 如果它们不同,如​​何编写此查询以使它们都相同? 问题答案: 它们都是一样的,因为NOW()在查询开始时被锁定了。 答案太短了吗? 好的,更多信息有关NOW()的MySQL参考 NOW()返回一个 恒定时间 ,该时间指示该语句 开始执行的时

  • 声纳扫描仪在运行扫描仪时抛出空指针异常。错误指向一个枚举。它实现了一个典型的接口。 我记得几个月前运行扫描仪时没有出现任何问题,但这次不同了,感谢您的帮助。 添加了一些乱码,我可以保证没有编译问题。 包括声纳项目属性。#所需元数据sonar.project密钥=com.companysonar.project名称=项目sonar.project版本=1.0

  • 问题内容: 在整个类路径中搜索带注释的类的最佳方法是什么? 我正在做一个库,我想允许用户注释他们的类,所以当Web应用程序启动时,我需要扫描整个类路径以查找某些注释。 你知道执行此操作的库或Java工具吗? 编辑:我正在考虑类似Java EE 5 Web服务或EJB的新功能。你使用或注释类,系统在加载时会找到这些类,因此可以远程访问它们。 问题答案: 使用 API 组件提供程序,它从基本程序包扫描

  • 当我尝试在查询中引用plsql表记录时,我收到pls-201错误。 下面是一个问题示例: 错误报告-ORA-06550:第15行,第23列:PLS-00201:标识符“QRY”。ID“必须声明为ORA-06550:第15行,第23列:PLS-00201:标识符”QRY。ID’必须声明为ORA-06550:第15行,第12列:PL/SQL:ORA-00904::无效标识符ORA-06550:第15行