Tabnine Logo
SqlQuery
Code IndexAdd Tabnine to your IDE (free)

How to use
SqlQuery
in
org.apache.ignite.cache.query

Best Java code snippets using org.apache.ignite.cache.query.SqlQuery (Showing top 20 results out of 315)

origin: apache/ignite

/**
 * Fails if result has entries.
 *
 * @param qryStr to execute.
 * @param arg argument that will be passed to query.
 * @param cache cache on which query will be executed.
 */
private void assertEmptyEnumQry(String qryStr, Object arg, IgniteCache<Long, EnumObject> cache) {
  final SqlQuery<Long, EnumObject> qry = new SqlQuery<>(EnumObject.class, qryStr);
  qry.setArgs(arg);
  final List<Cache.Entry<Long, EnumObject>> res = cache.query(qry).getAll();
  assert res.isEmpty();
}
origin: apache/ignite

/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override public SqlFieldsQuery generateFieldsQuery(String cacheName, SqlQuery qry) {
  String schemaName = schema(cacheName);
  String type = qry.getType();
  H2TableDescriptor tblDesc = schemaMgr.tableForType(schemaName, cacheName, type);
  if (tblDesc == null)
    throw new IgniteSQLException("Failed to find SQL table for type: " + type,
      IgniteQueryErrorCode.TABLE_NOT_FOUND);
  String sql;
  try {
    sql = H2Utils.generateFieldsQueryString(qry.getSql(), qry.getAlias(), tblDesc);
  }
  catch (IgniteCheckedException e) {
    throw new IgniteException(e);
  }
  SqlFieldsQuery res = new SqlFieldsQuery(sql);
  res.setArgs(qry.getArgs());
  res.setDistributedJoins(qry.isDistributedJoins());
  res.setLocal(qry.isLocal());
  res.setPageSize(qry.getPageSize());
  res.setPartitions(qry.getPartitions());
  res.setReplicatedOnly(qry.isReplicatedOnly());
  res.setSchema(schemaName);
  res.setSql(sql);
  res.setDataPageScanEnabled(qry.isDataPageScanEnabled());
  if (qry.getTimeout() > 0)
    res.setTimeout(qry.getTimeout(), TimeUnit.MILLISECONDS);
  return res;
}
origin: apache/ignite

/**
 * Ctor.
 *
 * @param reader Reader.
 */
public ClientCacheSqlQueryRequest(BinaryRawReaderEx reader) {
  super(reader);
  qry = new SqlQuery(reader.readString(), reader.readString())
      .setArgs(PlatformCache.readQueryArgs(reader))
      .setDistributedJoins(reader.readBoolean())
      .setLocal(reader.readBoolean())
      .setReplicatedOnly(reader.readBoolean())
      .setPageSize(reader.readInt())
      .setTimeout((int) reader.readLong(), TimeUnit.MILLISECONDS);
}
origin: apache/ignite

/** Handle SQL query. */
private QueryCursor<Cache.Entry<K, V>> sqlQuery(SqlQuery qry) {
  Consumer<BinaryOutputStream> qryWriter = out -> {
    writeCacheInfo(out);
    serDes.writeObject(out, qry.getType());
    serDes.writeObject(out, qry.getSql());
    ClientUtils.collection(qry.getArgs(), out, serDes::writeObject);
    out.writeBoolean(qry.isDistributedJoins());
    out.writeBoolean(qry.isLocal());
    out.writeBoolean(qry.isReplicatedOnly());
    out.writeInt(qry.getPageSize());
    out.writeLong(qry.getTimeout());
  };
  return new ClientQueryCursor<>(new ClientQueryPager<>(
    ch,
    ClientOperation.QUERY_SQL,
    ClientOperation.QUERY_SQL_CURSOR_GET_PAGE,
    qryWriter,
    keepBinary,
    marsh
  ));
}
origin: apache/ignite

/** */
@Test
public void testDisappearedCacheWasNotFoundMessage() {
  SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JoinSqlTestHelper.JOIN_SQL).setArgs("Organization #0");
  qry.setDistributedJoins(true);
  try {
    personCache.query(qry).getAll();
    fail("No CacheException emitted.");
  }
  catch (CacheException e) {
    boolean exp = e.getMessage().contains("Cache not found on local node (was concurrently destroyed?)");
    if (!exp)
      throw e;
  }
}
origin: apache/ignite

  @Override public Object call() throws Exception {
    cachePers.query(new SqlQuery(Person.class, "SELECT firstName from PERSON"));
    return null;
  }
}, CacheException.class, null);
origin: apache/ignite

/**
 * @param ignite Ignite.
 * @param orgId Organization id.
 * @return Count of found Person object with specified orgId
 */
private static int getPersonsCountBySqlLocalQuery(final IgniteEx ignite, int orgId) {
  List res = ignite.cache(Person.class.getSimpleName())
    .query(new SqlQuery<Person.Key, Person>(Person.class, "orgId = ?").setArgs(orgId).setLocal(true))
    .getAll();
  return res.size();
}
origin: apache/ignite

  /** {@inheritDoc} */
  @Override public List<Cache.Entry<Integer, GridCacheQueryTestValue>> call() throws Exception {
    IgniteCache<Integer, GridCacheQueryTestValue> c = ignite.cache(CACHE_NAME);
    String sqlStr = "FROM GridCacheQueryTestValue WHERE fieldname = ?";
    SqlQuery<Integer, GridCacheQueryTestValue> sql = new SqlQuery<>(GridCacheQueryTestValue.class, sqlStr);
    sql.setArgs("C");
    return c.query(sql.setSql(sqlStr)).getAll();
  }
}
origin: apache/ignite

private void checkSqlQuery(IgniteCache<Long,TestData> cache, Boolean dataPageScanEnabled) {
  DirectPageScanIndexing.expectedDataPageScanEnabled = dataPageScanEnabled;
  assertTrue(cache.query(new SqlQuery<>(TestData.class,
    "from TestData use index() where check_scan_flag(?,false)") // Force full scan with USE INDEX()
    .setArgs(DirectPageScanIndexing.expectedDataPageScanEnabled)
    .setDataPageScanEnabled(DirectPageScanIndexing.expectedDataPageScanEnabled))
    .getAll().isEmpty());
  checkSqlLastFindDataPageScan(dataPageScanEnabled);
}
origin: apache/ignite

/**
 * Test metrics for Scan queries.
 *
 * @throws Exception In case of error.
 */
@Test
public void testSqlQueryHistoryNotFullyFetched() throws Exception {
  SqlQuery<Integer, String> qry = new SqlQuery<>("String", "from String");
  qry.setPageSize(10);
  checkQueryNotFullyFetchedMetrics(qry, true);
}
origin: apache/ignite

  new SqlQuery<Integer, Person>(Person.class, "id >= ?").setArgs(minId).setPageSize(pageSize)
);
origin: apache/ignite

/**
 * Test table alias in SqlQuery.
 *
 * @throws Exception In case of error.
 */
@Test
public void testTableAliasInSqlQuery() throws Exception {
  IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
  int key = 898;
  int val = 2;
  cache.put(key, val);
  SqlQuery<Integer, Integer> sqlQry = new SqlQuery<>(Integer.class, "t1._key = ? and t1._val > 1");
  QueryCursor<Cache.Entry<Integer, Integer>> qry = cache.query(sqlQry.setAlias("t1").setArgs(key));
  Cache.Entry<Integer, Integer> entry = F.first(qry.getAll());
  assert entry != null;
  assertEquals(key, entry.getKey().intValue());
  assertEquals(val, entry.getValue().intValue());
  sqlQry = new SqlQuery<>(Integer.class, "FROM Integer as t1 WHERE t1._key = ? and t1._val > 1");
  qry = cache.query(sqlQry.setAlias("t1").setArgs(key));
  entry = F.first(qry.getAll());
  assert entry != null;
  assertEquals(key, entry.getKey().intValue());
  assertEquals(val, entry.getValue().intValue());
}
origin: apache/ignite

/**
 * @param orig Originator.
 */
protected void doTestRegionQuery(Ignite orig) {
  IgniteCache<ClientKey, Client> cl = orig.cache("cl");
  for (int regionId = 1; regionId <= PARTS_PER_REGION.length; regionId++) {
    SqlQuery<ClientKey, Client> qry1 = new SqlQuery<>(Client.class, "regionId=?");
    qry1.setArgs(regionId);
    List<Cache.Entry<ClientKey, Client>> clients1 = cl.query(qry1).getAll();
    int expRegionCnt = regionId == 5 ? 0 : PARTS_PER_REGION[regionId - 1] * CLIENTS_PER_PARTITION;
    assertEquals("Region " + regionId + " count", expRegionCnt, clients1.size());
    validateClients(regionId, clients1);
    // Repeat the same query with partition set condition.
    List<Integer> range = REGION_TO_PART_MAP.get(regionId);
    SqlQuery<ClientKey, Client> qry2 = new SqlQuery<>(Client.class, "1=1");
    qry2.setPartitions(createRange(range.get(0), range.get(1)));
    try {
      List<Cache.Entry<ClientKey, Client>> clients2 = cl.query(qry2).getAll();
      assertEquals("Region " + regionId + " count with partition set", expRegionCnt, clients2.size());
      // Query must produce only results from single region.
      validateClients(regionId, clients2);
      if (regionId == UNMAPPED_REGION)
        fail();
    } catch (CacheException ignored) {
      if (regionId != UNMAPPED_REGION)
        fail();
    }
  }
}
origin: apache/ignite

/**
 * Tests local sql query.
 */
@Test
public void testLocalSqlQuery() {
  IgniteCache<Integer, Value> cache = grid(0).cache(DEFAULT_CACHE_NAME);
  SqlQuery<Integer, Value> qry = new SqlQuery<>(Value.class.getSimpleName(), "select * from Value");
  qry.setLocal(true);
  List<Cache.Entry<Integer, Value>> all = cache.query(qry).getAll();
  assertFalse(all.isEmpty());
  for (Cache.Entry<Integer, Value> entry : all)
    entry.getValue().str = "after";
  check(cache);
}
origin: org.apache.ignite/ignite-core

/**
 * Execute distributed SQL query.
 *
 * @param cctx Cache context.
 * @param qry Query.
 * @param keepBinary Keep binary flag.
 * @return Cursor.
 */
public <K, V> QueryCursor<Cache.Entry<K,V>> querySql(final GridCacheContext<?,?> cctx, final SqlQuery qry,
  boolean keepBinary) {
  validateSqlQuery(qry, ctx, cctx);
  if (qry.isReplicatedOnly() && qry.getPartitions() != null)
    throw new CacheException("Partitions are not supported in replicated only mode.");
  if (qry.isDistributedJoins() && qry.getPartitions() != null)
    throw new CacheException(
      "Using both partitions and distributed JOINs is not supported for the same query");
  if ((qry.isReplicatedOnly() && cctx.isReplicatedAffinityNode()) || cctx.isLocal() || qry.isLocal())
    return queryLocalSql(cctx, qry, keepBinary);
  return queryDistributedSql(cctx, qry, keepBinary);
}
origin: org.apache.ignite/ignite-indexing

@Override public <K, V> QueryCursor<Cache.Entry<K,V>> queryLocalSql(String schemaName, String cacheName,
  final SqlQuery qry, final IndexingQueryFilter filter, final boolean keepBinary) throws IgniteCheckedException {
  String type = qry.getType();
  String sqlQry = qry.getSql();
  String alias = qry.getAlias();
  Object[] params = qry.getArgs();
origin: apache/ignite

  /** {@inheritDoc} */
  @Override public ClientResponse process(ClientConnectionContext ctx) {
    IgniteCache cache = cache(ctx);

    ctx.incrementCursors();

    try {
      QueryCursor cur = cache.query(qry);

      ClientCacheEntryQueryCursor cliCur = new ClientCacheEntryQueryCursor(
          cur, qry.getPageSize(), ctx);

      long cursorId = ctx.resources().put(cliCur);

      cliCur.id(cursorId);

      return new ClientCacheQueryResponse(requestId(), cliCur);
    }
    catch (Exception e) {
      ctx.decrementCursors();

      throw e;
    }
  }
}
origin: apache/ignite

/**
 * Convert query arguments to BinaryObjects if binary marshaller used.
 *
 * @param qry Query.
 */
private void convertToBinary(final Query qry) {
  GridCacheContext<K, V> ctx = getContextSafe();
  if (ctx.binaryMarshaller()) {
    if (qry instanceof SqlQuery) {
      final SqlQuery sqlQry = (SqlQuery) qry;
      convertToBinary(sqlQry.getArgs());
    }
    else if (qry instanceof SpiQuery) {
      final SpiQuery spiQry = (SpiQuery) qry;
      convertToBinary(spiQry.getArgs());
    }
    else if (qry instanceof SqlFieldsQuery) {
      final SqlFieldsQuery fieldsQry = (SqlFieldsQuery) qry;
      convertToBinary(fieldsQry.getArgs());
    }
  }
}
origin: org.apache.ignite/ignite-core

return executeQuery(GridCacheQueryType.SQL, qry.getSql(), cctx,
  new IgniteOutClosureX<QueryCursor<Cache.Entry<K, V>>>() {
    @Override public QueryCursor<Cache.Entry<K, V>> applyx() throws IgniteCheckedException {
origin: apache/ignite

/** */
@Test
public void testDisappearedCacheCauseRetryMessage() {
  SqlQuery<String, JoinSqlTestHelper.Person> qry = new SqlQuery<String, JoinSqlTestHelper.Person>(JoinSqlTestHelper.Person.class, JoinSqlTestHelper.JOIN_SQL).setArgs("Organization #0");
  qry.setDistributedJoins(true);
  try {
    personCache.query(qry).getAll();
    fail("No CacheException emitted.");
  }
  catch (CacheException e) {
    assertTrue(e.getMessage(), e.getMessage().contains("Failed to reserve partitions for query (cache is not found on local node) ["));
  }
}
org.apache.ignite.cache.querySqlQuery

Javadoc

SQL Query.

Most used methods

  • <init>
    Constructs query for the given type name and SQL query.
  • setArgs
    Sets SQL arguments.
  • getArgs
    Gets SQL arguments.
  • getPageSize
  • getPartitions
    Gets partitions for query, in ascending order.
  • getSql
    Gets SQL clause.
  • getTimeout
    Gets the query execution timeout in milliseconds.
  • getType
    Gets type for query.
  • isDistributedJoins
    Check if distributed joins are enabled for this query.
  • isLocal
  • isReplicatedOnly
    Check is the query contains only replicated tables.
  • setDistributedJoins
    Specify if distributed joins are enabled for this query. When disabled, join results will only conta
  • isReplicatedOnly,
  • setDistributedJoins,
  • setLocal,
  • setPageSize,
  • setReplicatedOnly,
  • setSql,
  • getAlias,
  • isDataPageScanEnabled,
  • prepare,
  • setAlias

Popular in Java

  • Creating JSON documents from java classes using gson
  • getApplicationContext (Context)
  • onCreateOptionsMenu (Activity)
  • runOnUiThread (Activity)
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • ImageIO (javax.imageio)
  • BoxLayout (javax.swing)
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now