You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/06/06 08:59:57 UTC
[39/50] [abbrv] ignite git commit: IGNITE-5309: Added schema to
SqlFieldsQuery for C++
IGNITE-5309: Added schema to SqlFieldsQuery for C++
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2485b984
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2485b984
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2485b984
Branch: refs/heads/ignite-5075
Commit: 2485b984d78331605ff184a893e4fb22c15c77f9
Parents: 2ba6ab4
Author: Igor Sapego <is...@gridgain.com>
Authored: Mon Jun 5 17:14:29 2017 +0300
Committer: Igor Sapego <is...@gridgain.com>
Committed: Mon Jun 5 17:14:29 2017 +0300
----------------------------------------------------------------------
.../ignite/cache/query/SqlFieldsQuery.java | 12 +++--
.../platform/cache/PlatformCache.java | 4 +-
.../core-test/config/cache-query-default.xml | 27 ++++++----
.../cpp/core-test/src/cache_query_test.cpp | 47 +++++++++++++++--
.../ignite/cache/query/query_sql_fields.h | 53 +++++++++++++++++---
.../Apache.Ignite.Core/Impl/Cache/CacheImpl.cs | 1 +
6 files changed, 118 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java b/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
index 93910dc..2838fe3 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/SqlFieldsQuery.java
@@ -291,18 +291,22 @@ public class SqlFieldsQuery extends Query<List<?>> {
}
/**
- * Get schema.
+ * Get schema for the query.
+ * If not set, current cache name is used, which means you can
+ * omit schema name for tables within the current cache.
*
- * @return Schema.
+ * @return Schema. Null if schema is not set.
*/
@Nullable public String getSchema() {
return schema;
}
/**
- * Set schema.
+ * Set schema for the query.
+ * If not set, current cache name is used, which means you can
+ * omit schema name for tables within the current cache.
*
- * @param schema Schema.
+ * @param schema Schema. Null to unset schema.
* @return {@code this} for chaining.
*/
public SqlFieldsQuery setSchema(@Nullable String schema) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
index 13a8ca1..6207995 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
@@ -1312,6 +1312,7 @@ public class PlatformCache extends PlatformAbstractTarget {
int timeout = reader.readInt();
boolean replicated = reader.readBoolean();
boolean collocated = reader.readBoolean();
+ String schema = reader.readString();
return new SqlFieldsQuery(sql)
.setPageSize(pageSize)
@@ -1321,7 +1322,8 @@ public class PlatformCache extends PlatformAbstractTarget {
.setEnforceJoinOrder(enforceJoinOrder)
.setTimeout(timeout, TimeUnit.MILLISECONDS)
.setReplicatedOnly(replicated)
- .setCollocated(collocated);
+ .setCollocated(collocated)
+ .setSchema(schema);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/platforms/cpp/core-test/config/cache-query-default.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core-test/config/cache-query-default.xml b/modules/platforms/cpp/core-test/config/cache-query-default.xml
index 1c1e5f3..38636e5 100644
--- a/modules/platforms/cpp/core-test/config/cache-query-default.xml
+++ b/modules/platforms/cpp/core-test/config/cache-query-default.xml
@@ -94,12 +94,6 @@
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
- <property name="affinity">
- <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
- <property name="partitions" value="256"/>
- </bean>
- </property>
-
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
@@ -121,18 +115,29 @@
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
- <property name="affinity">
- <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
- <property name="partitions" value="256"/>
- </bean>
+ <!-- Configure type metadata to enable queries. -->
+ <property name="queryEntities">
+ <list>
+ <bean class="org.apache.ignite.cache.QueryEntity">
+ <property name="keyType" value="java.lang.Integer"/>
+ <property name="valueType" value="java.sql.Time"/>
+ </bean>
+ </list>
</property>
+ </bean>
+
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="name" value="IntCache"/>
+ <property name="cacheMode" value="PARTITIONED"/>
+ <property name="atomicityMode" value="TRANSACTIONAL"/>
+ <property name="writeSynchronizationMode" value="FULL_SYNC"/>
<!-- Configure type metadata to enable queries. -->
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Integer"/>
- <property name="valueType" value="java.sql.Time"/>
+ <property name="valueType" value="java.lang.Integer"/>
</bean>
</list>
</property>
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/platforms/cpp/core-test/src/cache_query_test.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core-test/src/cache_query_test.cpp b/modules/platforms/cpp/core-test/src/cache_query_test.cpp
index 65dcda5..e763e08 100644
--- a/modules/platforms/cpp/core-test/src/cache_query_test.cpp
+++ b/modules/platforms/cpp/core-test/src/cache_query_test.cpp
@@ -1094,14 +1094,14 @@ BOOST_AUTO_TEST_CASE(TestScanQueryPartitioned)
std::stringstream stream;
stream << "A" << key;
- BOOST_REQUIRE(entry.GetValue().GetName().compare(stream.str()) == 0);
+ BOOST_REQUIRE_EQUAL(entry.GetValue().GetName().compare(stream.str()), 0);
- BOOST_REQUIRE(entry.GetValue().GetAge() == key * 10);
+ BOOST_REQUIRE_EQUAL(entry.GetValue().GetAge(), key * 10);
}
}
// Ensure that all keys were read.
- BOOST_REQUIRE(keys.size() == entryCnt);
+ BOOST_CHECK_EQUAL(keys.size(), entryCnt);
}
/**
@@ -1915,4 +1915,45 @@ BOOST_AUTO_TEST_CASE(TestKeyValFields)
}
}
+/**
+ * Test query for Public schema.
+ */
+BOOST_AUTO_TEST_CASE(TestFieldsQuerySetSchema)
+{
+ Cache<int32_t, Time> timeCache = grid.GetCache<int32_t, Time>("TimeCache");
+
+ int32_t entryCnt = 1000; // Number of entries.
+
+ for (int i = 0; i < entryCnt; i++)
+ {
+ int secs = i % 60;
+ int mins = i / 60;
+ timeCache.Put(i, MakeTimeGmt(4, mins, secs));
+ }
+
+ Cache<int32_t, int32_t> intCache = grid.GetCache<int32_t, int32_t>("IntCache");
+
+ SqlFieldsQuery qry("select _key from Time where _val='04:11:02'");
+
+ BOOST_CHECK_EXCEPTION(intCache.Query(qry), IgniteError, ignite_test::IsGenericError);
+
+ qry.SetSchema("TimeCache");
+
+ QueryFieldsCursor cursor = intCache.Query(qry);
+
+ BOOST_REQUIRE(cursor.HasNext());
+
+ QueryFieldsRow row = cursor.GetNext();
+
+ BOOST_REQUIRE(row.HasNext());
+
+ int32_t key = row.GetNext<int32_t>();
+
+ BOOST_CHECK(key == 662);
+
+ BOOST_REQUIRE(!row.HasNext());
+
+ CheckEmpty(cursor);
+}
+
BOOST_AUTO_TEST_SUITE_END()
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
index db26fc4..bf8d7ac 100644
--- a/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
+++ b/modules/platforms/cpp/core/include/ignite/cache/query/query_sql_fields.h
@@ -49,6 +49,7 @@ namespace ignite
*/
SqlFieldsQuery(const std::string& sql) :
sql(sql),
+ schema(),
pageSize(1024),
loc(false),
distributedJoins(false),
@@ -66,6 +67,7 @@ namespace ignite
*/
SqlFieldsQuery(const std::string& sql, bool loc) :
sql(sql),
+ schema(),
pageSize(1024),
loc(false),
distributedJoins(false),
@@ -82,6 +84,7 @@ namespace ignite
*/
SqlFieldsQuery(const SqlFieldsQuery& other) :
sql(other.sql),
+ schema(other.schema),
pageSize(other.pageSize),
loc(other.loc),
distributedJoins(other.distributedJoins),
@@ -133,12 +136,15 @@ namespace ignite
{
if (this != &other)
{
- std::swap(sql, other.sql);
- std::swap(pageSize, other.pageSize);
- std::swap(loc, other.loc);
- std::swap(distributedJoins, other.distributedJoins);
- std::swap(enforceJoinOrder, other.enforceJoinOrder);
- std::swap(args, other.args);
+ using std::swap;
+
+ swap(sql, other.sql);
+ swap(sql, other.schema);
+ swap(pageSize, other.pageSize);
+ swap(loc, other.loc);
+ swap(distributedJoins, other.distributedJoins);
+ swap(enforceJoinOrder, other.enforceJoinOrder);
+ swap(args, other.args);
}
}
@@ -276,6 +282,31 @@ namespace ignite
}
/**
+ * Set schema name for the query.
+ * If not set, current cache name is used, which means you can
+ * omit schema name for tables within the current cache.
+ *
+ * @param schema Schema. Empty string to unset.
+ */
+ void SetSchema(const std::string& schema)
+ {
+ this->schema = schema;
+ }
+
+ /**
+ * Get schema name for the query.
+ *
+ * If not set, current cache name is used, which means you can
+ * omit schema name for tables within the current cache.
+ *
+ * @return Schema. Empty string if not set.
+ */
+ const std::string& GetSchema() const
+ {
+ return schema;
+ }
+
+ /**
* Write query info to the stream.
*
* @param writer Writer.
@@ -295,15 +326,23 @@ namespace ignite
writer.WriteBool(distributedJoins);
writer.WriteBool(enforceJoinOrder);
- writer.WriteInt32(0); // Timeout, ms
+ writer.WriteInt32(0); // Timeout, ms
writer.WriteBool(false); // ReplicatedOnly
writer.WriteBool(false); // Colocated
+
+ if (schema.empty())
+ writer.WriteNull();
+ else
+ writer.WriteString(schema);
}
private:
/** SQL string. */
std::string sql;
+ /** SQL Schema. */
+ std::string schema;
+
/** Page size. */
int32_t pageSize;
http://git-wip-us.apache.org/repos/asf/ignite/blob/2485b984/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
index 95787eb..e280a8f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
@@ -1089,6 +1089,7 @@ namespace Apache.Ignite.Core.Impl.Cache
writer.WriteInt((int) qry.Timeout.TotalMilliseconds);
writer.WriteBoolean(qry.ReplicatedOnly);
writer.WriteBoolean(qry.Colocated);
+ writer.WriteString(null); // Schema
});
return new FieldsQueryCursor<T>(cursor, Marshaller, _flagKeepBinary, readerFunc);