Skip to content

[WIP] [feature](timestamp) support timestamp data type#41760

Closed
justfortaste wants to merge 22 commits intoapache:masterfrom
justfortaste:feature_timestamp
Closed

[WIP] [feature](timestamp) support timestamp data type#41760
justfortaste wants to merge 22 commits intoapache:masterfrom
justfortaste:feature_timestamp

Conversation

@justfortaste
Copy link
Copy Markdown
Contributor

@justfortaste justfortaste commented Oct 12, 2024

Proposed changes

Issue Number: close #xxx

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1(id int, t timestamp)ENGINE=OLAP
    ->             UNIQUE KEY(id)
    ->             DISTRIBUTED BY HASH(id) BUCKETS 2 
    ->             properties(
    ->                 "replication_num" = "1",
    ->                 "enable_unique_key_merge_on_write" = "true",
    ->                 "disable_auto_compaction" = "true");
Query OK, 0 rows affected (0.05 sec)

mysql> 
mysql> set time_zone="+8:00";
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values(1, '2020-01-01 10:00:00');

Query OK, 1 row affected (1.31 sec)
{'label':'label_153fb3e333924a87_be864385a5c9e63b', 'status':'VISIBLE', 'txnId':'62060'}

mysql> select * from t1;
+------+---------------------+
| id   | t                   |
+------+---------------------+
|    1 | 2020-01-01 10:00:00 |
+------+---------------------+
1 row in set (16.54 sec)

mysql> set time_zone="+10:00";
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values(2, '2020-01-01 10:00:00');
Query OK, 1 row affected (0.06 sec)
{'label':'label_debe49b6d6e345e6_a890671ace1a437e', 'status':'VISIBLE', 'txnId':'62061'}

mysql> select * from t1;
+------+---------------------+
| id   | t                   |
+------+---------------------+
|    1 | 2020-01-01 12:00:00 |
|    2 | 2020-01-01 10:00:00 |
+------+---------------------+
2 rows in set (0.04 sec)

mysql> 
mysql> set time_zone="+8:00";
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1;
+------+---------------------+
| id   | t                   |
+------+---------------------+
|    1 | 2020-01-01 10:00:00 |
|    2 | 2020-01-01 08:00:00 |
+------+---------------------+
2 rows in set (0.03 sec)

todo:

create table t1(id int, t timestamp)ENGINE=OLAP
            UNIQUE KEY(k)
            DISTRIBUTED BY HASH(id) BUCKETS 2
            properties(
                "replication_num" = "1",
                "enable_unique_key_merge_on_write" = "true",
                "disable_auto_compaction" = "true");
ERROR 1105 (HY000): errCode = 2, detailMessage = Nereids do not support type: timestamp
ERROR 1109 (42S02): errCode = 2, detailMessage = errCode = 2, detailMessage = Unknown table 't2' in test
MySQL [test]> create table t2(t timestamp, id int)ENGINE=OLAP
    ->             UNIQUE KEY(t)
    ->             DISTRIBUTED BY HASH(t) BUCKETS 2
    ->             properties(
    ->                 "replication_num" = "1",
    ->                 "enable_unique_key_merge_on_write" = "true",
    ->                 "disable_auto_compaction" = "true");
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> insert into t2 values('2020-01-01 10:00:00',1);
Query OK, 1 row affected (0.06 sec)
{'label':'label_1946a1a147b84131_b1e0100d5679ef25', 'status':'VISIBLE', 'txnId':'3'}

MySQL [test]> insert into t2 values('2025-01-01 11:11:11',2);
Query OK, 1 row affected (0.05 sec)
{'label':'label_d231330c9b1a4b06_9cf94bcc8c440c81', 'status':'VISIBLE', 'txnId':'4'}

MySQL [test]> select * from t2;
+---------------------+------+
| t                   | id   |
+---------------------+------+
| 2020-01-01 10:00:00 |    1 |
| 2025-01-01 11:11:11 |    2 |
+---------------------+------+
2 rows in set (0.03 sec)
todo:
MySQL [test]> create table t2(t timestamp, id int)ENGINE=OLAP
    ->             UNIQUE KEY(t)
    ->             DISTRIBUTED BY HASH(t) BUCKETS 2
    ->             properties(
    ->                 "replication_num" = "1",
    ->                 "enable_unique_key_merge_on_write" = "true",
    ->                 "disable_auto_compaction" = "true");
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> insert into t2 values('2020-01-01 10:00:00',1);
ERROR 1105 (HY000): errCode = 2, detailMessage = unknown date like type
todo:
ERROR 1105 (HY000): send fragments failed. io.grpc.StatusRuntimeException: UNAVAILABLE: Network closed for unknown reason, host: 127.0.0.1

 7# google::LogMessageFatal::~LogMessageFatal() in /data/ayuanzhang/mydoris/output/be/lib/doris_be
 8# doris::thrift_to_type(doris::TPrimitiveType::type) in /data/ayuanzhang/mydoris/output/be/lib/doris_be
 9# doris::TypeDescriptor::TypeDescriptor(std::vector<doris::TTypeNode, std::allocator<doris::TTypeNode> > const&, int*) in /data/ayuanzhang/mydoris/output/be/lib/doris_be
10# doris::TypeDescriptor::from_thrift(doris::TTypeDesc const&) at /data/ayuanzhang/mydoris/be/src/runtime/types.h:149
11# doris::SlotDescriptor::SlotDescriptor(doris::TSlotDescriptor const&) at /data/ayuanzhang/mydoris/be/src/runtime/descriptors.cpp:46
12# doris::DescriptorTbl::create(doris::ObjectPool*, doris::TDescriptorTable const&, doris::DescriptorTbl**) in /data/ayuanzhang/mydoris/output/be/lib/doris_be
mysql> set time_zone="+8:00";
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values(1, '2020-01-01 10:00:00');
Query OK, 1 row affected (0.22 sec)
{'label':'label_5961c3a91f6f406e_ad316bfcc1d66eaa', 'status':'VISIBLE', 'txnId':'30028'}

mysql> set time_zone="+10:00";
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values(2, '2020-01-01 10:00:00');
Query OK, 1 row affected (0.06 sec)
{'label':'label_684e9fee3de24054_a6fd582a5fce6440', 'status':'VISIBLE', 'txnId':'30029'}

mysql> select * from t1;
+------+---------------------+
| id   | t                   |
+------+---------------------+
|    1 | 2020-01-01 10:00:00 |
|    2 | 2020-01-01 12:00:00 |
+------+---------------------+
2 rows in set (0.04 sec)
    ->             UNIQUE KEY(id)
    ->             DISTRIBUTED BY HASH(id) BUCKETS 2
    ->             properties(
    ->                 "replication_num" = "1",
    ->                 "enable_unique_key_merge_on_write" = "true",
    ->                 "disable_auto_compaction" = "true");
Query OK, 0 rows affected (0.01 sec)

mysql> set time_zone="+8:00";
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 values(1, '2020-01-01 10:00:00');
Query OK, 1 row affected (0.07 sec)
{'label':'label_57f023e840c49ef_87835e9756a210fc', 'status':'VISIBLE', 'txnId':'42043'}

mysql> select * from t1;
+------+---------------------+
| id   | t                   |
+------+---------------------+
|    1 | 2020-01-01 11:00:00 |
+------+---------------------+
1 row in set (0.04 sec)

todo:
PGenericType::DATETIMEV2
PColumnType::COLUMN_TYPE_TIMESTAMP
@doris-robot
Copy link
Copy Markdown

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

std::vector<RowwiseIteratorUPtr>* out_iters,
bool use_cache = false) override;

long tz_offset() { return _tz_offset; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'tz_offset' can be made const [readability-make-member-function-const]

Suggested change
long tz_offset() { return _tz_offset; }
long tz_offset() const { return _tz_offset; }


void insert_many_binary_data(char* data_array, uint32_t* len_array,
uint32_t* start_offset_array, size_t num) override {
uint32_t* start_offset_array, size_t num,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pointer parameter 'start_offset_array' can be pointer to const [readability-non-const-parameter]

Suggested change
uint32_t* start_offset_array, size_t num,
const uint32_t* start_offset_array, size_t num,


void insert_many_binary_data(char* data_array, uint32_t* len_array,
uint32_t* start_offset_array, size_t num) override {
uint32_t* start_offset_array, size_t num,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: pointer parameter 'start_offset_array' can be pointer to const [readability-non-const-parameter]

Suggested change
uint32_t* start_offset_array, size_t num,
const uint32_t* start_offset_array, size_t num,

static constexpr bool is_parametric = true;

DataTypeDateTimeV2(UInt32 scale = 0) : _scale(scale) {
DataTypeDateTimeV2(UInt32 scale = 0, bool is_timestamp = 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]

Suggested change
DataTypeDateTimeV2(UInt32 scale = 0, bool is_timestamp = 0)
DataTypeDateTimeV2(UInt32 scale = 0, bool is_timestamp = false)

};

DataTypePtr create_datetimev2(UInt64 scale);
DataTypePtr create_datetimev2(UInt64 scale, bool is_timestamp = 0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]

Suggested change
DataTypePtr create_datetimev2(UInt64 scale, bool is_timestamp = 0);
DataTypePtr create_datetimev2(UInt64 scale, bool is_timestamp = false);


OlapBlockDataConvertor::OlapColumnDataConvertorBaseUPtr
OlapBlockDataConvertor::create_olap_column_data_convertor(const TabletColumn& column) {
OlapBlockDataConvertor::create_olap_column_data_convertor(const TabletColumn& column,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'create_olap_column_data_convertor' exceeds recommended size/complexity thresholds [readability-function-size]

OlapBlockDataConvertor::create_olap_column_data_convertor(const TabletColumn& column,
                        ^
Additional context

be/src/vec/olap/olap_data_convertor.cpp:115: 108 lines including whitespace and comments (threshold 80)

OlapBlockDataConvertor::create_olap_column_data_convertor(const TabletColumn& column,
                        ^

union DateTimeV2UInt64Union {
DateV2Value<DateTimeV2ValueType> dt;
uint64_t ui64;
~DateTimeV2UInt64Union() {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use '= default' to define a trivial destructor [modernize-use-equals-default]

Suggested change
~DateTimeV2UInt64Union() {}
~DateTimeV2UInt64Union() = default;

union DateTimeV2UInt64Union {
DateV2Value<DateTimeV2ValueType> dt;
uint64_t ui64;
~DateTimeV2UInt64Union() {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use '= default' to define a trivial destructor [modernize-use-equals-default]

Suggested change
~DateTimeV2UInt64Union() {}
~DateTimeV2UInt64Union() = default;

@github-actions
Copy link
Copy Markdown
Contributor

We're closing this PR because it hasn't been updated in a while.
This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and feel free a maintainer to remove the Stale tag!

@github-actions github-actions bot added the Stale label Apr 11, 2025
@github-actions github-actions bot closed this Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants