Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobhan1 committed Oct 25, 2023
1 parent 4403451 commit f18428c
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 12 deletions.
2 changes: 2 additions & 0 deletions be/src/vec/functions/function_date_or_datetime_computation.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ struct CurrentDateTimeImpl {
static Status executeImpl(FunctionContext* context, Block& block,
const ColumnNumbers& arguments, size_t result,
size_t input_rows_count) {
LOG(INFO) << fmt::format("[CurrentDateTimeImpl::executeImpl] input_rows_count: {}",
input_rows_count);
auto col_to = ColumnVector<NativeType>::create();
DateValueType dtv;
bool use_const;
Expand Down
12 changes: 9 additions & 3 deletions be/src/vec/sink/vtablet_block_convertor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ Status OlapTableBlockConvertor::validate_and_convert_block(
std::shared_ptr<vectorized::Block>& block, vectorized::VExprContextSPtrs output_vexpr_ctxs,
size_t rows, bool& has_filtered_rows) {
DCHECK(input_block->rows() > 0);

LOG(INFO) << fmt::format(
"[OlapTableBlockConvertor::validate_and_convert_block-1] input block:\n{}",
input_block->dump_structure());
block = vectorized::Block::create_shared(input_block->get_columns_with_type_and_name());
if (!output_vexpr_ctxs.empty()) {
// Do vectorized expr here to speed up load
RETURN_IF_ERROR(vectorized::VExprContext::get_output_block_after_execute_exprs(
output_vexpr_ctxs, *input_block, block.get()));
}

LOG(INFO) << fmt::format(
"[OlapTableBlockConvertor::validate_and_convert_block-2] input block:\n{}",
input_block->dump_structure());
// fill the valus for auto-increment columns
if (_auto_inc_col_idx.has_value()) {
RETURN_IF_ERROR(_fill_auto_inc_cols(block.get(), rows));
Expand All @@ -87,7 +91,9 @@ Status OlapTableBlockConvertor::validate_and_convert_block(
}
_convert_to_dest_desc_block(block.get());
}

LOG(INFO) << fmt::format(
"[OlapTableBlockConvertor::validate_and_convert_block-2] input block:\n{}",
input_block->dump_structure());
return Status::OK();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ columnDef
: colName=identifier type=dataType
KEY? (aggType=aggTypeDef)? ((NOT NULL) | NULL)?
(DEFAULT (nullValue=NULL | INTEGER_VALUE | stringValue=STRING_LITERAL
| CURRENT_TIMESTAMP (LEFT_PAREN precision=number RIGHT_PAREN)?))?
| CURRENT_TIMESTAMP (LEFT_PAREN precision1=number RIGHT_PAREN)?))?
(ON UPDATE CURRENT_TIMESTAMP (LEFT_PAREN precision2=number RIGHT_PAREN)?)?
(COMMENT comment=STRING_LITERAL)?
;

Expand Down
31 changes: 28 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public class Column implements Writable, GsonPostProcessable {

private boolean isCompoundKey = false;

private boolean hasOnUpdateDefaultValue = false;

private DefaultValueExprDef onUpdateDefaultValueExprDef;

public Column() {
this.name = "";
this.type = Type.NULL;
Expand Down Expand Up @@ -170,24 +174,33 @@ public Column(String name, Type type, boolean isKey, AggregateType aggregateType
public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
String defaultValue, String comment) {
this(name, type, isKey, aggregateType, isAllowNull, false, defaultValue, comment, true, null,
COLUMN_UNIQUE_ID_INIT_VALUE, defaultValue);
COLUMN_UNIQUE_ID_INIT_VALUE, defaultValue, false, null);
}

public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
String comment, boolean visible, int colUniqueId) {
this(name, type, isKey, aggregateType, isAllowNull, false, null, comment, visible, null, colUniqueId, null);
this(name, type, isKey, aggregateType, isAllowNull, false, null, comment, visible, null, colUniqueId, null,
false, null);
}

public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
String defaultValue, String comment, boolean visible, DefaultValueExprDef defaultValueExprDef,
int colUniqueId, String realDefaultValue) {
this(name, type, isKey, aggregateType, isAllowNull, false, defaultValue, comment, visible, defaultValueExprDef,
colUniqueId, realDefaultValue);
colUniqueId, realDefaultValue, false, null);
}

public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
boolean isAutoInc, String defaultValue, String comment, boolean visible,
DefaultValueExprDef defaultValueExprDef, int colUniqueId, String realDefaultValue) {
this(name, type, isKey, aggregateType, isAllowNull, isAutoInc, defaultValue, comment, visible,
defaultValueExprDef, colUniqueId, realDefaultValue, false, null);
}

public Column(String name, Type type, boolean isKey, AggregateType aggregateType, boolean isAllowNull,
boolean isAutoInc, String defaultValue, String comment, boolean visible,
DefaultValueExprDef defaultValueExprDef, int colUniqueId, String realDefaultValue,
boolean hasOnUpdateDefaultValue, DefaultValueExprDef onUpdateDefaultValueExprDef) {
this.name = name;
if (this.name == null) {
this.name = "";
Expand All @@ -212,6 +225,8 @@ public Column(String name, Type type, boolean isKey, AggregateType aggregateType
this.children = new ArrayList<>();
createChildrenColumn(this.type, this);
this.uniqueId = colUniqueId;
this.hasOnUpdateDefaultValue = hasOnUpdateDefaultValue;
this.onUpdateDefaultValueExprDef = onUpdateDefaultValueExprDef;

if (type.isAggStateType()) {
AggStateType aggState = (AggStateType) type;
Expand Down Expand Up @@ -244,6 +259,8 @@ public Column(Column column) {
this.uniqueId = column.getUniqueId();
this.defineExpr = column.getDefineExpr();
this.defineName = column.getDefineName();
this.hasOnUpdateDefaultValue = column.hasOnUpdateDefaultValue;
this.onUpdateDefaultValueExprDef = column.onUpdateDefaultValueExprDef;
}

public void createChildrenColumn(Type type, Column column) {
Expand Down Expand Up @@ -489,6 +506,14 @@ public int getOlapColumnIndexSize() {
}
}

public boolean hasOnUpdateDefaultValue() {
return hasOnUpdateDefaultValue;
}

public Expr getOnUpdateDefaultValueExpr() throws AnalysisException {
return onUpdateDefaultValueExprDef.getExpr(type);
}

public TColumn toThrift() {
TColumn tColumn = new TColumn();
tColumn.setColumnName(removeNamePrefix(this.name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ public PlanFragment visitPhysicalOlapTableSink(PhysicalOlapTableSink<? extends P
for (Column col : olapTableSink.getCols()) {
partialUpdateCols.add(col.getName());
}
for (Column col : olapTable.getFullSchema()) {
if (col.hasOnUpdateDefaultValue()) {
partialUpdateCols.add(col.getName());
}
}
if (olapTable.hasSequenceCol() && olapTable.getSequenceMapCol() != null
&& partialUpdateCols.contains(olapTable.getSequenceMapCol())) {
partialUpdateCols.add(Column.SEQUENCE_COL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,7 @@ public ColumnDefinition visitColumnDef(ColumnDefContext ctx) {
boolean isNotNull = ctx.NOT() != null;
String aggTypeString = ctx.aggType != null ? ctx.aggType.getText() : null;
Optional<DefaultValue> defaultValue = Optional.empty();
Optional<DefaultValue> onUpdateDefaultValue = Optional.empty();
if (ctx.DEFAULT() != null) {
if (ctx.INTEGER_VALUE() != null) {
defaultValue = Optional.of(new DefaultValue(ctx.INTEGER_VALUE().getText()));
Expand All @@ -1972,14 +1973,22 @@ public ColumnDefinition visitColumnDef(ColumnDefContext ctx) {
} else if (ctx.nullValue != null) {
defaultValue = Optional.of(DefaultValue.NULL_DEFAULT_VALUE);
} else if (ctx.CURRENT_TIMESTAMP() != null) {
if (ctx.precision == null) {
if (ctx.precision1 == null) {
defaultValue = Optional.of(DefaultValue.CURRENT_TIMESTAMP_DEFAULT_VALUE);
} else {
defaultValue = Optional.of(DefaultValue
.currentTimeStampDefaultValueWithPrecision(Long.valueOf(ctx.precision.getText())));
.currentTimeStampDefaultValueWithPrecision(Long.valueOf(ctx.precision1.getText())));
}
}
}
if (ctx.UPDATE() != null) {
if (ctx.precision2 == null) {
onUpdateDefaultValue = Optional.of(DefaultValue.CURRENT_TIMESTAMP_DEFAULT_VALUE);
} else {
onUpdateDefaultValue = Optional.of(DefaultValue
.currentTimeStampDefaultValueWithPrecision(Long.valueOf(ctx.precision2.getText())));
}
}
AggregateType aggType = null;
if (aggTypeString != null) {
try {
Expand All @@ -1990,7 +1999,8 @@ public ColumnDefinition visitColumnDef(ColumnDefContext ctx) {
}
}
String comment = ctx.comment != null ? ctx.comment.getText() : "";
return new ColumnDefinition(colName, colType, isKey, aggType, !isNotNull, defaultValue, comment);
return new ColumnDefinition(colName, colType, isKey, aggType, !isNotNull, defaultValue,
onUpdateDefaultValue, comment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,21 @@ public List<Rule> buildRules() {
// If the current load is a partial update, the values of unmentioned
// columns will be filled in SegmentWriter. And the output of sink node
// should not contain these unmentioned columns, so we just skip them.
continue;
try {
if (column.hasOnUpdateDefaultValue()) {
Expression defualtValueExpression = FunctionBinder.INSTANCE.rewrite(
new NereidsParser().parseExpression(
column.getOnUpdateDefaultValueExpr().toSqlWithoutTbl()),
new ExpressionRewriteContext(ctx.cascadesContext));
columnToOutput.put(column.getName(),
new Alias(defualtValueExpression, column.getName()));
} else {
continue;
}

} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e.getCause());
}
} else if (column.getDefaultValue() == null) {
// Otherwise, the unmentioned columns should be filled with default values
// or null values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ColumnDefinition {
private AggregateType aggType;
private boolean isNullable;
private Optional<DefaultValue> defaultValue;
private Optional<DefaultValue> onUpdateDefaultValue = Optional.empty();
private final String comment;
private final boolean isVisible;
private boolean aggTypeImplicit = false;
Expand All @@ -60,6 +61,11 @@ public ColumnDefinition(String name, DataType type, boolean isKey, AggregateType
this(name, type, isKey, aggType, isNullable, defaultValue, comment, true);
}

public ColumnDefinition(String name, DataType type, boolean isKey, AggregateType aggType, boolean isNullable,
Optional<DefaultValue> defaultValue, Optional<DefaultValue> onUpdateDefaultValue, String comment) {
this(name, type, isKey, aggType, isNullable, defaultValue, onUpdateDefaultValue, comment, true);
}

/**
* constructor
*/
Expand All @@ -75,6 +81,23 @@ public ColumnDefinition(String name, DataType type, boolean isKey, AggregateType
this.isVisible = isVisible;
}

/**
* constructor
*/
public ColumnDefinition(String name, DataType type, boolean isKey, AggregateType aggType, boolean isNullable,
Optional<DefaultValue> defaultValue, Optional<DefaultValue> onUpdateDefaultValue, String comment,
boolean isVisible) {
this.name = name;
this.type = type;
this.isKey = isKey;
this.aggType = aggType;
this.isNullable = isNullable;
this.defaultValue = defaultValue;
this.onUpdateDefaultValue = onUpdateDefaultValue;
this.comment = comment;
this.isVisible = isVisible;
}

public ColumnDefinition(String name, DataType type, boolean isNullable) {
this(name, type, false, null, isNullable, Optional.empty(), "");
}
Expand Down Expand Up @@ -198,6 +221,16 @@ public void validate(Set<String> keysSet, boolean isEnableMergeOnWrite, KeysType
throw new AnalysisException(e.getMessage(), e);
}
}
if (onUpdateDefaultValue.isPresent()
&& onUpdateDefaultValue.get().getValue() != null
&& type.toCatalogDataType().isScalarType()) {
try {
ColumnDef.validateDefaultValue(type.toCatalogDataType(),
onUpdateDefaultValue.get().getValue(), onUpdateDefaultValue.get().getDefaultValueExprDef());
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e);
}
}
}

/**
Expand Down Expand Up @@ -231,7 +264,8 @@ public Column translateToCatalogStyle() {
Column column = new Column(name, type.toCatalogDataType(), isKey, aggType, isNullable,
false, defaultValue.map(DefaultValue::getRawValue).orElse(null), comment, isVisible,
defaultValue.map(DefaultValue::getDefaultValueExprDef).orElse(null), Column.COLUMN_UNIQUE_ID_INIT_VALUE,
defaultValue.map(DefaultValue::getValue).orElse(null));
defaultValue.map(DefaultValue::getValue).orElse(null), onUpdateDefaultValue.isPresent(),
onUpdateDefaultValue.map(DefaultValue::getDefaultValueExprDef).orElse(null));
column.setAggregationTypeImplicit(aggTypeImplicit);
return column;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,9 @@ public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpr
return new LogicalOlapTableSink<>(database, targetTable, cols, partitionIds, outputExprs, isPartialUpdate,
isFromNativeInsertStmt, groupExpression, logicalProperties, children.get(0));
}

public Plan withCols(List<Column> cols) {
return new LogicalOlapTableSink<>(database, targetTable, cols, partitionIds, outputExprs, isPartialUpdate,
isFromNativeInsertStmt, groupExpression, Optional.of(getLogicalProperties()), child());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
1 doris 1000 123 1 2020-01-01T00:00
2 doris2 2000 223 1 2020-01-01T00:00

-- !sql --
1 doris 1999 123 1 2023-10-25T15:23:51
2 doris2 2999 223 1 2023-10-25T15:23:51
3 unknown 3999 \N 4321 2023-10-25T15:23:51
4 unknown 4999 \N 4321 2023-10-25T15:23:51

-- !sql --
1 doris 1000 123 1 2023-10-25T15:23:51
2 doris2 2000 223 1 2023-10-25T15:23:51

-- !sql --
1 doris 1999 123 1 2023-10-25T15:23:52
2 doris2 2999 223 1 2023-10-25T15:23:52
3 unknown 3999 \N 4321 2023-10-25T15:23:52
4 unknown 4999 \N 4321 2023-10-25T15:23:52

Loading

0 comments on commit f18428c

Please sign in to comment.