Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsititue ColumnType to Type #366

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 25 additions & 140 deletions fe/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.apache.doris.catalog.AccessPrivilege;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ColumnType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.catalog.View;
Expand Down Expand Up @@ -328,7 +327,6 @@ nonterminal InlineViewRef inline_view_ref;
nonterminal JoinOperator join_operator;
nonterminal ArrayList<String> opt_plan_hints;
nonterminal ArrayList<String> opt_sort_hints;
nonterminal PrimitiveType primitive_type;
nonterminal Expr sign_chain_expr;
nonterminal Qualifier union_op;

Expand All @@ -347,14 +345,13 @@ nonterminal List<SetVar> option_value_list, option_value_list_continued, start_o
start_option_value_list_following_option_type, user_property_list;

nonterminal Map<String, String> key_value_map, opt_key_value_map, opt_properties, opt_ext_properties;
nonterminal Column column_definition;
nonterminal ArrayList<Column> column_definition_list;
nonterminal ColumnType column_type;
nonterminal List<ColumnType> column_type_list;
nonterminal ColumnDef column_definition;
nonterminal ArrayList<ColumnDef> column_definition_list;
nonterminal AggregateType opt_agg_type;
nonterminal PartitionDesc opt_partition;
nonterminal DistributionDesc opt_distribution;
nonterminal Integer opt_distribution_number;
nonterminal Long opt_field_length;
nonterminal KeysDesc opt_keys;

nonterminal PartitionKeyDesc partition_key_desc;
Expand Down Expand Up @@ -831,6 +828,7 @@ create_stmt ::=
RESULT = new CreateClusterStmt(name, properties, password);
:}*/
/* Function */
/*
| KW_CREATE KW_FUNCTION function_name:functionName LPAREN column_type_list:arguments RPAREN
column_type:retrunType KW_SONAME STRING_LITERAL:soPath
opt_properties:properties
Expand All @@ -843,6 +841,7 @@ create_stmt ::=
{:
RESULT = new CreateFunctionStmt(functionName, arguments, retrunType, soPath, properties, true);
:}
*/
/* Table */
| KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name
LPAREN column_definition_list:columns RPAREN opt_engine:engineName
Expand Down Expand Up @@ -946,19 +945,6 @@ user_identity ::=
:}
;

column_type_list ::=
column_type:type
{:
RESULT = Lists.newArrayList();
RESULT.add(type);
:}
| column_type_list:types COMMA column_type:type
{:
types.add(type);
RESULT = types;
:}
;

// Help statement
help_stmt ::=
KW_HELP ident_or_text:mark
Expand Down Expand Up @@ -1416,89 +1402,6 @@ column_definition_list ::=
:}
;

column_type ::=
KW_TINYINT
{:
RESULT = ColumnType.createType(PrimitiveType.TINYINT);
:}
| KW_TINYINT LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createType(PrimitiveType.TINYINT);
:}
| KW_SMALLINT
{:
RESULT = ColumnType.createType(PrimitiveType.SMALLINT);
:}
| KW_SMALLINT LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createType(PrimitiveType.SMALLINT);
:}
| KW_INT
{:
RESULT = ColumnType.createType(PrimitiveType.INT);
:}
| KW_INT LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createType(PrimitiveType.INT);
:}
| KW_BIGINT
{:
RESULT = ColumnType.createType(PrimitiveType.BIGINT);
:}
| KW_BIGINT LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createType(PrimitiveType.BIGINT);
:}
| KW_LARGEINT
{:
RESULT = ColumnType.createType(PrimitiveType.LARGEINT);
:}
| KW_LARGEINT LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createType(PrimitiveType.LARGEINT);
:}
| KW_FLOAT
{:
RESULT = ColumnType.createType(PrimitiveType.FLOAT);
:}
| KW_DOUBLE
{:
RESULT = ColumnType.createType(PrimitiveType.DOUBLE);
:}
| KW_DECIMAL
{:
RESULT = ColumnType.createDecimal(10, 0);
:}
| KW_DECIMAL LPAREN INTEGER_LITERAL:precision COMMA INTEGER_LITERAL:scale RPAREN
{:
RESULT = ColumnType.createDecimal(precision.intValue(), scale.intValue());
:}
| KW_DATE
{:
RESULT = ColumnType.createType(PrimitiveType.DATE);
:}
| KW_DATETIME
{:
RESULT = ColumnType.createType(PrimitiveType.DATETIME);
:}
| KW_CHAR
{:
RESULT = ColumnType.createChar(1);
:}
| KW_CHAR LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createChar(length.intValue());
:}
| KW_VARCHAR LPAREN INTEGER_LITERAL:length RPAREN
{:
RESULT = ColumnType.createVarchar(length.intValue());
:}
| KW_HLL
{:
RESULT = ColumnType.createHll();
:}
;

opt_default_value ::=
/* Empty */
{:
Expand All @@ -1525,10 +1428,10 @@ opt_is_key ::=
;

column_definition ::=
ident:columnName column_type:dataType opt_is_key:isKey opt_agg_type:aggType opt_is_allow_null:isAllowNull opt_default_value:defaultValue opt_comment:comment
ident:columnName type_def:typeDef opt_is_key:isKey opt_agg_type:aggType opt_is_allow_null:isAllowNull opt_default_value:defaultValue opt_comment:comment
{:
Column column = new Column(columnName, dataType, isKey, aggType, isAllowNull, defaultValue, comment);
RESULT = column;
ColumnDef columnDef = new ColumnDef(columnName, typeDef, isKey, aggType, isAllowNull, defaultValue, comment);
RESULT = columnDef;
:}
;

Expand Down Expand Up @@ -3032,15 +2935,15 @@ limit_clause ::=
;

type ::=
KW_TINYINT
KW_TINYINT opt_field_length
{: RESULT = Type.TINYINT; :}
| KW_SMALLINT
| KW_SMALLINT opt_field_length
{: RESULT = Type.SMALLINT; :}
| KW_INT
| KW_INT opt_field_length
{: RESULT = Type.INT; :}
| KW_BIGINT
| KW_BIGINT opt_field_length
{: RESULT = Type.BIGINT; :}
| KW_LARGEINT
| KW_LARGEINT opt_field_length
{: RESULT = Type.LARGEINT; :}
| KW_BOOLEAN
{: RESULT = Type.BOOLEAN; :}
Expand All @@ -3053,21 +2956,30 @@ type ::=
| KW_DATETIME
{: RESULT = Type.DATETIME; :}
| KW_STRING
{: RESULT = ScalarType.createVarcharType(-1); :}
{: RESULT = ScalarType.createVarcharType(1); :}
| KW_VARCHAR LPAREN INTEGER_LITERAL:len RPAREN
{: RESULT = ScalarType.createVarcharType(len.intValue()); :}
| KW_VARCHAR
{: RESULT = ScalarType.createVarcharType(-1); :}
{: RESULT = ScalarType.createVarcharType(1); :}
| KW_CHAR LPAREN INTEGER_LITERAL:len RPAREN
{: RESULT = ScalarType.createCharType(len.intValue()); :}
| KW_CHAR
{: RESULT = ScalarType.createCharType(-1); :}
{: RESULT = ScalarType.createCharType(1); :}
| KW_DECIMAL LPAREN INTEGER_LITERAL:precision RPAREN
{: RESULT = ScalarType.createDecimalType(precision.intValue()); :}
| KW_DECIMAL LPAREN INTEGER_LITERAL:precision COMMA INTEGER_LITERAL:scale RPAREN
{: RESULT = ScalarType.createDecimalType(precision.intValue(), scale.intValue()); :}
| KW_DECIMAL
{: RESULT = ScalarType.createDecimalType(); :}
| KW_HLL
{: RESULT = Type.HLL; :}
;

opt_field_length ::=
LPAREN INTEGER_LITERAL:length RPAREN
{: RESULT = length; :}
|
{: RESULT = null; :}
;

type_def ::=
Expand Down Expand Up @@ -3509,33 +3421,6 @@ column_ref ::=
{: RESULT = new SlotRef(new TableName(db, tbl), col); :}
;

primitive_type ::=
KW_TINYINT
{: RESULT = PrimitiveType.TINYINT; :}
| KW_SMALLINT
{: RESULT = PrimitiveType.SMALLINT; :}
| KW_INT
{: RESULT = PrimitiveType.INT; :}
| KW_BIGINT
{: RESULT = PrimitiveType.BIGINT; :}
| KW_LARGEINT
{: RESULT = PrimitiveType.LARGEINT; :}
| KW_BOOLEAN
{: RESULT = PrimitiveType.BOOLEAN; :}
| KW_FLOAT
{: RESULT = PrimitiveType.FLOAT; :}
| KW_DOUBLE
{: RESULT = PrimitiveType.DOUBLE; :}
| KW_DATE
{: RESULT = PrimitiveType.DATE; :}
| KW_DATETIME
{: RESULT = PrimitiveType.DATETIME; :}
| KW_DECIMAL
{: RESULT = PrimitiveType.DECIMAL; :}
| KW_HLL
{: RESULT = PrimitiveType.HLL; :}
;

privilege_type ::=
ident:name
{:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.apache.doris.common.util.ListComparator;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.common.util.Util;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TResourceInfo;
import org.apache.doris.thrift.TStorageType;
Expand Down Expand Up @@ -86,7 +85,7 @@ public SchemaChangeHandler() {

private void processAddColumn(AddColumnClause alterClause, OlapTable olapTable,
Map<Long, LinkedList<Column>> indexSchemaMap) throws DdlException {
Column column = alterClause.getCol();
Column column = alterClause.getColumn();
ColumnPosition columnPos = alterClause.getColPos();
String targetIndexName = alterClause.getRollupName();
checkIndexExists(olapTable, targetIndexName);
Expand Down Expand Up @@ -264,7 +263,7 @@ private void processDropColumn(DropColumnClause alterClause, OlapTable olapTable

private void processModifyColumn(ModifyColumnClause alterClause, OlapTable olapTable,
Map<Long, LinkedList<Column>> indexSchemaMap) throws DdlException {
Column modColumn = alterClause.getCol();
Column modColumn = alterClause.getColumn();
if (KeysType.AGG_KEYS == olapTable.getKeysType()) {
if (modColumn.isKey() && null != modColumn.getAggregationType()) {
throw new DdlException("key column of aggregate key table cannot use aggregation method");
Expand Down Expand Up @@ -663,7 +662,7 @@ private void checkKeyModificationIfInRandomDistributedTable(OlapTable olapTable)
private void checkRowLength(List<Column> modIndexSchema) throws DdlException {
int rowLengthBytes = 0;
for (Column column : modIndexSchema) {
rowLengthBytes += column.getColumnType().getMemlayoutBytes();
rowLengthBytes += column.getType().getStorageLayoutBytes();
}

if (rowLengthBytes > Config.max_layout_length_per_row) {
Expand Down
30 changes: 16 additions & 14 deletions fe/src/main/java/org/apache/doris/analysis/AddColumnClause.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
// clause which is used to add one column to
public class AddColumnClause extends AlterClause {
private static final Logger LOG = LogManager.getLogger(AddColumnClause.class);
private Column col;
private ColumnDef columnDef;
// Column position
private ColumnPosition colPos;
// if rollupName is null, add to column to base index.
private String rollupName;

private Map<String, String> properties;
// set in analyze
private Column column;

public Column getCol() {
return col;
}
public Column getColumn() { return column; }

public ColumnPosition getColPos() {
return colPos;
Expand All @@ -52,35 +52,37 @@ public String getRollupName() {
return rollupName;
}

public AddColumnClause(Column col, ColumnPosition colPos, String rollupName,
public AddColumnClause(ColumnDef columnDef, ColumnPosition colPos, String rollupName,
Map<String, String> properties) {
this.col = col;
this.columnDef = columnDef;
this.colPos = colPos;
this.rollupName = rollupName;
this.properties = properties;
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
if (col == null) {
throw new AnalysisException("No column definition in add columnn clause.");
if (columnDef == null) {
throw new AnalysisException("No column definition in add column clause.");
}
col.analyze(true);
columnDef.analyze(true);
if (colPos != null) {
colPos.analyze();
}

if (false == col.isAllowNull() && col.getDefaultValue() == null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DEFAULT_FOR_FIELD, col.getName());
if (!columnDef.isAllowNull() && columnDef.getDefaultValue() == null) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DEFAULT_FOR_FIELD, columnDef.getName());
}

if (col.getAggregationType() != null && colPos != null && colPos.isFirst()) {
throw new AnalysisException("Cannot add value column[" + col.getName() + "] at first");
if (columnDef.getAggregateType() != null && colPos != null && colPos.isFirst()) {
throw new AnalysisException("Cannot add value column[" + columnDef.getName() + "] at first");
}

if (Strings.isNullOrEmpty(rollupName)) {
rollupName = null;
}

column = columnDef.toColumn();
}

@Override
Expand All @@ -91,7 +93,7 @@ public Map<String, String> getProperties() {
@Override
public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("ADD COLUMN ").append(col.toSql());
sb.append("ADD COLUMN ").append(columnDef.toSql());
if (colPos != null) {
sb.append(" ").append(colPos.toSql());
}
Expand Down
Loading