jpisaac commented on code in PR #1844:
URL: https://github.com/apache/phoenix/pull/1844#discussion_r1684575066
##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java:
##########
@@ -209,6 +250,151 @@ public MutationPlan compile(CreateTableStatement create)
throws SQLException {
viewStatement, viewType, viewColumnConstants,
isViewColumnReferenced, connection);
}
+ /**
+ * Restrict view to be UPDATABLE if the view specification (view
statement):
+ * 1. uses only the PK columns
+ * 2. starts from the first PK column if the parent table is not multi
tenant; otherwise,
+ * starts from the second PK column (the first column will be TENANT_ID)
+ * 3. PK columns should be in the order they are defined
+ * 4. uses the same set of PK columns as its sibling views' specification
+ * Otherwise, mark the view as READ_ONLY.
+ *
+ * @param connection The client connection
+ * @param parentToBe To be parent for given view
+ * @param pkColumnsInWhere Set of primary key in where clause
+ * @param nonPkColumnsInWhere Set of non-primary key columns in where
clause
+ * @throws IOException thrown if there is an error finding sibling views
+ * @throws SQLException
+ */
+ private ViewType setViewTypeToBe(final PhoenixConnection connection, final
PTable parentToBe,
+ final Set<PColumn> pkColumnsInWhere,
+ final Set<PColumn> nonPkColumnsInWhere)
+ throws IOException, SQLException {
+ // 1. Check the view specification WHERE clause uses only the PK
columns
+ if (!nonPkColumnsInWhere.isEmpty()) {
+ LOGGER.info("Setting the view type as READ_ONLY because the
statement contains non-PK" +
+ " columns");
+ return ViewType.READ_ONLY;
+ }
+ if (pkColumnsInWhere.isEmpty()) {
+ return ViewType.UPDATABLE;
+ }
+
+ List<Integer> tablePkPositions = new ArrayList<>();
+ List<Integer> pkPositions = new ArrayList<>();
+ parentToBe.getPKColumns().forEach(tablePkColumn ->
+ tablePkPositions.add(tablePkColumn.getPosition()));
+ pkColumnsInWhere.forEach(pkColumn ->
pkPositions.add(pkColumn.getPosition()));
+ Collections.sort(pkPositions);
+
+ // 2. If not multi tenant, view specification WHERE clause should
start from the first PK
+ // column; otherwise, start from the second PK column
+ boolean isMultiTenant = parentToBe.isMultiTenant();
+ int firstPkPosition = pkPositions.get(0);
Review Comment:
@jinggou
Adjust the logic if it is a salted table, you can find out if it is a salted
table by boolean isSalted = parentToBe.getBucketNum() != null;
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]