ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/8] ignite git commit: IGNITE-2294: Implemented DML.
Date Wed, 23 Nov 2016 09:58:39 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1.8 [created] 86d143bb8


http://git-wip-us.apache.org/repos/asf/ignite/blob/86d143bb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlMergeQueryBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlMergeQueryBenchmark.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlMergeQueryBenchmark.java
new file mode 100644
index 0000000..2a466f1
--- /dev/null
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlMergeQueryBenchmark.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.yardstick.cache.dml;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.yardstick.cache.IgniteCacheAbstractBenchmark;
+import org.apache.ignite.yardstick.cache.model.Person;
+import org.yardstickframework.BenchmarkConfiguration;
+
+import static org.yardstickframework.BenchmarkUtils.println;
+
+/**
+ * Ignite benchmark that performs SQL MERGE and query operations.
+ */
+public class IgniteSqlMergeQueryBenchmark extends IgniteCacheAbstractBenchmark<Integer,
Object> {
+    /** */
+    private AtomicInteger putCnt = new AtomicInteger();
+
+    /** */
+    private AtomicInteger qryCnt = new AtomicInteger();
+
+    /** {@inheritDoc} */
+    @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
+        super.setUp(cfg);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean test(Map<Object, Object> ctx) throws Exception {
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        if (rnd.nextBoolean()) {
+            double salary = rnd.nextDouble() * args.range() * 1000;
+
+            double maxSalary = salary + 1000;
+
+            Collection<Cache.Entry<Integer, Object>> entries = executeQuery(salary,
maxSalary);
+
+            for (Cache.Entry<Integer, Object> entry : entries) {
+                Object o = entry.getValue();
+
+                double s = o instanceof Person ? ((Person) o).getSalary() : ((BinaryObject)
o).<Double>field("salary");
+
+                if (s < salary || s > maxSalary)
+                    throw new Exception("Invalid person retrieved [min=" + salary + ", max="
+ maxSalary +
+                            ", person=" + o + ']');
+            }
+
+            qryCnt.getAndIncrement();
+        }
+        else {
+            int i = rnd.nextInt(args.range());
+
+            cache.query(new SqlFieldsQuery("merge into Person(_key, id, firstName, lastName,
salary) " +
+                "values (?, ?, ?, ?, ?)").setArgs(i ,i, "firstName" + i, "lastName" + i,
(double) i * 1000));
+
+            putCnt.getAndIncrement();
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onWarmupFinished() {
+        super.onWarmupFinished();
+    }
+
+    /**
+     * @param minSalary Min salary.
+     * @param maxSalary Max salary.
+     * @return Query result.
+     * @throws Exception If failed.
+     */
+    private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary,
double maxSalary) throws Exception {
+        SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
+
+        qry.setArgs(minSalary, maxSalary);
+
+        return cache.query(qry).getAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteCache<Integer, Object> cache() {
+        return ignite().cache("query").withKeepBinary();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void tearDown() throws Exception {
+        println(cfg, "Finished sql query put benchmark [putCnt=" + putCnt.get() + ", qryCnt="
+ qryCnt.get() + ']');
+
+        super.tearDown();
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/ignite/blob/86d143bb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateBenchmark.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateBenchmark.java
new file mode 100644
index 0000000..17eb1d2
--- /dev/null
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateBenchmark.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.yardstick.cache.dml;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.yardstick.cache.IgniteCacheAbstractBenchmark;
+import org.apache.ignite.yardstick.cache.model.Person1;
+import org.yardstickframework.BenchmarkConfiguration;
+import org.yardstickframework.BenchmarkUtils;
+
+/**
+ * Ignite benchmark that performs SQL UPDATE operations.
+ */
+public class IgniteSqlUpdateBenchmark extends IgniteCacheAbstractBenchmark<Integer, Object>
{
+    /** {@inheritDoc} */
+    @Override public void setUp(final BenchmarkConfiguration cfg) throws Exception {
+        super.setUp(cfg);
+
+        final AtomicInteger i = new AtomicInteger();
+
+        Collection<Thread> setupThreads = new ArrayList<>(cfg.threads());
+
+        for (int j = 0; j < cfg.threads(); j++) {
+            Thread t = new Thread() {
+                /** {@inheritDoc} */
+                @Override public void run() {
+                    int k;
+
+                    while ((k = i.getAndIncrement()) < args.range()) {
+                        cache().put(k, new Person1(k));
+                        if (++k % 100000 == 0)
+                            BenchmarkUtils.println(cfg, "UPDATE setUp: have successfully
put " + k + " items");
+                    }
+                }
+            };
+
+            setupThreads.add(t);
+
+            t.start();
+        }
+
+        for (Thread t : setupThreads)
+            t.join();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean test(Map<Object, Object> ctx) throws Exception {
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        cache().query(new SqlFieldsQuery("update Person1 set _val = ? where _key = ?")
+            .setArgs(new Person1(rnd.nextInt(args.range())), rnd.nextInt(args.range())));
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteCache<Integer, Object> cache() {
+        return ignite().cache("atomic-index");
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/ignite/blob/86d143bb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateFilteredBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateFilteredBenchmark.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateFilteredBenchmark.java
new file mode 100644
index 0000000..94a83df
--- /dev/null
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/dml/IgniteSqlUpdateFilteredBenchmark.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.yardstick.cache.dml;
+
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.yardstick.cache.IgniteCacheAbstractBenchmark;
+import org.apache.ignite.yardstick.cache.model.Person;
+import org.yardstickframework.BenchmarkConfiguration;
+
+import static org.yardstickframework.BenchmarkUtils.println;
+
+/**
+ * Ignite benchmark that performs put and SQL UPDATE operations.
+ */
+public class IgniteSqlUpdateFilteredBenchmark extends IgniteCacheAbstractBenchmark<Integer,
Object> {
+    /** */
+    private AtomicInteger putCnt = new AtomicInteger();
+
+    /** */
+    private AtomicInteger updCnt = new AtomicInteger();
+
+    /** */
+    private AtomicInteger updItemsCnt = new AtomicInteger();
+
+    /** {@inheritDoc} */
+    @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
+        super.setUp(cfg);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean test(Map<Object, Object> ctx) throws Exception {
+        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+        if (rnd.nextBoolean()) {
+            double salary = rnd.nextDouble() * args.range() * 1000;
+
+            double maxSalary = salary + 1000;
+
+            int res = (Integer) cache().query(new SqlFieldsQuery("update Person set salary
= (salary - ?1 + ?2) / 2 " +
+                "where salary >= ?1 and salary <= ?2").setArgs(salary, maxSalary)).getAll().get(0).get(0);
+
+            updItemsCnt.getAndAdd(res);
+
+            updCnt.getAndIncrement();
+        }
+        else {
+            int i = rnd.nextInt(args.range());
+
+            cache.put(i, new Person(i, "firstName" + i, "lastName" + i, i * 1000));
+
+            putCnt.getAndIncrement();
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteCache<Integer, Object> cache() {
+        return ignite().cache("query");
+    }
+
+    /** {@inheritDoc} */
+    @Override public void tearDown() throws Exception {
+        println(cfg, "Finished SQL UPDATE query benchmark [putCnt=" + putCnt.get() + ", updCnt="
+ updCnt.get() +
+            ", updItemsCnt=" + updItemsCnt.get() + ']');
+
+        super.tearDown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/86d143bb/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
index 20be370..19167f8 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
@@ -25,12 +25,14 @@ import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryReader;
 import org.apache.ignite.binary.BinaryWriter;
 import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
 
 /**
  * Entity class for benchmark.
  */
 public class SampleValue implements Externalizable, Binarylizable {
     /** */
+    @QuerySqlField
     private int id;
 
     /** */


Mime
View raw message