页面大小在Ignite SQL查询中

huangapple go评论60阅读模式
英文:

page size in Ignite Sql query

问题

I am trying create a sql query on ignite to fetch records in batches. I found in ignite docs that there is a way to set page size. I would like to know if this parameter is query result payload size or number of records returned at a time.

我试图创建一个在Ignite上获取记录批量的SQL查询。我在Ignite文档中发现有一种设置页面大小的方法。我想知道这个参数是查询结果的负载大小还是一次返回的记录数量。

https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/cache/query/SqlFieldsQuery.html#setPageSize-int-

Also, is page size applicable only when we obtain query cursor? Is it used when we do query.getAll() ?

此外,页面大小仅在我们获取查询游标时适用吗?在执行query.getAll()时是否也会使用页面大小?

private static final String EMP_CACHE = "emp_cache";

public static void main(String[] args) {

try (Ignite ignite = Ignition.start(new IgniteConfiguration())) {
IgniteCache<Long, Employee> empCache = ignite.getOrCreateCache(empCacheConfig());
String[] dept = {"Math", "Science", "CS", "ECE", "Physics", "Chemistry", "English", "Hindi"};
long count = 10;
while (count-- > 0) {
String name = RandomStringUtils.randomAlphanumeric(20);
int deptNo = (int) (Math.random() * 7);
empCache.put(count, new Employee(count, name, dept[deptNo]));
}
FieldsQueryCursor<List> cursor =
empCache.query(new SqlFieldsQuery("select * from empCache.EMPLOYEE").setPageSize(2));
for (List objects : cursor) {
System.out.println("Record =" + objects);
// would this mean cursor will fetch two records and go back to ignite to fetch next batch
// OR cursor will fetch records 2KB at a time
}
}
}

public static CacheConfiguration<Long, Employee> empCacheConfig() {
CacheConfiguration<Long, Employee> empCacheConfig = new CacheConfiguration<>(EMP_CACHE);
empCacheConfig.setCacheMode(CacheMode.PARTITIONED);
empCacheConfig.setBackups(1);
empCacheConfig.setIndexedTypes(Long.class, Employee.class);
return empCacheConfig;
}

Thanks.

英文:

I am trying create a sql query on ignite to fetch records in batches. I found in ignite docs that there is a way to set page size. I would like to know if this parameter is query result payload size or number of records returned at a time.

https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/cache/query/SqlFieldsQuery.html#setPageSize-int-

Also, is page size applicable only when we obtain query cursor? Is it used when we do query.getAll() ?

private static final String EMP_CACHE = &quot;emp_cache&quot;;

  public static void main(String[] args) {

    try (Ignite ignite = Ignition.start(new IgniteConfiguration())) {
      IgniteCache&lt;Long, Employee&gt; empCache = ignite.getOrCreateCache(empCacheConfig());
      String[] dept = {&quot;Math&quot;, &quot;Science&quot;, &quot;CS&quot;, &quot;ECE&quot;, &quot;Physics&quot;, &quot;Chemistry&quot;, &quot;English&quot;, &quot;Hindi&quot;};
      long count = 10;
      while (count-- &gt; 0) {
        String name = RandomStringUtils.randomAlphanumeric(20);
        int deptNo = (int) (Math.random() * 7);
        empCache.put(count, new Employee(count, name, dept[deptNo]));
      }
      FieldsQueryCursor&lt;List&lt;?&gt;&gt; cursor =
          empCache.query(new SqlFieldsQuery(&quot;select * from empCache.EMPLOYEE&quot;).setPageSize(2));
      for (List&lt;?&gt; objects : cursor) {
        System.out.println(&quot;Record =&quot; + objects);
        // would this mean cursor will fetch two records and go back to ignite to fetch next batch
        // OR cursor will fetch records 2KB at a time
      }
    }
  }

  public static CacheConfiguration&lt;Long, Employee&gt; empCacheConfig() {
    CacheConfiguration&lt;Long, Employee&gt; empCacheConfig = new CacheConfiguration&lt;&gt;(EMP_CACHE);
    empCacheConfig.setCacheMode(CacheMode.PARTITIONED);
    empCacheConfig.setBackups(1);
    empCacheConfig.setIndexedTypes(Long.class, Employee.class);
    return empCacheConfig;
  }

Thanks.

答案1

得分: 1

  1. pageSize设置每个批次的行数(而非字节数)。行以批次方式从远程节点传输。

  2. getAll不受此属性影响。

英文:
  1. pageSize sets the number of rows per batch (not bytes). Rows are transferred in batches from remote nodes.

  2. getAll is not affected by this property

huangapple
  • 本文由 发表于 2023年3月10日 00:03:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定