Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76a97d8

Browse files
Shylock-Hgyixinglu
andauthored
Fix the error which insert mismatched datetime type (vesoft-inc#2527)
* Fix the error which insert mismatched datetime type. * Add test cases. Co-authored-by: Yee <[email protected]>
1 parent 1213ce4 commit 76a97d8

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

src/codec/RowWriterV2.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,6 @@ WriteResult RowWriterV2::write(ssize_t index, const Date& v) noexcept {
691691
buf_[offset + sizeof(int16_t)] = v.month;
692692
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = v.day;
693693
break;
694-
case meta::cpp2::PropertyType::DATETIME:
695-
memcpy(&buf_[offset], reinterpret_cast<const void*>(&v.year), sizeof(int16_t));
696-
buf_[offset + sizeof(int16_t)] = v.month;
697-
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = v.day;
698-
memset(&buf_[offset + sizeof(int16_t) + 2 * sizeof(int8_t)],
699-
0,
700-
3 * sizeof(int8_t) + 2 * sizeof(int32_t));
701-
break;
702694
default:
703695
return WriteResult::TYPE_MISMATCH;
704696
}
@@ -742,11 +734,6 @@ WriteResult RowWriterV2::write(ssize_t index, const DateTime& v) noexcept {
742734
int8_t sec = v.sec;
743735
int32_t microsec = v.microsec;
744736
switch (field->type()) {
745-
case meta::cpp2::PropertyType::DATE:
746-
memcpy(&buf_[offset], reinterpret_cast<const void*>(&year), sizeof(int16_t));
747-
buf_[offset + sizeof(int16_t)] = month;
748-
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = day;
749-
break;
750737
case meta::cpp2::PropertyType::DATETIME:
751738
memcpy(&buf_[offset], reinterpret_cast<const void*>(&year), sizeof(int16_t));
752739
buf_[offset + sizeof(int16_t)] = month;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2021 vesoft inc. All rights reserved.
2+
#
3+
# This source code is licensed under Apache 2.0 License,
4+
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
5+
Feature: Datetime insert mismatched type
6+
7+
# issue https://github.com/vesoft-inc/nebula-graph/issues/1318
8+
Scenario: DateTime insert mismatched type
9+
Given an empty graph
10+
And create a space with following options:
11+
| partition_num | 9 |
12+
| replica_factor | 1 |
13+
| vid_type | FIXED_STRING(30) |
14+
| charset | utf8 |
15+
| collate | utf8_bin |
16+
When executing query:
17+
"""
18+
create tag ddl_tag1(col1 date default date("2017-03-04"),
19+
col2 datetime default datetime("2017-03-04T00:00:01"),
20+
col3 time default time("11:11:11"));
21+
"""
22+
Then the execution should be successful
23+
When try to execute query:
24+
"""
25+
INSERT VERTEX ddl_tag1() VALUES 'test':()
26+
"""
27+
Then the execution should be successful
28+
When executing query:
29+
"""
30+
INSERT VERTEX ddl_tag1(col1, col2, col3) VALUES 'test':(date("2019-01-02"), date('2019-01-02'), time('11:11:11'))
31+
"""
32+
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
33+
When executing query:
34+
"""
35+
INSERT VERTEX ddl_tag1(col1, col2, col3) VALUES 'test':(datetime("2019-01-02T00:00:00"), datetime('2019-01-02T00:00:00'), time('11:11:11'))
36+
"""
37+
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
38+
When executing query:
39+
"""
40+
INSERT VERTEX ddl_tag1(col1, col2, col3) VALUES 'test':(date("2019-01-02"), datetime('2019-01-02T00:00:00'), datetime('2019-01-02T11:11:11'))
41+
"""
42+
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
43+
Then drop the used space

tests/tck/features/bugfix/TimeDefaultValue.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Copyright (c) 2021 vesoft inc. All rights reserved.
2+
#
3+
# This source code is licensed under Apache 2.0 License,
4+
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
15
Feature: Datetime default value
26

37
Scenario: DateTime Default Value

0 commit comments

Comments
 (0)