http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowDataSrcsStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowDataSrcsStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowDataSrcsStmt.java deleted file mode 100644 index 291c467..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowDataSrcsStmt.java +++ /dev/null @@ -1,72 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TShowDataSrcsParams; - -/** - * Representation of a SHOW DATA SOURCES [pattern] statement. - * Acceptable syntax: - * - * SHOW DATA SOURCES - * SHOW DATA SOURCES LIKE 'pattern' - * TODO: Refactor Show*Stmt to remove code duplication - */ -public class ShowDataSrcsStmt extends StatementBase { - // Pattern to match tables against. | denotes choice, * matches all strings - private final String pattern_; - - /** - * Default constructor, which creates a show statement which returns all - * data sources. - */ - public ShowDataSrcsStmt() { - this(null); - } - - /** - * Constructs a show statement which matches all data sources against the - * supplied pattern. - */ - public ShowDataSrcsStmt(String pattern) { - this.pattern_ = pattern; - } - - public String getPattern() { return pattern_; } - - @Override - public String toSql() { - if (pattern_ == null) { - return "SHOW DATA SOURCES"; - } else { - return "SHOW DATA SOURCES LIKE '" + pattern_ + "'"; - } - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - // Nothing to do here - } - - public TShowDataSrcsParams toThrift() { - TShowDataSrcsParams params = new TShowDataSrcsParams(); - params.setShow_pattern(getPattern()); - return params; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowDbsStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowDbsStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowDbsStmt.java deleted file mode 100644 index 40c3cc8..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowDbsStmt.java +++ /dev/null @@ -1,74 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TShowDbsParams; - -/** - * Representation of a SHOW DATABASES [pattern] statement. - * Acceptable syntax: - * - * SHOW DATABASES - * SHOW SCHEMAS - * SHOW DATABASES LIKE 'pattern' - * SHOW SCHEMAS LIKE 'pattern' - * - */ -public class ShowDbsStmt extends StatementBase { - // Pattern to match tables against. | denotes choice, * matches all strings - private final String pattern_; - - /** - * Default constructor, which creates a show statement which returns all - * databases. - */ - public ShowDbsStmt() { - this(null); - } - - /** - * Constructs a show statement which matches all databases against the - * supplied pattern. - */ - public ShowDbsStmt(String pattern) { - this.pattern_ = pattern; - } - - public String getPattern() { return pattern_; } - - @Override - public String toSql() { - if (pattern_ == null) { - return "SHOW DATABASES"; - } else { - return "SHOW DATABASES LIKE '" + pattern_ + "'"; - } - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - // Nothing to do here - } - - public TShowDbsParams toThrift() { - TShowDbsParams params = new TShowDbsParams(); - params.setShow_pattern(getPattern()); - return params; - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowFilesStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowFilesStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowFilesStmt.java deleted file mode 100644 index 0bfc46b..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowFilesStmt.java +++ /dev/null @@ -1,90 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import java.util.List; - -import com.cloudera.impala.authorization.Privilege; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TShowFilesParams; -import com.cloudera.impala.thrift.TPartitionKeyValue; -import com.cloudera.impala.catalog.Table; -import com.cloudera.impala.catalog.HdfsTable; -import com.cloudera.impala.thrift.TTableName; -import com.google.common.base.Preconditions; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; - -/** - * Representation of a SHOW FILES statement. - * Acceptable syntax: - * - * SHOW FILES IN [dbName.]tableName [PARTITION(key=value,...)] - * - */ -public class ShowFilesStmt extends StatementBase { - private TableName tableName_; - - // Show files for all the partitions if this is null. - private final PartitionSpec partitionSpec_; - - // Set during analysis. - protected Table table_; - - public ShowFilesStmt(TableName tableName, PartitionSpec partitionSpec) { - this.tableName_ = tableName; - this.partitionSpec_ = partitionSpec; - } - - @Override - public String toSql() { - StringBuilder strBuilder = new StringBuilder(); - strBuilder.append("SHOW FILES IN " + tableName_.toString()); - if (partitionSpec_ != null) strBuilder.append(" " + partitionSpec_.toSql()); - return strBuilder.toString(); - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - if (!tableName_.isFullyQualified()) { - tableName_ = new TableName(analyzer.getDefaultDb(), tableName_.getTbl()); - } - table_ = analyzer.getTable(tableName_, Privilege.VIEW_METADATA); - if (!(table_ instanceof HdfsTable)) { - throw new AnalysisException(String.format( - "SHOW FILES not applicable to a non hdfs table: %s", table_.getFullName())); - } - - // Analyze the partition spec, if one was specified. - if (partitionSpec_ != null) { - partitionSpec_.setTableName(tableName_); - partitionSpec_.setPartitionShouldExist(); - partitionSpec_.setPrivilegeRequirement(Privilege.VIEW_METADATA); - partitionSpec_.analyze(analyzer); - } - } - - public TShowFilesParams toThrift() { - TShowFilesParams params = new TShowFilesParams(); - params.setTable_name(new TTableName(tableName_.getDb(), tableName_.getTbl())); - if (partitionSpec_ != null) { - params.setPartition_spec(partitionSpec_.toThrift()); - } - return params; - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowFunctionsStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowFunctionsStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowFunctionsStmt.java deleted file mode 100644 index 33129d2..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowFunctionsStmt.java +++ /dev/null @@ -1,94 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.authorization.Privilege; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TFunctionCategory; -import com.cloudera.impala.thrift.TShowFunctionsParams; -import com.google.common.base.Preconditions; - -/** - * Representation of a SHOW FUNCTIONS [pattern] statement. - * Acceptable syntax: - * - * SHOW FUNCTIONS - * SHOW FUNCTIONS LIKE 'pattern' - * - */ -public class ShowFunctionsStmt extends StatementBase { - // Pattern to match tables against. | denotes choice, * matches all strings - private final String pattern_; - - // DB (if any) as seen by the parser - private final String parsedDb_; - - // Category of functions to be shown. Always set. - private final TFunctionCategory fnCategory_; - - // Set during analysis - private String postAnalysisDb_; - - /** - * Constructs a show statement which matches all functions against the - * supplied pattern. - */ - public ShowFunctionsStmt(String db, String pattern, TFunctionCategory fnCategory) { - Preconditions.checkNotNull(fnCategory); - parsedDb_ = db; - pattern_ = pattern; - fnCategory_ = fnCategory; - } - - /** - * Can only be called after analysis, returns the name of the database that - * this show will search against. - */ - public String getDb() { - Preconditions.checkNotNull(postAnalysisDb_); - return postAnalysisDb_; - } - - public String getPattern() { return pattern_; } - - @Override - public String toSql() { - String fnCategory = (fnCategory_ == null) ? "" : fnCategory_.toString() + " "; - if (pattern_ == null) { - return "SHOW " + fnCategory + "FUNCTIONS"; - } else { - return "SHOW " + fnCategory + "FUNCTIONS LIKE '" + pattern_ + "'"; - } - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - postAnalysisDb_ = (parsedDb_ == null ? analyzer.getDefaultDb() : parsedDb_); - if (analyzer.getDb(postAnalysisDb_, Privilege.VIEW_METADATA) == null) { - throw new AnalysisException(Analyzer.DB_DOES_NOT_EXIST_ERROR_MSG + postAnalysisDb_); - } - } - - public TShowFunctionsParams toThrift() { - TShowFunctionsParams params = new TShowFunctionsParams(); - params.setCategory(fnCategory_); - params.setDb(getDb()); - params.setShow_pattern(getPattern()); - return params; - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowGrantRoleStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowGrantRoleStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowGrantRoleStmt.java deleted file mode 100644 index b8fe737..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowGrantRoleStmt.java +++ /dev/null @@ -1,77 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.catalog.Role; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.common.InternalException; -import com.cloudera.impala.thrift.TShowGrantRoleParams; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; - -/** - * Represents a "SHOW GRANT ROLE <role> [ON <privilegeSpec>]" statement. - */ -public class ShowGrantRoleStmt extends AuthorizationStmt { - private final PrivilegeSpec privilegeSpec_; - private final String roleName_; - - // Set/modified during analysis - private Role role_; - - public ShowGrantRoleStmt(String roleName, PrivilegeSpec privilegeSpec) { - Preconditions.checkNotNull(roleName); - roleName_ = roleName; - privilegeSpec_ = privilegeSpec; - } - - public TShowGrantRoleParams toThrift() throws InternalException { - TShowGrantRoleParams params = new TShowGrantRoleParams(); - params.setRole_name(roleName_); - params.setRequesting_user(requestingUser_.getShortName()); - if (privilegeSpec_ != null) { - params.setPrivilege(privilegeSpec_.toThrift().get(0)); - params.getPrivilege().setRole_id(role_.getId()); - } - return params; - } - - @Override - public String toSql() { - StringBuilder sb = new StringBuilder("SHOW GRANT ROLE "); - sb.append(roleName_); - if (privilegeSpec_ != null) sb.append(" " + privilegeSpec_.toSql()); - return sb.toString(); - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - super.analyze(analyzer); - if (Strings.isNullOrEmpty(roleName_)) { - throw new AnalysisException("Role name in SHOW GRANT ROLE cannot be " + - "empty."); - } - role_ = analyzer.getCatalog().getAuthPolicy().getRole(roleName_); - if (role_ == null) { - throw new AnalysisException(String.format("Role '%s' does not exist.", roleName_)); - } - if (privilegeSpec_ != null) privilegeSpec_.analyze(analyzer); - } - - public Role getRole() { return role_; } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowPartitionsStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowPartitionsStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowPartitionsStmt.java deleted file mode 100644 index 69cd7a1..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowPartitionsStmt.java +++ /dev/null @@ -1,55 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.catalog.HdfsTable; -import com.cloudera.impala.common.AnalysisException; -import com.google.common.base.Preconditions; - -/** - * Representation of a SHOW PARTITIONS statement for displaying - * partition information on a given table. - */ -public class ShowPartitionsStmt extends ShowStatsStmt { - - public ShowPartitionsStmt(TableName tableName) { - super(tableName, false); - } - - @Override - public String toSql() { - return getSqlPrefix() + " " + tableName_.toString(); - } - - @Override - protected String getSqlPrefix() { return "SHOW PARTITIONS"; } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - super.analyze(analyzer); - Preconditions.checkNotNull(table_); - if (!(table_ instanceof HdfsTable)) { - throw new AnalysisException(getSqlPrefix() + " must target an HDFS table: " + - table_.getFullName()); - } - if (table_.getNumClusteringCols() == 0) { - throw new AnalysisException(String.format( - "Table is not partitioned: %s", table_.getFullName())); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowRolesStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowRolesStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowRolesStmt.java deleted file mode 100644 index 516edfe..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowRolesStmt.java +++ /dev/null @@ -1,72 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.authorization.User; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.common.InternalException; -import com.cloudera.impala.thrift.TShowRolesParams; -import com.google.common.base.Preconditions; - -/** - * Represents "SHOW [CURRENT] ROLES" and "SHOW ROLE GRANT GROUP <groupName>" - * statements. - */ -public class ShowRolesStmt extends AuthorizationStmt { - // If null, all roles will be shown. Otherwise only roles granted to this - // group will be shown. - private final String groupName_; - private final boolean isShowCurrentRoles_; - - // Set during analysis. - private User requestingUser_; - - public ShowRolesStmt(boolean isShowCurrentRoles, String groupName) { - // An empty group name should never be possible since group name is an identifier - // and Impala does not allow empty identifiers. - Preconditions.checkState(!isShowCurrentRoles || - (groupName == null || !groupName.isEmpty())); - groupName_ = groupName; - isShowCurrentRoles_ = isShowCurrentRoles; - } - - @Override - public String toSql() { - if (groupName_ == null) { - return isShowCurrentRoles_ ? "SHOW CURRENT ROLES" : "SHOW ROLES"; - } else { - return "SHOW ROLE GRANT GROUP " + groupName_; - } - } - - public TShowRolesParams toThrift() throws InternalException { - TShowRolesParams params = new TShowRolesParams(); - params.setRequesting_user(requestingUser_.getShortName()); - params.setIs_show_current_roles(isShowCurrentRoles_); - if (groupName_ != null) params.setGrant_group(groupName_); - // Users should always be able to execute SHOW CURRENT ROLES. - params.setIs_admin_op(!isShowCurrentRoles_); - return params; - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - super.analyze(analyzer); - requestingUser_ = analyzer.getUser(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowStatsStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowStatsStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowStatsStmt.java deleted file mode 100644 index a421b71..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowStatsStmt.java +++ /dev/null @@ -1,65 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.authorization.Privilege; -import com.cloudera.impala.catalog.Table; -import com.cloudera.impala.catalog.View; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TShowStatsParams; - -/** - * Representation of a SHOW TABLE/COLUMN STATS statement for - * displaying column and table/partition statistics for a given table. - */ -public class ShowStatsStmt extends StatementBase { - protected final boolean isShowColStats_; - protected final TableName tableName_; - - // Set during analysis. - protected Table table_; - - public ShowStatsStmt(TableName tableName, boolean isShowColStats) { - this.tableName_ = tableName; - this.isShowColStats_ = isShowColStats; - } - - @Override - public String toSql() { - return getSqlPrefix() + " " + tableName_.toString(); - } - - protected String getSqlPrefix() { - return "SHOW " + ((isShowColStats_) ? "COLUMN" : "TABLE") + " STATS"; - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - table_ = analyzer.getTable(tableName_, Privilege.VIEW_METADATA); - if (table_ instanceof View) { - throw new AnalysisException(String.format( - "%s not applicable to a view: %s", getSqlPrefix(), table_.getFullName())); - } - } - - public TShowStatsParams toThrift() { - // Ensure the DB is set in the table_name field by using table and not tableName. - return new TShowStatsParams(isShowColStats_, - new TableName(table_.getDb().getName(), table_.getName()).toThrift()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/ShowTablesStmt.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ShowTablesStmt.java b/fe/src/main/java/com/cloudera/impala/analysis/ShowTablesStmt.java deleted file mode 100644 index 22767b5..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/ShowTablesStmt.java +++ /dev/null @@ -1,120 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.authorization.Privilege; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TShowTablesParams; -import com.google.common.base.Preconditions; - -/** - * Representation of a SHOW TABLES [pattern] statement. - * Acceptable syntax: - * - * SHOW TABLES - * SHOW TABLES "pattern" - * SHOW TABLES LIKE "pattern" - * SHOW TABLES IN database - * SHOW TABLES IN database "pattern" - * SHOW TABLES IN database LIKE "pattern" - * - * In Hive, the 'LIKE' is optional. Also SHOW TABLES unquotedpattern is accepted - * by the parser but returns no results. We don't support that syntax. - */ -public class ShowTablesStmt extends StatementBase { - // Pattern to match tables against. | denotes choice, * matches all strings - private final String pattern_; - - // DB (if any) as seen by the parser - private final String parsedDb_; - - // Set during analysis - private String postAnalysisDb_; - - /** - * Default constructor, which creates a show statement with the default - * database and no pattern (which returns all tables in the default database). - */ - public ShowTablesStmt() { - this(null, null); - } - - /** - * Constructs a show statement against the default database using the supplied - * pattern. - */ - public ShowTablesStmt(String pattern) { - this(null, pattern); - } - - /** - * General purpose constructor which builds a show statement that matches - * table names against a given pattern in the supplied database. - * - * If pattern is null, all tables in the supplied database match. - * If database is null, the default database is searched. - */ - public ShowTablesStmt(String database, String pattern) { - this.parsedDb_ = database; - this.pattern_ = pattern; - this.postAnalysisDb_ = null; - } - - public String getPattern() { return pattern_; } - - /** - * Can only be called after analysis, returns the name of the database that - * this show will search against. - */ - public String getDb() { - Preconditions.checkNotNull(postAnalysisDb_); - return postAnalysisDb_; - } - - @Override - public String toSql() { - if (pattern_ == null) { - if (parsedDb_ == null) { - return "SHOW TABLES"; - } else { - return "SHOW TABLES IN " + parsedDb_; - } - } else { - if (parsedDb_ == null) { - return "SHOW TABLES LIKE '" + pattern_ + "'"; - } else { - return "SHOW TABLES IN " + parsedDb_ + " LIKE '" + pattern_ + "'"; - } - } - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - postAnalysisDb_ = (parsedDb_ == null ? analyzer.getDefaultDb() : parsedDb_); - if (analyzer.getDb(postAnalysisDb_, Privilege.ANY) == null) { - throw new AnalysisException(Analyzer.DB_DOES_NOT_EXIST_ERROR_MSG + postAnalysisDb_); - } - } - - public TShowTablesParams toThrift() { - TShowTablesParams params = new TShowTablesParams(); - params.setShow_pattern(getPattern()); - params.setDb(getDb()); - return params; - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/SingularRowSrcTableRef.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/SingularRowSrcTableRef.java b/fe/src/main/java/com/cloudera/impala/analysis/SingularRowSrcTableRef.java deleted file mode 100644 index 0a5d331..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/SingularRowSrcTableRef.java +++ /dev/null @@ -1,64 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import java.util.List; - -import com.cloudera.impala.planner.PlanNode; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; - -/** - * Dummy table ref that is used in plan generation for adding a SingularRowSrcNode - * inside a SubplanNode's plan tree (second child). - */ -public class SingularRowSrcTableRef extends TableRef { - private final List<TupleId> tblRefIds_; - private final List<TupleId> tupleIds_; - - public SingularRowSrcTableRef(PlanNode subplanInput) { - super(null, "singular-row-src-tblref"); - Preconditions.checkNotNull(subplanInput); - desc_ = null; - isAnalyzed_ = true; - tblRefIds_ = Lists.newArrayList(subplanInput.getTblRefIds()); - tupleIds_ = Lists.newArrayList(subplanInput.getTupleIds()); - } - - /** - * This override is needed to support join inversion where the original lhs - * is a SingularRowSrcTableRef. - */ - @Override - public void setLeftTblRef(TableRef leftTblRef) { - super.setLeftTblRef(leftTblRef); - tblRefIds_.clear(); - tupleIds_.clear(); - tblRefIds_.addAll(leftTblRef_.getAllTableRefIds()); - tupleIds_.addAll(leftTblRef_.getAllMaterializedTupleIds()); - } - - @Override - public TupleId getId() { return tblRefIds_.get(tblRefIds_.size() - 1); } - - @Override - public List<TupleId> getAllTableRefIds() { return tblRefIds_; } - - @Override - public List<TupleId> getAllMaterializedTupleIds() { return tupleIds_; } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/SlotDescriptor.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/SlotDescriptor.java b/fe/src/main/java/com/cloudera/impala/analysis/SlotDescriptor.java deleted file mode 100644 index 7850a0e..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/SlotDescriptor.java +++ /dev/null @@ -1,261 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import java.util.Collections; -import java.util.List; - -import com.cloudera.impala.catalog.Column; -import com.cloudera.impala.catalog.ColumnStats; -import com.cloudera.impala.catalog.KuduColumn; -import com.cloudera.impala.catalog.Type; -import com.cloudera.impala.thrift.TSlotDescriptor; -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; - -public class SlotDescriptor { - private final SlotId id_; - private final TupleDescriptor parent_; - - // Resolved path to the column/field corresponding to this slot descriptor, if any, - // Only set for slots that represent a column/field materialized in a scan. - private Path path_; - private Type type_; - - // Tuple descriptor for collection items. Only set if type_ is an array or map. - private TupleDescriptor itemTupleDesc_; - - // for SlotRef.toSql() in the absence of a path - private String label_; - - // Expr(s) materialized into this slot; multiple exprs for unions. Should be empty if - // path_ is set. - private List<Expr> sourceExprs_ = Lists.newArrayList(); - - // if false, this slot doesn't need to be materialized in parent tuple - // (and physical layout parameters are invalid) - private boolean isMaterialized_ = false; - - // if false, this slot cannot be NULL - private boolean isNullable_ = true; - - // physical layout parameters - private int byteSize_; - private int byteOffset_; // within tuple - private int nullIndicatorByte_; // index into byte array - private int nullIndicatorBit_; // index within byte - private int slotIdx_; // index within tuple struct - - private ColumnStats stats_; // only set if 'column' isn't set - - SlotDescriptor(SlotId id, TupleDescriptor parent) { - id_ = id; - parent_ = parent; - byteOffset_ = -1; // invalid - } - - SlotDescriptor(SlotId id, TupleDescriptor parent, SlotDescriptor src) { - id_ = id; - parent_ = parent; - type_ = src.type_; - itemTupleDesc_ = src.itemTupleDesc_; - path_ = src.path_; - label_ = src.label_; - sourceExprs_ = src.sourceExprs_; - isMaterialized_ = src.isMaterialized_; - isNullable_ = src.isNullable_; - byteSize_ = src.byteSize_; - byteOffset_ = src.byteOffset_; - nullIndicatorByte_ = src.nullIndicatorByte_; - nullIndicatorBit_ = src.nullIndicatorBit_; - slotIdx_ = src.slotIdx_; - stats_ = src.stats_; - } - - public int getNullIndicatorByte() { return nullIndicatorByte_; } - public void setNullIndicatorByte(int nullIndicatorByte) { - this.nullIndicatorByte_ = nullIndicatorByte; - } - public int getNullIndicatorBit() { return nullIndicatorBit_; } - public void setNullIndicatorBit(int nullIndicatorBit) { - this.nullIndicatorBit_ = nullIndicatorBit; - } - public SlotId getId() { return id_; } - public TupleDescriptor getParent() { return parent_; } - public Type getType() { return type_; } - public void setType(Type type) { type_ = type; } - public TupleDescriptor getItemTupleDesc() { return itemTupleDesc_; } - public void setItemTupleDesc(TupleDescriptor t) { - Preconditions.checkState( - itemTupleDesc_ == null, "Item tuple descriptor already set."); - itemTupleDesc_ = t; - } - public boolean isMaterialized() { return isMaterialized_; } - public void setIsMaterialized(boolean value) { isMaterialized_ = value; } - public boolean getIsNullable() { return isNullable_; } - public void setIsNullable(boolean value) { isNullable_ = value; } - public int getByteSize() { return byteSize_; } - public void setByteSize(int byteSize) { this.byteSize_ = byteSize; } - public int getByteOffset() { return byteOffset_; } - public void setByteOffset(int byteOffset) { this.byteOffset_ = byteOffset; } - public void setSlotIdx(int slotIdx) { this.slotIdx_ = slotIdx; } - public String getLabel() { return label_; } - public void setLabel(String label) { label_ = label; } - public void setSourceExprs(List<Expr> exprs) { sourceExprs_ = exprs; } - public void setSourceExpr(Expr expr) { sourceExprs_ = Collections.singletonList(expr); } - public void addSourceExpr(Expr expr) { sourceExprs_.add(expr); } - public List<Expr> getSourceExprs() { return sourceExprs_; } - public void setStats(ColumnStats stats) { this.stats_ = stats; } - - public void setPath(Path path) { - Preconditions.checkNotNull(path); - Preconditions.checkState(path.isRootedAtTuple()); - Preconditions.checkState(path.getRootDesc() == parent_); - path_ = path; - type_ = path_.destType(); - label_ = Joiner.on(".").join(path.getRawPath()); - - // Set nullability, if this refers to a KuduColumn. - if (path_.destColumn() instanceof KuduColumn) { - KuduColumn kuduColumn = (KuduColumn)path_.destColumn(); - isNullable_ = kuduColumn.isNullable(); - } - } - - public Path getPath() { return path_; } - - public boolean isScanSlot() { return path_ != null && path_.isRootedAtTable(); } - - public Column getColumn() { return !isScanSlot() ? null : path_.destColumn(); } - - public ColumnStats getStats() { - if (stats_ == null) { - Column c = getColumn(); - if (c != null) { - stats_ = c.getStats(); - } else { - stats_ = new ColumnStats(type_); - } - } - return stats_; - } - - /** - * Assembles the absolute materialized path to this slot starting from the schema - * root. The materialized path points to the first non-struct schema element along the - * path starting from the parent's tuple path to this slot's path. - * - * The materialized path is used to determine when a new tuple (containing a new - * instance of this slot) should be created. A tuple is emitted for every data item - * pointed to by the materialized path. For scalar slots this trivially means that every - * data item goes into a different tuple. For collection slots, the materialized path - * specifies how many data items go into a single collection value. - * - * For scalar slots, the materialized path is the same as its path. However, for - * collection slots, the materialized path may be different than path_. This happens - * when the query materializes a "flattened" collection composed of concatenated nested - * collections. - * - * For example, given the table: - * CREATE TABLE tbl (id bigint, outer_array array<array<int>>); - * - * And the query: - * select id, inner_array.item from tbl t, t.outer_array.item inner_array - * - * The path 't.outer_array.item' corresponds to the absolute path [1,0]. However, the - * 'inner_array' slot appears in the table-level tuple, with tuplePath [] (i.e. one - * tuple materialized per table row). There is a single array materialized per - * 'outer_array', not per 'inner_array'. Thus the materializedPath for this slot will be - * [1], not [1,0]. - */ - public List<Integer> getMaterializedPath() { - Preconditions.checkNotNull(parent_); - // A slot descriptor typically only has a path if the parent also has one. - // However, we sometimes materialize inline-view tuples when generating plan trees - // with EmptySetNode portions. In that case, a slot descriptor could have a non-empty - // path pointing into the inline-view tuple (which has no path). - if (!isScanSlot() || parent_.getPath() == null) return Collections.emptyList(); - Preconditions.checkState(path_.isResolved()); - - List<Integer> materializedPath = Lists.newArrayList(path_.getAbsolutePath()); - // For scalar types, the materialized path is the same as path_ - if (type_.isScalarType()) return materializedPath; - Preconditions.checkState(type_.isCollectionType()); - Preconditions.checkState(path_.getFirstCollectionIndex() != -1); - // Truncate materializedPath after first collection element - // 'offset' adjusts for the index returned by path_.getFirstCollectionIndex() being - // relative to path_.getRootDesc() - int offset = !path_.isRootedAtTuple() ? 0 : - path_.getRootDesc().getPath().getAbsolutePath().size(); - materializedPath.subList( - offset + path_.getFirstCollectionIndex() + 1, materializedPath.size()).clear(); - return materializedPath; - } - - /** - * Initializes a slot by setting its source expression information - */ - public void initFromExpr(Expr expr) { - setLabel(expr.toSql()); - Preconditions.checkState(sourceExprs_.isEmpty()); - setSourceExpr(expr); - setStats(ColumnStats.fromExpr(expr)); - Preconditions.checkState(expr.getType().isValid()); - setType(expr.getType()); - } - - public TSlotDescriptor toThrift() { - Preconditions.checkState(isMaterialized_); - List<Integer> materializedPath = getMaterializedPath(); - TSlotDescriptor result = new TSlotDescriptor( - id_.asInt(), parent_.getId().asInt(), type_.toThrift(), - materializedPath, byteOffset_, nullIndicatorByte_, nullIndicatorBit_, - slotIdx_); - if (itemTupleDesc_ != null) { - // Check for recursive or otherwise invalid item tuple descriptors. Since we assign - // tuple ids globally in increasing order, the id of an item tuple descriptor must - // always have been generated after the parent tuple id if the tuple/slot belong - // to a base table. For example, tuples/slots introduced during planning do not - // have such a guarantee. - Preconditions.checkState(!isScanSlot() || - itemTupleDesc_.getId().asInt() > parent_.getId().asInt()); - result.setItemTupleId(itemTupleDesc_.getId().asInt()); - } - return result; - } - - public String debugString() { - String pathStr = (path_ == null) ? "null" : path_.toString(); - String typeStr = (type_ == null ? "null" : type_.toString()); - return Objects.toStringHelper(this) - .add("id", id_.asInt()) - .add("path", pathStr) - .add("type", typeStr) - .add("materialized", isMaterialized_) - .add("byteSize", byteSize_) - .add("byteOffset", byteOffset_) - .add("nullable", isNullable_) - .add("nullIndicatorByte", nullIndicatorByte_) - .add("nullIndicatorBit", nullIndicatorBit_) - .add("slotIdx", slotIdx_) - .add("stats", stats_) - .toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/SlotId.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/SlotId.java b/fe/src/main/java/com/cloudera/impala/analysis/SlotId.java deleted file mode 100644 index 36e88e7..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/SlotId.java +++ /dev/null @@ -1,37 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import com.cloudera.impala.common.Id; -import com.cloudera.impala.common.IdGenerator; - -public class SlotId extends Id<SlotId> { - // Construction only allowed via an IdGenerator. - protected SlotId(int id) { - super(id); - } - - public static IdGenerator<SlotId> createGenerator() { - return new IdGenerator<SlotId>() { - @Override - public SlotId getNextId() { return new SlotId(nextId_++); } - @Override - public SlotId getMaxId() { return new SlotId(nextId_ - 1); } - }; - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/SlotRef.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/SlotRef.java b/fe/src/main/java/com/cloudera/impala/analysis/SlotRef.java deleted file mode 100644 index 8a544d0..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/SlotRef.java +++ /dev/null @@ -1,243 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.cloudera.impala.analysis.Path.PathType; -import com.cloudera.impala.catalog.Table; -import com.cloudera.impala.catalog.TableLoadingException; -import com.cloudera.impala.catalog.Type; -import com.cloudera.impala.common.AnalysisException; -import com.cloudera.impala.thrift.TExprNode; -import com.cloudera.impala.thrift.TExprNodeType; -import com.cloudera.impala.thrift.TSlotRef; -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; - -public class SlotRef extends Expr { - private final static Logger LOG = LoggerFactory.getLogger(SlotRef.class); - - private final List<String> rawPath_; - private final String label_; // printed in toSql() - - // Results of analysis. - private SlotDescriptor desc_; - - public SlotRef(ArrayList<String> rawPath) { - super(); - rawPath_ = rawPath; - label_ = ToSqlUtils.getPathSql(rawPath_); - } - - /** - * C'tor for a "dummy" SlotRef used in substitution maps. - */ - public SlotRef(String alias) { - super(); - rawPath_ = null; - // Relies on the label_ being compared in equals(). - label_ = ToSqlUtils.getIdentSql(alias.toLowerCase()); - } - - /** - * C'tor for a "pre-analyzed" ref to a slot. - */ - public SlotRef(SlotDescriptor desc) { - super(); - if (desc.isScanSlot()) { - rawPath_ = desc.getPath().getRawPath(); - } else { - rawPath_ = null; - } - isAnalyzed_ = true; - desc_ = desc; - type_ = desc.getType(); - evalCost_ = SLOT_REF_COST; - String alias = desc.getParent().getAlias(); - label_ = (alias != null ? alias + "." : "") + desc.getLabel(); - numDistinctValues_ = desc.getStats().getNumDistinctValues(); - } - - /** - * C'tor for cloning. - */ - private SlotRef(SlotRef other) { - super(other); - rawPath_ = other.rawPath_; - label_ = other.label_; - desc_ = other.desc_; - type_ = other.type_; - isAnalyzed_ = other.isAnalyzed_; - } - - @Override - public void analyze(Analyzer analyzer) throws AnalysisException { - if (isAnalyzed_) return; - super.analyze(analyzer); - Path resolvedPath = null; - try { - resolvedPath = analyzer.resolvePath(rawPath_, PathType.SLOT_REF); - } catch (TableLoadingException e) { - // Should never happen because we only check registered table aliases. - Preconditions.checkState(false); - } - Preconditions.checkNotNull(resolvedPath); - desc_ = analyzer.registerSlotRef(resolvedPath); - type_ = desc_.getType(); - if (!type_.isSupported()) { - throw new AnalysisException("Unsupported type '" - + type_.toSql() + "' in '" + toSql() + "'."); - } - if (type_.isInvalid()) { - // In this case, the metastore contained a string we can't parse at all - // e.g. map. We could report a better error if we stored the original - // HMS string. - throw new AnalysisException("Unsupported type in '" + toSql() + "'."); - } - evalCost_ = SLOT_REF_COST; - - numDistinctValues_ = desc_.getStats().getNumDistinctValues(); - Table rootTable = resolvedPath.getRootTable(); - if (rootTable != null && rootTable.getNumRows() > 0) { - // The NDV cannot exceed the #rows in the table. - numDistinctValues_ = Math.min(numDistinctValues_, rootTable.getNumRows()); - } - isAnalyzed_ = true; - } - - @Override - public boolean isConstant() { return false; } - - public SlotDescriptor getDesc() { - Preconditions.checkState(isAnalyzed_); - Preconditions.checkNotNull(desc_); - return desc_; - } - - public SlotId getSlotId() { - Preconditions.checkState(isAnalyzed_); - Preconditions.checkNotNull(desc_); - return desc_.getId(); - } - - public Path getResolvedPath() { - Preconditions.checkState(isAnalyzed_); - return desc_.getPath(); - } - - @Override - public String toSqlImpl() { - if (label_ != null) return label_; - if (rawPath_ != null) return ToSqlUtils.getPathSql(rawPath_); - return "<slot " + Integer.toString(desc_.getId().asInt()) + ">"; - } - - @Override - protected void toThrift(TExprNode msg) { - msg.node_type = TExprNodeType.SLOT_REF; - msg.slot_ref = new TSlotRef(desc_.getId().asInt()); - // we shouldn't be sending exprs over non-materialized slots - Preconditions.checkState(desc_.isMaterialized(), String.format( - "Illegal reference to non-materialized slot: tid=%s sid=%s", - desc_.getParent().getId(), desc_.getId())); - // check that the tuples associated with this slot are executable - desc_.getParent().checkIsExecutable(); - if (desc_.getItemTupleDesc() != null) desc_.getItemTupleDesc().checkIsExecutable(); - } - - @Override - public String debugString() { - Objects.ToStringHelper toStrHelper = Objects.toStringHelper(this); - if (rawPath_ != null) toStrHelper.add("path", Joiner.on('.').join(rawPath_)); - toStrHelper.add("type", type_.toSql()); - String idStr = (desc_ == null ? "null" : Integer.toString(desc_.getId().asInt())); - toStrHelper.add("id", idStr); - return toStrHelper.toString(); - } - - @Override - public int hashCode() { - if (desc_ != null) return desc_.getId().hashCode(); - return Objects.hashCode(Joiner.on('.').join(rawPath_).toLowerCase()); - } - - @Override - public boolean equals(Object obj) { - if (!super.equals(obj)) return false; - SlotRef other = (SlotRef) obj; - // check slot ids first; if they're both set we only need to compare those - // (regardless of how the ref was constructed) - if (desc_ != null && other.desc_ != null) { - return desc_.getId().equals(other.desc_.getId()); - } - if ((label_ == null) != (other.label_ == null)) return false; - if (!label_.equalsIgnoreCase(other.label_)) return false; - return true; - } - - @Override - public boolean isBoundByTupleIds(List<TupleId> tids) { - Preconditions.checkState(desc_ != null); - for (TupleId tid: tids) { - if (tid.equals(desc_.getParent().getId())) return true; - } - return false; - } - - @Override - public boolean isBoundBySlotIds(List<SlotId> slotIds) { - Preconditions.checkState(isAnalyzed_); - return slotIds.contains(desc_.getId()); - } - - @Override - public void getIdsHelper(Set<TupleId> tupleIds, Set<SlotId> slotIds) { - Preconditions.checkState(type_.isValid()); - Preconditions.checkState(desc_ != null); - if (slotIds != null) slotIds.add(desc_.getId()); - if (tupleIds != null) tupleIds.add(desc_.getParent().getId()); - } - - @Override - public Expr clone() { return new SlotRef(this); } - - @Override - public String toString() { - if (desc_ != null) { - return "tid=" + desc_.getParent().getId() + " sid=" + desc_.getId(); - } - return "no desc set"; - } - - @Override - protected Expr uncheckedCastTo(Type targetType) throws AnalysisException { - if (type_.isNull()) { - // Hack to prevent null SlotRefs in the BE - return NullLiteral.create(targetType); - } else { - return super.uncheckedCastTo(targetType); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/SortInfo.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/SortInfo.java b/fe/src/main/java/com/cloudera/impala/analysis/SortInfo.java deleted file mode 100644 index 469f1e6..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/SortInfo.java +++ /dev/null @@ -1,131 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import java.util.List; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; - -/** - * Encapsulates all the information needed to compute ORDER BY - * This doesn't contain aliases or positional exprs. - * TODO: reorganize this completely, this doesn't really encapsulate anything; this - * should move into planner/ and encapsulate the implementation of the sort of a - * particular input row (materialize all row slots) - */ -public class SortInfo { - private List<Expr> orderingExprs_; - private final List<Boolean> isAscOrder_; - // True if "NULLS FIRST", false if "NULLS LAST", null if not specified. - private final List<Boolean> nullsFirstParams_; - // The single tuple that is materialized, sorted and output by a sort operator - // (i.e. SortNode or TopNNode) - private TupleDescriptor sortTupleDesc_; - // Input expressions materialized into sortTupleDesc_. One expr per slot in - // sortTupleDesc_. - private List<Expr> sortTupleSlotExprs_; - - public SortInfo(List<Expr> orderingExprs, List<Boolean> isAscOrder, - List<Boolean> nullsFirstParams) { - Preconditions.checkArgument(orderingExprs.size() == isAscOrder.size()); - Preconditions.checkArgument(orderingExprs.size() == nullsFirstParams.size()); - orderingExprs_ = orderingExprs; - isAscOrder_ = isAscOrder; - nullsFirstParams_ = nullsFirstParams; - } - - /** - * C'tor for cloning. - */ - private SortInfo(SortInfo other) { - orderingExprs_ = Expr.cloneList(other.orderingExprs_); - isAscOrder_ = Lists.newArrayList(other.isAscOrder_); - nullsFirstParams_ = Lists.newArrayList(other.nullsFirstParams_); - sortTupleDesc_ = other.sortTupleDesc_; - if (other.sortTupleSlotExprs_ != null) { - sortTupleSlotExprs_ = Expr.cloneList(other.sortTupleSlotExprs_); - } - } - - public void setMaterializedTupleInfo( - TupleDescriptor tupleDesc, List<Expr> tupleSlotExprs) { - sortTupleDesc_ = tupleDesc; - sortTupleSlotExprs_ = tupleSlotExprs; - for (int i = 0; i < sortTupleDesc_.getSlots().size(); ++i) { - SlotDescriptor slotDesc = sortTupleDesc_.getSlots().get(i); - slotDesc.setSourceExpr(sortTupleSlotExprs_.get(i)); - } - } - public List<Expr> getOrderingExprs() { return orderingExprs_; } - public List<Boolean> getIsAscOrder() { return isAscOrder_; } - public List<Boolean> getNullsFirstParams() { return nullsFirstParams_; } - public List<Expr> getSortTupleSlotExprs() { return sortTupleSlotExprs_; } - public TupleDescriptor getSortTupleDescriptor() { return sortTupleDesc_; } - - /** - * Gets the list of booleans indicating whether nulls come first or last, independent - * of asc/desc. - */ - public List<Boolean> getNullsFirst() { - List<Boolean> nullsFirst = Lists.newArrayList(); - for (int i = 0; i < orderingExprs_.size(); ++i) { - nullsFirst.add(OrderByElement.nullsFirst(nullsFirstParams_.get(i), - isAscOrder_.get(i))); - } - return nullsFirst; - } - - /** - * Materializes the slots in sortTupleDesc_ referenced in the ordering exprs. - * Materializes the slots referenced by the corresponding sortTupleSlotExpr after - * applying the 'smap'. - */ - public void materializeRequiredSlots(Analyzer analyzer, ExprSubstitutionMap smap) { - Preconditions.checkNotNull(sortTupleDesc_); - Preconditions.checkNotNull(sortTupleSlotExprs_); - Preconditions.checkState(sortTupleDesc_.isMaterialized()); - analyzer.materializeSlots(orderingExprs_); - List<SlotDescriptor> sortTupleSlotDescs = sortTupleDesc_.getSlots(); - List<Expr> materializedExprs = Lists.newArrayList(); - for (int i = 0; i < sortTupleSlotDescs.size(); ++i) { - if (sortTupleSlotDescs.get(i).isMaterialized()) { - materializedExprs.add(sortTupleSlotExprs_.get(i)); - } - } - List<Expr> substMaterializedExprs = - Expr.substituteList(materializedExprs, smap, analyzer, false); - analyzer.materializeSlots(substMaterializedExprs); - } - - public void substituteOrderingExprs(ExprSubstitutionMap smap, Analyzer analyzer) { - orderingExprs_ = Expr.substituteList(orderingExprs_, smap, analyzer, false); - } - - /** - * Asserts that all ordering exprs are bound by the sort tuple. - */ - public void checkConsistency() { - for (Expr orderingExpr: orderingExprs_) { - Preconditions.checkState(orderingExpr.isBound(sortTupleDesc_.getId())); - } - } - - @Override - public SortInfo clone() { return new SortInfo(this); } -} http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/b544f019/fe/src/main/java/com/cloudera/impala/analysis/StatementBase.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/com/cloudera/impala/analysis/StatementBase.java b/fe/src/main/java/com/cloudera/impala/analysis/StatementBase.java deleted file mode 100644 index 9a6cb1b..0000000 --- a/fe/src/main/java/com/cloudera/impala/analysis/StatementBase.java +++ /dev/null @@ -1,141 +0,0 @@ -// 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 com.cloudera.impala.analysis; - -import org.apache.commons.lang.NotImplementedException; - -import com.cloudera.impala.catalog.Column; -import com.cloudera.impala.catalog.Type; -import com.cloudera.impala.common.AnalysisException; - -/** - * Base class for all Impala SQL statements. - */ -abstract class StatementBase implements ParseNode { - - // True if this Stmt is the top level of an explain stmt. - protected boolean isExplain_ = false; - - ///////////////////////////////////////// - // BEGIN: Members that need to be reset() - - // Analyzer that was used to analyze this statement. - protected Analyzer analyzer_; - - // END: Members that need to be reset() - ///////////////////////////////////////// - - protected StatementBase() { } - - /** - * C'tor for cloning. - */ - protected StatementBase(StatementBase other) { - analyzer_ = other.analyzer_; - isExplain_ = other.isExplain_; - } - - /** - * Analyzes the statement and throws an AnalysisException if analysis fails. A failure - * could be due to a problem with the statement or because one or more tables/views - * were missing from the catalog. - * It is up to the analysis() implementation to ensure the maximum number of missing - * tables/views get collected in the Analyzer before failing analyze(). - */ - public void analyze(Analyzer analyzer) throws AnalysisException { - if (isAnalyzed()) return; - if (isExplain_) analyzer.setIsExplain(); - analyzer_ = analyzer; - } - - public Analyzer getAnalyzer() { return analyzer_; } - public boolean isAnalyzed() { return analyzer_ != null; } - - public String toSql() { return ""; } - public void setIsExplain() { isExplain_ = true; } - public boolean isExplain() { return isExplain_; } - - /** - * Returns a deep copy of this node including its analysis state. Some members such as - * tuple and slot descriptors are generally not deep copied to avoid potential - * confusion of having multiple descriptor instances with the same id, although - * they should be unique in the descriptor table. - * TODO for 2.3: Consider also cloning table and slot descriptors for clarity, - * or otherwise make changes to more provide clearly defined clone() semantics. - */ - @Override - public StatementBase clone() { - throw new NotImplementedException( - "Clone() not implemented for " + getClass().getSimpleName()); - } - - /** - * Resets the internal analysis state of this node. - * For easier maintenance, class members that need to be reset are grouped into - * a 'section' clearly indicated by comments as follows: - * - * class SomeStmt extends StatementBase { - * ... - * ///////////////////////////////////////// - * // BEGIN: Members that need to be reset() - * - * <member declarations> - * - * // END: Members that need to be reset() - * ///////////////////////////////////////// - * ... - * } - * - * In general, members that are set or modified during analyze() must be reset(). - * TODO: Introduce this same convention for Exprs, possibly by moving clone()/reset() - * into the ParseNode interface for clarity. - */ - public void reset() { analyzer_ = null; } - - /** - * Checks that 'srcExpr' is type compatible with 'dstCol' and returns a type compatible - * expression by applying a CAST() if needed. Throws an AnalysisException the types - * are incompatible. 'dstTableName' is only used when constructing an AnalysisException - * message. - */ - protected Expr checkTypeCompatibility(String dstTableName, Column dstCol, Expr srcExpr) - throws AnalysisException { - Type dstColType = dstCol.getType(); - Type srcExprType = srcExpr.getType(); - - // Trivially compatible, unless the type is complex. - if (dstColType.equals(srcExprType) && !dstColType.isComplexType()) return srcExpr; - - Type compatType = Type.getAssignmentCompatibleType(dstColType, srcExprType, false); - if (!compatType.isValid()) { - throw new AnalysisException(String.format( - "Target table '%s' is incompatible with source expressions.\nExpression '%s' " + - "(type: %s) is not compatible with column '%s' (type: %s)", - dstTableName, srcExpr.toSql(), srcExprType.toSql(), dstCol.getName(), - dstColType.toSql())); - } - if (!compatType.equals(dstColType) && !compatType.isNull()) { - throw new AnalysisException(String.format( - "Possible loss of precision for target table '%s'.\nExpression '%s' (type: " + - "%s) would need to be cast to %s for column '%s'", - dstTableName, srcExpr.toSql(), srcExprType.toSql(), dstColType.toSql(), - dstCol.getName())); - } - return srcExpr.castTo(compatType); - } -}
