You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2018/08/17 14:10:12 UTC
ignite git commit: IGNITE-7701: SQL: implemented NODE_ATTRIBUTES
system view. This closes #4445.
Repository: ignite
Updated Branches:
refs/heads/master 654ccf016 -> 5d63d7f44
IGNITE-7701: SQL: implemented NODE_ATTRIBUTES system view. This closes #4445.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5d63d7f4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5d63d7f4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5d63d7f4
Branch: refs/heads/master
Commit: 5d63d7f44c343c72deb4ff1b3f5a41362646f1a4
Parents: 654ccf0
Author: Aleksey Plekhanov <pl...@gmail.com>
Authored: Fri Aug 17 17:10:04 2018 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Fri Aug 17 17:10:04 2018 +0300
----------------------------------------------------------------------
.../processors/query/h2/IgniteH2Indexing.java | 2 +
.../processors/query/h2/sys/SqlSystemIndex.java | 5 +-
.../processors/query/h2/sys/SqlSystemTable.java | 4 +-
.../h2/sys/view/SqlAbstractLocalSystemView.java | 18 +++-
.../query/h2/sys/view/SqlSystemView.java | 3 +-
.../sys/view/SqlSystemViewNodeAttributes.java | 108 +++++++++++++++++++
.../query/h2/sys/view/SqlSystemViewNodes.java | 23 +---
.../query/SqlSystemViewsSelfTest.java | 38 ++++++-
8 files changed, 171 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index cff2525..5f74c04 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -114,6 +114,7 @@ import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser;
import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQuerySplitter;
import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement;
import org.apache.ignite.internal.processors.query.h2.sys.SqlSystemTableEngine;
+import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemViewNodeAttributes;
import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemViewNodes;
import org.apache.ignite.internal.processors.query.h2.twostep.GridMapQueryExecutor;
import org.apache.ignite.internal.processors.query.h2.twostep.GridReduceQueryExecutor;
@@ -2641,6 +2642,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
Collection<SqlSystemView> views = new ArrayList<>();
views.add(new SqlSystemViewNodes(ctx));
+ views.add(new SqlSystemViewNodeAttributes(ctx));
return views;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemIndex.java
index 55f5f29..2b4896e 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemIndex.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.query.h2.sys;
+import java.util.Iterator;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2Cursor;
import org.h2.engine.Session;
import org.h2.index.BaseIndex;
@@ -73,9 +74,9 @@ public class SqlSystemIndex extends BaseIndex {
@Override public Cursor find(Session ses, SearchRow first, SearchRow last) {
assert table instanceof SqlSystemTable;
- Iterable<Row> rows = ((SqlSystemTable)table).getRows(ses, first, last);
+ Iterator<Row> rows = ((SqlSystemTable)table).getRows(ses, first, last);
- return new GridH2Cursor(rows.iterator());
+ return new GridH2Cursor(rows);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemTable.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemTable.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemTable.java
index 23106ee..664da0f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemTable.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/SqlSystemTable.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.query.h2.sys;
import java.util.ArrayList;
-
+import java.util.Iterator;
import org.apache.ignite.internal.processors.query.h2.sys.view.SqlSystemView;
import org.h2.command.ddl.CreateTableData;
import org.h2.engine.Session;
@@ -202,7 +202,7 @@ public class SqlSystemTable extends TableBase {
* @param first First.
* @param last Last.
*/
- public Iterable<Row> getRows(Session ses, SearchRow first, SearchRow last) {
+ public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last) {
return view.getRows(ses, first, last);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlAbstractLocalSystemView.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlAbstractLocalSystemView.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlAbstractLocalSystemView.java
index c601708..e8d52d2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlAbstractLocalSystemView.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlAbstractLocalSystemView.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.query.h2.sys.view;
+import java.util.UUID;
import org.apache.ignite.internal.GridKernalContext;
import org.h2.engine.Session;
import org.h2.result.Row;
@@ -27,7 +28,7 @@ import org.h2.value.ValueNull;
import org.h2.value.ValueString;
/**
- * Local meta view base class (which uses only local node data).
+ * Local system view base class (which uses only local node data).
*/
public abstract class SqlAbstractLocalSystemView extends SqlAbstractSystemView {
/**
@@ -42,7 +43,6 @@ public abstract class SqlAbstractLocalSystemView extends SqlAbstractSystemView {
super(tblName, desc, ctx, cols, indexes);
assert tblName != null;
- assert ctx != null;
assert cols != null;
assert indexes != null;
}
@@ -101,4 +101,18 @@ public abstract class SqlAbstractLocalSystemView extends SqlAbstractSystemView {
protected SqlSystemViewColumnCondition conditionForColumn(String colName, SearchRow first, SearchRow last) {
return SqlSystemViewColumnCondition.forColumn(getColumnIndex(colName), first, last);
}
+
+ /**
+ * Converts value to UUID safe (suppressing exceptions).
+ *
+ * @param val UUID.
+ */
+ protected static UUID uuidFromValue(Value val) {
+ try {
+ return UUID.fromString(val.getString());
+ }
+ catch (RuntimeException e) {
+ return null;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemView.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemView.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemView.java
index 7eab521..93fdfa0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemView.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemView.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.query.h2.sys.view;
+import java.util.Iterator;
import org.h2.engine.Session;
import org.h2.result.Row;
import org.h2.result.SearchRow;
@@ -53,7 +54,7 @@ public interface SqlSystemView {
* @param first First.
* @param last Last.
*/
- public Iterable<Row> getRows(Session ses, SearchRow first, SearchRow last);
+ public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last);
/**
* Gets row count for this view (or approximated row count, if real value can't be calculated quickly).
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodeAttributes.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodeAttributes.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodeAttributes.java
new file mode 100644
index 0000000..1ba0c7f
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodeAttributes.java
@@ -0,0 +1,108 @@
+/*
+ * 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.internal.processors.query.h2.sys.view;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.util.typedef.F;
+import org.h2.engine.Session;
+import org.h2.result.Row;
+import org.h2.result.SearchRow;
+import org.h2.value.Value;
+
+/**
+ * System view: node attributes.
+ */
+public class SqlSystemViewNodeAttributes extends SqlAbstractLocalSystemView {
+ /**
+ * @param ctx Grid context.
+ */
+ public SqlSystemViewNodeAttributes(GridKernalContext ctx) {
+ super("NODE_ATTRIBUTES", "Node attributes", ctx, new String[] {"NODE_ID,NAME", "NAME"},
+ newColumn("NODE_ID", Value.UUID),
+ newColumn("NAME"),
+ newColumn("VALUE")
+ );
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last) {
+ Collection<ClusterNode> nodes;
+
+ SqlSystemViewColumnCondition idCond = conditionForColumn("NODE_ID", first, last);
+ SqlSystemViewColumnCondition nameCond = conditionForColumn("NAME", first, last);
+
+ if (idCond.isEquality()) {
+ try {
+ UUID nodeId = uuidFromValue(idCond.valueForEquality());
+
+ ClusterNode node = nodeId == null ? null : ctx.discovery().node(nodeId);
+
+ if (node != null)
+ nodes = Collections.singleton(node);
+ else
+ nodes = Collections.emptySet();
+ }
+ catch (Exception e) {
+ nodes = Collections.emptySet();
+ }
+ }
+ else
+ nodes = F.concat(false, ctx.discovery().allNodes(), ctx.discovery().daemonNodes());
+
+ if (nameCond.isEquality()) {
+ String attrName = nameCond.valueForEquality().getString();
+
+ List<Row> rows = new ArrayList<>();
+
+ for (ClusterNode node : nodes) {
+ if (node.attributes().containsKey(attrName))
+ rows.add(
+ createRow(ses, rows.size(),
+ node.id(),
+ attrName,
+ node.attribute(attrName)
+ )
+ );
+ }
+
+ return rows.iterator();
+ }
+ else {
+ AtomicLong rowKey = new AtomicLong();
+
+ return F.concat(F.iterator(nodes,
+ node -> F.iterator(node.attributes().entrySet(),
+ attr -> createRow(ses,
+ rowKey.incrementAndGet(),
+ node.id(),
+ attr.getKey(),
+ attr.getValue()),
+ true).iterator(),
+ true));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodes.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodes.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodes.java
index e944b4f..3e97faa 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodes.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sys/view/SqlSystemViewNodes.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.query.h2.sys.view;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.apache.ignite.cluster.ClusterNode;
@@ -31,7 +32,7 @@ import org.h2.result.SearchRow;
import org.h2.value.Value;
/**
- * Meta view: nodes.
+ * System view: nodes.
*/
public class SqlSystemViewNodes extends SqlAbstractLocalSystemView {
/**
@@ -52,7 +53,7 @@ public class SqlSystemViewNodes extends SqlAbstractLocalSystemView {
}
/** {@inheritDoc} */
- @Override public Iterable<Row> getRows(Session ses, SearchRow first, SearchRow last) {
+ @Override public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last) {
List<Row> rows = new ArrayList<>();
Collection<ClusterNode> nodes;
@@ -63,7 +64,7 @@ public class SqlSystemViewNodes extends SqlAbstractLocalSystemView {
if (locCond.isEquality() && locCond.valueForEquality().getBoolean())
nodes = Collections.singleton(ctx.discovery().localNode());
else if (idCond.isEquality()) {
- UUID nodeId = uuidFromString(idCond.valueForEquality().getString());
+ UUID nodeId = uuidFromValue(idCond.valueForEquality());
nodes = nodeId == null ? Collections.emptySet() : Collections.singleton(ctx.discovery().node(nodeId));
}
@@ -87,7 +88,7 @@ public class SqlSystemViewNodes extends SqlAbstractLocalSystemView {
);
}
- return rows;
+ return rows.iterator();
}
/** {@inheritDoc} */
@@ -99,18 +100,4 @@ public class SqlSystemViewNodes extends SqlAbstractLocalSystemView {
@Override public long getRowCount() {
return ctx.discovery().allNodes().size() + ctx.discovery().daemonNodes().size();
}
-
- /**
- * Converts string to UUID safe (suppressing exceptions).
- *
- * @param val UUID in string format.
- */
- private static UUID uuidFromString(String val) {
- try {
- return UUID.fromString(val);
- }
- catch (RuntimeException e) {
- return null;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5d63d7f4/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
index 9c7ce38..acd2a1c 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlSystemViewsSelfTest.java
@@ -26,13 +26,14 @@ import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteNodeAttributes;
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
- * Tests for ignite SQL meta views.
+ * Tests for ignite SQL system views.
*/
public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
/** {@inheritDoc} */
@@ -70,7 +71,7 @@ public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
*/
private void assertSqlError(final String sql) {
Throwable t = GridTestUtils.assertThrowsWithCause(new Callable<Void>() {
- @Override public Void call() throws Exception {
+ @Override public Void call() {
execSql(sql);
return null;
@@ -85,7 +86,7 @@ public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
}
/**
- * Test meta views modifications.
+ * Test system views modifications.
*/
public void testModifications() throws Exception {
startGrid();
@@ -140,7 +141,7 @@ public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
}
/**
- * Test that we can't use cache tables and meta views in the same query.
+ * Test that we can't use cache tables and system views in the same query.
*/
public void testCacheToViewJoin() throws Exception {
Ignite ignite = startGrid();
@@ -163,7 +164,7 @@ public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
}
/**
- * Test nodes meta view.
+ * Test nodes system view.
*
* @throws Exception If failed.
*/
@@ -243,5 +244,32 @@ public class SqlSystemViewsSelfTest extends GridCommonAbstractTest {
assertEquals(ignite1.cluster().localNode().id(), execSql("SELECT N1.ID FROM IGNITE.NODES N1 " +
"WHERE NOT EXISTS (SELECT 1 FROM IGNITE.NODES N2 WHERE N2.ID = N1.ID AND N2.IS_LOCAL = false)")
.get(0).get(0));
+
+ // Check node attributes view
+ UUID cliNodeId = ignite2.cluster().localNode().id();
+
+ String cliAttrName = IgniteNodeAttributes.ATTR_CLIENT_MODE;
+
+ assertColumnTypes(execSql("SELECT NODE_ID, NAME, VALUE FROM IGNITE.NODE_ATTRIBUTES").get(0),
+ UUID.class, String.class, String.class);
+
+ assertEquals(1,
+ execSql("SELECT NODE_ID FROM IGNITE.NODE_ATTRIBUTES WHERE NAME = ? AND VALUE = 'true'",
+ cliAttrName).size());
+
+ assertEquals(3,
+ execSql("SELECT NODE_ID FROM IGNITE.NODE_ATTRIBUTES WHERE NAME = ?", cliAttrName).size());
+
+ assertEquals(1,
+ execSql("SELECT NODE_ID FROM IGNITE.NODE_ATTRIBUTES WHERE NODE_ID = ? AND NAME = ? AND VALUE = 'true'",
+ cliNodeId, cliAttrName).size());
+
+ assertEquals(0,
+ execSql("SELECT NODE_ID FROM IGNITE.NODE_ATTRIBUTES WHERE NODE_ID = '-' AND NAME = ?",
+ cliAttrName).size());
+
+ assertEquals(0,
+ execSql("SELECT NODE_ID FROM IGNITE.NODE_ATTRIBUTES WHERE NODE_ID = ? AND NAME = '-'",
+ cliNodeId).size());
}
}