com.baidu.hugegraph.backend.query.Query.limit()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中com.baidu.hugegraph.backend.query.Query.limit方法的一些代码示例,展示了Query.limit的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.limit方法的具体详情如下:
包路径:com.baidu.hugegraph.backend.query.Query
类名称:Query
方法名:limit

Query.limit介绍

暂无

代码示例

代码示例来源:origin: hugegraph/hugegraph

protected void wrapOffset(StringBuilder select, Query query) {
  assert query.limit() >= 0;
  assert query.offset() >= 0;
  // Set limit and offset
  select.append(" limit ");
  select.append(query.limit());
  select.append(" offset ");
  select.append(query.offset());
  select.append(";");
}

代码示例来源:origin: hugegraph/hugegraph

/**
 * Set or update the offset and limit by a range [start, end)
 * NOTE: it will use the min range one: max start and min end
 * @param start the range start, include it
 * @param end   the range end, exclude it
 */
public void range(long start, long end) {
  // Update offset
  long offset = this.offset();
  start = Math.max(start, offset);
  this.offset(start);
  // Update limit
  if (end != -1L) {
    if (this.limit() != Query.NO_LIMIT) {
      end = Math.min(end, offset + this.limit());
    } else {
      assert end < Query.NO_LIMIT;
    }
    E.checkArgument(end >= start,
            "Invalid range: [%s, %s)", start, end);
    this.limit(end - start);
  } else {
    // Keep the origin limit
    assert this.limit() <= Query.NO_LIMIT;
  }
}

代码示例来源:origin: hugegraph/hugegraph

private Iterator<Edge> edgesOfVertex(Id source, Directions dir,
                   Id label, long limit) {
  Id[] labels = {};
  if (label != null) {
    labels = new Id[]{label};
  }
  Query query = GraphTransaction.constructEdgesQuery(source, dir, labels);
  if (limit != NO_LIMIT) {
    query.limit(limit);
  }
  return this.graph.edges(query);
}

代码示例来源:origin: hugegraph/hugegraph

private static Set<Id> limit(Set<Id> ids, Query query) {
  long fromIndex = query.offset();
  E.checkArgument(fromIndex <= Integer.MAX_VALUE,
          "Offset must be <= 0x7fffffff, but got '%s'",
          fromIndex);
  if (query.offset() >= ids.size()) {
    return ImmutableSet.of();
  }
  if (query.limit() == Query.NO_LIMIT && query.offset() == 0) {
    return ids;
  }
  long toIndex = query.offset() + query.limit();
  if (query.limit() == Query.NO_LIMIT || toIndex > ids.size()) {
    toIndex = ids.size();
  }
  assert fromIndex < ids.size();
  assert toIndex <= ids.size();
  return CollectionUtil.subSet(ids, (int) fromIndex, (int) toIndex);
}

代码示例来源:origin: hugegraph/hugegraph

protected void wrapPage(StringBuilder select, Query query) {
  String page = query.page();
  // It's the first time if page is empty
  if (!page.isEmpty()) {
    PageState pageState = PageState.fromString(page);
    Map<HugeKeys, Object> columns = pageState.columns();
    List<HugeKeys> idColumnNames = this.idColumnName();
    List<Object> values = new ArrayList<>(idColumnNames.size());
    for (HugeKeys key : idColumnNames) {
      values.add(columns.get(key));
    }
    // Need add `where` to `select` when query is IdQuery
    boolean startWithWhere = query.conditions().isEmpty();
    WhereBuilder where = new WhereBuilder(startWithWhere);
    where.gte(formatKeys(idColumnNames), values);
    select.append(where.build());
  }
  assert query.limit() != Query.NO_LIMIT;
  // Fetch `limit + 1` records for judging whether reached the last page
  select.append(" limit ");
  select.append(query.limit() + 1);
  select.append(";");
}

代码示例来源:origin: hugegraph/hugegraph

public default long setRange(long start, long end) {
  this.queryInfo().range(start, end);
  return this.queryInfo().limit();
}

代码示例来源:origin: hugegraph/hugegraph

@Override
public Iterator<BackendEntry> query(Session session, Query query) {
  ExtendableIterator<BackendEntry> rs = new ExtendableIterator<>();
  if (query.limit() == 0 && query.limit() != Query.NO_LIMIT) {
    LOG.debug("Return empty result(limit=0) for query {}", query);
    return rs;
  }
  List<StringBuilder> selections = this.query2Select(this.table(), query);
  try {
    for (StringBuilder selection : selections) {
      ResultSet results = session.select(selection.toString());
      rs.extend(this.results2Entries(query, results));
    }
  } catch (SQLException e) {
    throw new BackendException("Failed to query [%s]", e, query);
  }
  LOG.debug("Return {} for query {}", rs, query);
  return rs;
}

代码示例来源:origin: hugegraph/hugegraph

@Override
public Iterator<BackendEntry> query(CassandraSessionPool.Session session,
                  Query query) {
  ExtendableIterator<BackendEntry> rs = new ExtendableIterator<>();
  if (query.limit() == 0 && query.limit() != Query.NO_LIMIT) {
    LOG.debug("Return empty result(limit=0) for query {}", query);
    return rs;
  }
  List<Select> selections = this.query2Select(this.table(), query);
  try {
    for (Select selection : selections) {
      ResultSet results = session.query(selection);
      rs.extend(this.results2Entries(query, results));
    }
  } catch (DriverException e) {
    throw new BackendException("Failed to query [%s]", e, query);
  }
  LOG.debug("Return {} for query {}", rs, query);
  return rs;
}

代码示例来源:origin: hugegraph/hugegraph

} else if (query.limit() != Query.NO_LIMIT || query.offset() > 0) {
  this.wrapOffset(selection, query);

代码示例来源:origin: hugegraph/hugegraph

@Override
protected String pageState() {
  if (this.last == null) {
    return null;
  }
  if (this.fetched() <= this.query.limit() && this.next == null) {
    // There is no next page
    return null;
  }
  MysqlBackendEntry entry = (MysqlBackendEntry) this.last;
  PageState pageState = new PageState(entry.columnsMap());
  return pageState.toString();
}

代码示例来源:origin: hugegraph/hugegraph

@Test
public void testQueryAllWithLimitByQueryVertices() {
  HugeGraph graph = graph();
  init10Vertices();
  Query query = new Query(HugeType.VERTEX);
  query.limit(1);
  Iterator<Vertex> itor = graph.graphTransaction().queryVertices(query);
  List<Vertex> vertices = IteratorUtils.list(itor);
  Assert.assertEquals(1, vertices.size());
}

代码示例来源:origin: hugegraph/hugegraph

@Test
public void testQueryAllWithLimitByQueryEdges() {
  HugeGraph graph = graph();
  init18Edges();
  Query query = new Query(HugeType.EDGE);
  query.limit(1);
  Iterator<Edge> itor = graph.graphTransaction().queryEdges(query);
  List<Edge> edges = IteratorUtils.list(itor);
  Assert.assertEquals(1, edges.size());
}

代码示例来源:origin: hugegraph/hugegraph

@Override
public Iterator<BackendEntry> query(Session session, Query query) {
  if (query.limit() == 0 && query.limit() != Query.NO_LIMIT) {
    LOG.debug("Return empty result(limit=0) for query {}", query);
    return ImmutableList.<BackendEntry>of().iterator();

代码示例来源:origin: hugegraph/hugegraph

if (query.limit() != Query.NO_LIMIT &&
  query.offset() + query.limit() < rs.size()) {
  iterator = this.dropTails(iterator, query.limit());

代码示例来源:origin: hugegraph/hugegraph

public default <Q extends Query> Q injectQueryInfo(Q query) {
    query.orders(this.queryInfo().orders());
    query.offset(this.queryInfo().offset());
    query.limit(this.queryInfo().limit());
    query.page(this.queryInfo().page());
    query.capacity(this.queryInfo().capacity());
    return query;
  }
}

代码示例来源:origin: hugegraph/hugegraph

public CassandraEntryIterator(ResultSet results, Query query,
    BiFunction<BackendEntry, Row, BackendEntry> merger) {
  super(query);
  this.results = results;
  this.rows = results.iterator();
  this.remaining = results.getAvailableWithoutFetching();
  this.merger = merger;
  this.next = null;
  this.skipOffset();
  if (query.paging()) {
    E.checkState(this.remaining == query.limit() ||
           results.isFullyFetched(),
           "Unexpected fetched page size: %s", this.remaining);
  }
}

代码示例来源:origin: hugegraph/hugegraph

@Override
public Iterator<BackendEntry> query(Session session, Query query) {
  if (query.limit() == 0 && query.limit() != Query.NO_LIMIT) {
    LOG.debug("Return empty result(limit=0) for query {}", query);
    return ImmutableList.<BackendEntry>of().iterator();

代码示例来源:origin: hugegraph/hugegraph

if (query.limit() != Query.NO_LIMIT) {
  long total = query.total();
  String page = query.page();

代码示例来源:origin: hugegraph/hugegraph

IdQuery q = new IdQuery(query, id);
q.offset(query.offset());
q.limit(query.limit());
return super.query(session, q);

代码示例来源:origin: hugegraph/hugegraph

@Override
  protected void parseRowColumns(Result row, BackendEntry entry,
                  Query query) throws IOException {
    if (query.limit() == Query.NO_LIMIT) {
      super.parseRowColumns(row, entry, query);
      return;
    }
    long total = query.total();
    CellScanner cellScanner = row.cellScanner();
    while (cellScanner.advance() && total-- > 0) {
      Cell cell = cellScanner.current();
      entry.columns(BackendColumn.of(CellUtil.cloneQualifier(cell),
                      CellUtil.cloneValue(cell)));
    }
  }
}

相关文章