ignite-sql-tests - examples

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/de8b54c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/de8b54c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/de8b54c6

Branch: refs/heads/ignite-sql-tests
Commit: de8b54c69483e4a47014e9d61fe074be1fa3b4a7
Parents: 9c1139f
Author: S.Vladykin <[email protected]>
Authored: Sun Feb 8 18:03:09 2015 +0300
Committer: S.Vladykin <[email protected]>
Committed: Sun Feb 8 18:03:09 2015 +0300

----------------------------------------------------------------------
 .../datagrid/CachePopularNumbersExample.java    |  5 +--
 .../examples/datagrid/CacheQueryExample.java    | 37 ++++++++++----------
 .../starschema/CacheStarSchemaExample.java      | 16 +++++----
 3 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/de8b54c6/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
index 0cab49a..dfaf707 100644
--- 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
+++ 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CachePopularNumbersExample.java
@@ -18,12 +18,13 @@
 package org.apache.ignite.examples.datagrid;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.query.*;
 import org.apache.ignite.cluster.*;
 
 import javax.cache.processor.*;
 import java.util.*;
 
+import static org.apache.ignite.cache.query.Query.*;
+
 /**
  * Real time popular numbers counter.
  * <p>
@@ -118,7 +119,7 @@ public class CachePopularNumbersExample {
 
                 try {
                     List<List<?>> results = new ArrayList<>(cache.queryFields(
-                        new QuerySqlPredicate("select _key, _val from Long 
order by _val desc limit " + cnt)).getAll());
+                        sql("select _key, _val from Long order by _val desc 
limit ?").setArgs(cnt)).getAll());
 
                     Collections.sort(results, new Comparator<List<?>>() {
                         @Override public int compare(List<?> r1, List<?> r2) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/de8b54c6/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
index 72a20ff..f83a37b 100644
--- 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
+++ 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
@@ -26,6 +26,8 @@ import javax.cache.*;
 import java.io.*;
 import java.util.*;
 
+import static org.apache.ignite.cache.query.Query.*;
+
 /**
  * Cache queries example. This example demonstrates SQL, TEXT, and FULL SCAN
  * queries over cache.
@@ -121,13 +123,13 @@ public class CacheQueryExample {
 
         // Execute queries for salary ranges.
         print("People with salaries between 0 and 1000: ",
-            cache.query(new QuerySqlPredicate(Person.class, sql, 0, 
1000)).getAll());
+            cache.query(sql(Person.class, sql).setArgs(0, 1000)).getAll());
 
         print("People with salaries between 1000 and 2000: ",
-            cache.query(new QuerySqlPredicate(Person.class, sql, 1000, 
2000)).getAll());
+            cache.query(sql(Person.class, sql).setArgs(1000, 2000)).getAll());
 
         print("People with salaries greater than 2000: ",
-            cache.query(new QuerySqlPredicate(Person.class, sql, 2000, 
Integer.MAX_VALUE)).getAll());
+            cache.query(sql(Person.class, sql).setArgs(2000, 
Integer.MAX_VALUE)).getAll());
     }
 
     /**
@@ -146,9 +148,9 @@ public class CacheQueryExample {
 
         // Execute queries for find employees for different organizations.
         print("Following people are 'Ignite' employees: ",
-            cache.query(new QuerySqlPredicate(Person.class, joinSql, 
"Ignite")).getAll());
+            cache.query(sql(Person.class, 
joinSql).setArgs("Ignite")).getAll());
         print("Following people are 'Other' employees: ",
-            cache.query(new QuerySqlPredicate(Person.class, joinSql, 
"Other")).getAll());
+            cache.query(sql(Person.class, joinSql).setArgs("Other")).getAll());
     }
 
     /**
@@ -161,11 +163,11 @@ public class CacheQueryExample {
 
         //  Query for all people with "Master Degree" in their resumes.
         QueryCursor<Cache.Entry<CacheAffinityKey<UUID>, Person>> masters =
-            cache.query(new QueryTextPredicate(Person.class, "Master"));
+            cache.query(text(Person.class, "Master"));
 
         // Query for all people with "Bachelor Degree" in their resumes.
         QueryCursor<Cache.Entry<CacheAffinityKey<UUID>, Person>> bachelors =
-            cache.query(new QueryTextPredicate(Person.class, "Bachelor"));
+            cache.query(text(Person.class, "Bachelor"));
 
         print("Following people have 'Master Degree' in their resumes: ", 
masters.getAll());
         print("Following people have 'Bachelor Degree' in their resumes: ", 
bachelors.getAll());
@@ -180,12 +182,12 @@ public class CacheQueryExample {
         IgniteCache<CacheAffinityKey<UUID>, Person> cache = 
Ignition.ignite().jcache(CACHE_NAME);
 
         // Calculate average of salary of all persons in Ignite.
-        QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate(
+        QueryCursor<List<?>> cursor = cache.queryFields(sql(
             "select avg(salary) from Person, Organization where Person.orgId = 
Organization.id and "
-            + "lower(Organization.name) = lower(?)", "Ignite"));
+                + "lower(Organization.name) = lower(?)").setArgs("Ignite"));
 
         // Calculate average salary for a specific organization.
-        print("Average salary for 'Ignite' employees: " + qry.getAll());
+        print("Average salary for 'Ignite' employees: " + cursor.getAll());
     }
 
     /**
@@ -198,12 +200,12 @@ public class CacheQueryExample {
         IgniteCache<?, ?> cache = Ignition.ignite().jcache(CACHE_NAME);
 
         // Create query to get names of all employees.
-        QueryCursor<List<?>> qry = cache.queryFields(
-            new QuerySqlPredicate("select concat(firstName, ' ', lastName) 
from Person"));
+        QueryCursor<List<?>> cursor = cache.queryFields(
+            sql("select concat(firstName, ' ', lastName) from Person"));
 
         // Execute query to get collection of rows. In this particular
         // case each row will have one element with full name of an employees.
-        Collection<List<?>> res = qry.getAll();
+        List<List<?>> res = cursor.getAll();
 
         // Print names.
         print("Names of all employees:", res);
@@ -218,14 +220,13 @@ public class CacheQueryExample {
     private static void sqlFieldsQueryWithJoin() throws IgniteCheckedException 
{
         IgniteCache<?, ?> cache = Ignition.ignite().jcache(CACHE_NAME);
 
-        // Create query to get names of all employees.
-        QueryCursor<List<?>> qry = cache.queryFields(new 
QuerySqlPredicate("select concat(firstName, ' ', lastName), "
+        // Execute query to get names of all employees.
+        QueryCursor<List<?>> cursor = cache.queryFields(sql("select 
concat(firstName, ' ', lastName), "
             + "Organization.name from Person, Organization where "
             + "Person.orgId = Organization.id"));
 
-        // Execute query to get collection of rows. In this particular
-        // case each row will have one element with full name of an employees.
-        Collection<List<?>> res = qry.getAll();
+        // In this particular case each row will have one element with full 
name of an employees.
+        List<List<?>> res = cursor.getAll();
 
         // Print persons' names and organizations' names.
         print("Names of all employees and organizations they belong to:", res);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/de8b54c6/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
index bedbe34..9cdb70f 100644
--- 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
+++ 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/starschema/CacheStarSchemaExample.java
@@ -26,6 +26,8 @@ import javax.cache.*;
 import java.util.*;
 import java.util.concurrent.*;
 
+import static org.apache.ignite.cache.query.Query.*;
+
 /**
  * <a href="http://en.wikipedia.org/wiki/Snowflake_schema";>Snowflake 
Schema</a> is a logical
  * arrangement of data in which data is split into {@code dimensions} and 
{@code facts}.
@@ -155,11 +157,10 @@ public class CacheStarSchemaExample {
         // ========================
 
         // Create cross cache query to get all purchases made at store1.
-        QueryCursor<Cache.Entry<Integer, FactPurchase>> storePurchases = 
factCache.query(new QuerySqlPredicate(
-                FactPurchase.class,
-                "from \"replicated\".DimStore, \"partitioned\".FactPurchase "
-                    + "where DimStore.id=FactPurchase.storeId and 
DimStore.name=?",
-                "Store1"));
+        QueryCursor<Cache.Entry<Integer, FactPurchase>> storePurchases = 
factCache.query(sql(
+            FactPurchase.class,
+            "from \"replicated\".DimStore, \"partitioned\".FactPurchase "
+                + "where DimStore.id=FactPurchase.storeId and 
DimStore.name=?").setArgs("Store1"));
 
         printQueryResults("All purchases made at store1:", 
storePurchases.getAll());
     }
@@ -186,11 +187,12 @@ public class CacheStarSchemaExample {
 
         // Create cross cache query to get all purchases made at store2
         // for specified products.
-        QueryCursor<Cache.Entry<Integer, FactPurchase>> prodPurchases = 
factCache.query(new QuerySqlPredicate(
+        QueryCursor<Cache.Entry<Integer, FactPurchase>> prodPurchases = 
factCache.query(sql(
             FactPurchase.class,
             "from \"replicated\".DimStore, \"replicated\".DimProduct, 
\"partitioned\".FactPurchase "
                 + "where DimStore.id=FactPurchase.storeId and 
DimProduct.id=FactPurchase.productId "
-                + "and DimStore.name=? and DimProduct.id in(?, ?, ?)", 
"Store2", p1.getId(), p2.getId(), p3.getId()));
+                + "and DimStore.name=? and DimProduct.id in(?, ?, ?)")
+            .setArgs("Store2", p1.getId(), p2.getId(), p3.getId()));
 
         printQueryResults("All purchases made at store2 for 3 specific 
products:", prodPurchases.getAll());
     }

Reply via email to