You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/11/04 09:29:35 UTC

[iotdb] branch issue-4308 created (now 1cbdf09)

This is an automated email from the ASF dual-hosted git repository.

rong pushed a change to branch issue-4308
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 1cbdf09  spotless

This branch includes the following new commits:

     new 1cd7a74  add tests
     new 70303be  fix issue-4308
     new 1cbdf09  spotless

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/03: add tests

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch issue-4308
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 1cd7a745f3f5c2b07e4018d5fbfedeb48d342246
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Thu Nov 4 16:42:52 2021 +0800

    add tests
---
 .../db/integration/auth/IoTDBAuthorizationIT.java  | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
index c45d4ce..f5684a6 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
@@ -21,11 +21,6 @@ package org.apache.iotdb.db.integration.auth;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
 import java.sql.BatchUpdateException;
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -37,6 +32,11 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -1148,4 +1148,29 @@ public class IoTDBAuthorizationIT {
       assertTrue(expectedList.containsAll(result));
     }
   }
+
+  /** ISSUE-4308 */
+  @Test
+  public void testSelectUDTF() throws ClassNotFoundException, SQLException {
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    try (Connection adminConnection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+        Statement adminStatement = adminConnection.createStatement()) {
+      adminStatement.execute("CREATE USER a_application 'a_application'");
+      adminStatement.execute("CREATE ROLE application_role");
+      adminStatement.execute("GRANT ROLE application_role PRIVILEGES READ_TIMESERIES ON root.test");
+      adminStatement.execute("GRANT application_role TO a_application");
+
+      adminStatement.execute("INSERT INTO root.test(time, s1) VALUES(1, 1)");
+    }
+
+    try (Connection userConnection =
+            DriverManager.getConnection(
+                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "a_application", "a_application");
+        Statement userStatement = userConnection.createStatement();
+        ResultSet resultSet = userStatement.executeQuery("SELECT s1, sin(s1) FROM root.test")) {
+      assertTrue(resultSet.next());
+    }
+  }
 }

[iotdb] 03/03: spotless

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch issue-4308
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 1cbdf09e8b271cfbbc0c4b20f9ed033c7b04dbc9
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Thu Nov 4 17:28:59 2021 +0800

    spotless
---
 .../main/java/org/apache/iotdb/db/service/TSServiceImpl.java | 12 ++++++------
 .../iotdb/db/integration/auth/IoTDBAuthorizationIT.java      | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index d481b71..0f1158d 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -139,6 +139,12 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.read.common.Path;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 
+import com.google.common.primitives.Bytes;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.sql.SQLException;
@@ -157,12 +163,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
-import com.google.common.primitives.Bytes;
-import org.antlr.v4.runtime.misc.ParseCancellationException;
-import org.apache.thrift.TException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /** Thrift RPC implementation at server side. */
 public class TSServiceImpl implements TSIService.Iface {
 
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
index cac280f..2e3b807 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
@@ -21,6 +21,11 @@ package org.apache.iotdb.db.integration.auth;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
 import java.sql.BatchUpdateException;
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -32,11 +37,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;

[iotdb] 02/03: fix issue-4308

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch issue-4308
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 70303be3e54941236cc26f4fd9abb6ea458a2da1
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Thu Nov 4 17:26:59 2021 +0800

    fix issue-4308
---
 .../java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java |  5 +++++
 .../org/apache/iotdb/db/qp/physical/crud/QueryPlan.java    | 12 ++++++++++++
 .../org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java     |  4 ----
 .../org/apache/iotdb/db/query/expression/ResultColumn.java | 13 +++++++++----
 .../java/org/apache/iotdb/db/service/TSServiceImpl.java    | 14 +++++++-------
 .../iotdb/db/integration/auth/IoTDBAuthorizationIT.java    |  6 ++++--
 6 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index 6a3ab45..adc8ee6 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -252,6 +252,11 @@ public abstract class PhysicalPlan {
     }
   }
 
+  /** Used to check whether a user has the permission to execute the plan with these paths. */
+  public List<PartialPath> getAuthPaths() {
+    return getPaths();
+  }
+
   public static class Factory {
 
     private Factory() {
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java
index 1b99594..e49e91b 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/QueryPlan.java
@@ -26,9 +26,12 @@ import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
 import org.apache.iotdb.db.query.expression.ResultColumn;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 public abstract class QueryPlan extends PhysicalPlan {
 
@@ -182,4 +185,13 @@ public abstract class QueryPlan extends PhysicalPlan {
   public void setWithoutAllNull(boolean withoutAllNull) {
     this.withoutAllNull = withoutAllNull;
   }
+
+  @Override
+  public List<PartialPath> getAuthPaths() {
+    Set<PartialPath> authPaths = new HashSet<>();
+    for (ResultColumn resultColumn : resultColumns) {
+      authPaths.addAll(resultColumn.collectPaths());
+    }
+    return new ArrayList<>(authPaths);
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
index 502d996..954bf30 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
@@ -128,8 +128,4 @@ public class UDTFPlan extends RawDataQueryPlan implements UDFPlan {
   public int getReaderIndex(String pathName) {
     return pathNameToReaderIndex.get(pathName);
   }
-
-  public void setPathNameToReaderIndex(Map<String, Integer> pathNameToReaderIndex) {
-    this.pathNameToReaderIndex = pathNameToReaderIndex;
-  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/ResultColumn.java b/server/src/main/java/org/apache/iotdb/db/query/expression/ResultColumn.java
index b36a56c..6248fd1 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/ResultColumn.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/expression/ResultColumn.java
@@ -73,6 +73,8 @@ public class ResultColumn {
 
   private TSDataType dataType;
 
+  private List<PartialPath> allPathsInExpression;
+
   public ResultColumn(Expression expression, String alias) {
     this.expression = expression;
     this.alias = alias;
@@ -118,10 +120,13 @@ public class ResultColumn {
     }
   }
 
-  public Set<PartialPath> collectPaths() {
-    Set<PartialPath> pathSet = new HashSet<>();
-    expression.collectPaths(pathSet);
-    return pathSet;
+  public List<PartialPath> collectPaths() {
+    if (allPathsInExpression == null) {
+      Set<PartialPath> pathSet = new HashSet<>();
+      expression.collectPaths(pathSet);
+      allPathsInExpression = new ArrayList<>(pathSet);
+    }
+    return allPathsInExpression;
   }
 
   public Expression getExpression() {
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 6a8cc7e..d481b71 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -139,12 +139,6 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.read.common.Path;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 
-import com.google.common.primitives.Bytes;
-import org.antlr.v4.runtime.misc.ParseCancellationException;
-import org.apache.thrift.TException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.sql.SQLException;
@@ -163,6 +157,12 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
+import com.google.common.primitives.Bytes;
+import org.antlr.v4.runtime.misc.ParseCancellationException;
+import org.apache.thrift.TException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /** Thrift RPC implementation at server side. */
 public class TSServiceImpl implements TSIService.Iface {
 
@@ -901,7 +901,7 @@ public class TSServiceImpl implements TSIService.Iface {
     List<String> columnsTypes = new ArrayList<>();
 
     // check permissions
-    if (!checkAuthorization(physicalPlan.getPaths(), physicalPlan, username)) {
+    if (!checkAuthorization(physicalPlan.getAuthPaths(), physicalPlan, username)) {
       return RpcUtils.getTSExecuteStatementResp(
           RpcUtils.getStatus(
               TSStatusCode.NO_PERMISSION_ERROR,
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
index f5684a6..cac280f 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
@@ -1162,14 +1162,16 @@ public class IoTDBAuthorizationIT {
       adminStatement.execute("GRANT ROLE application_role PRIVILEGES READ_TIMESERIES ON root.test");
       adminStatement.execute("GRANT application_role TO a_application");
 
-      adminStatement.execute("INSERT INTO root.test(time, s1) VALUES(1, 1)");
+      adminStatement.execute("INSERT INTO root.test(time, s1, s2, s3) VALUES(1, 2, 3, 4)");
     }
 
     try (Connection userConnection =
             DriverManager.getConnection(
                 Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "a_application", "a_application");
         Statement userStatement = userConnection.createStatement();
-        ResultSet resultSet = userStatement.executeQuery("SELECT s1, sin(s1) FROM root.test")) {
+        ResultSet resultSet =
+            userStatement.executeQuery(
+                "SELECT s1, s1, s1 - s3, s2 * sin(s1), s1 + 1 / 2 * sin(s1), sin(s1), sin(s1) FROM root.test")) {
       assertTrue(resultSet.next());
     }
   }