You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@doris.apache.org by GitBox <gi...@apache.org> on 2018/11/07 10:00:27 UTC

[GitHub] imay commented on a change in pull request #246: Colocate Join (#245)

imay commented on a change in pull request #246: Colocate Join (#245)
URL: https://github.com/apache/incubator-doris/pull/246#discussion_r231430755
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/catalog/Catalog.java
 ##########
 @@ -3261,6 +3302,59 @@ private Table createOlapTable(Database db, CreateTableStmt stmt, boolean isResto
             throw new DdlException(e.getMessage());
         }
 
+        // colocateTable
+        try {
+            String colocateTable = PropertyAnalyzer.analyzeColocate(properties);
+            if (colocateTable != null) {
+                Table parentTable;
+                db.readLock();
+                try {
+                    parentTable = db.getTable(colocateTable);
+                } finally {
+                    db.readUnlock();
+                }
+
+                //for colocate child table
+                if (!colocateTable.equalsIgnoreCase(tableName)) {
+                    if (parentTable == null) {
+                        ErrorReport.reportDdlException(ErrorCode.ERR_COLOCATE_TABLE_NO_EXIT, colocateTable);
+                    }
+
+                    if (parentTable.type != (TableType.OLAP)) {
+                        ErrorReport.reportDdlException(ErrorCode.ERR_COLOCATE_TABLE_MUST_OLAP_TABLE);
+                    }
+
+                    HashDistributionInfo parentDistribution = (HashDistributionInfo) ((OlapTable) parentTable).getDefaultDistributionInfo();
+                    if (parentDistribution.getBucketNum() != distributionInfo.getBucketNum()) {
+                        ErrorReport.reportDdlException(ErrorCode.ERR_COLOCATE_TABLE_MUST_SAME_BUCKNUM);
+                    }
+
+                    List<Column> parentColumns = parentDistribution.getDistributionColumns();
+                    List<Column> columns = ((HashDistributionInfo) distributionInfo).getDistributionColumns();
+
+                    int columnSize = parentColumns.size();
+                    if (columnSize != columns.size()) {
+                        ErrorReport.reportDdlException(ErrorCode.ERR_COLOCATE_TABLE_MUST_SAME_DISTRIBUTED_COLUMNS);
+                    }
+
+                    for (int i = 0; i < columnSize; i++) {
+                        if (!parentColumns.get(i).getColumnType().equals(columns.get(i).getColumnType())) {
+                            ErrorReport.reportDdlException(ErrorCode.ERR_COLOCATE_TABLE_MUST_SAME_DISTRIBUTED_COLUMNS);
 
 Review comment:
   Better to tell user `column_name` and `column_type`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@doris.apache.org
For additional commands, e-mail: dev-help@doris.apache.org