Skip to content

Commit

Permalink
Fix the error which insert mismatched datetime type (#2527)
Browse files Browse the repository at this point in the history
* Fix the error which insert mismatched datetime type.

* Add test cases.

Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and yixinglu authored Aug 17, 2021
1 parent 1213ce4 commit 76a97d8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/codec/RowWriterV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,6 @@ WriteResult RowWriterV2::write(ssize_t index, const Date& v) noexcept {
buf_[offset + sizeof(int16_t)] = v.month;
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = v.day;
break;
case meta::cpp2::PropertyType::DATETIME:
memcpy(&buf_[offset], reinterpret_cast<const void*>(&v.year), sizeof(int16_t));
buf_[offset + sizeof(int16_t)] = v.month;
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = v.day;
memset(&buf_[offset + sizeof(int16_t) + 2 * sizeof(int8_t)],
0,
3 * sizeof(int8_t) + 2 * sizeof(int32_t));
break;
default:
return WriteResult::TYPE_MISMATCH;
}
Expand Down Expand Up @@ -742,11 +734,6 @@ WriteResult RowWriterV2::write(ssize_t index, const DateTime& v) noexcept {
int8_t sec = v.sec;
int32_t microsec = v.microsec;
switch (field->type()) {
case meta::cpp2::PropertyType::DATE:
memcpy(&buf_[offset], reinterpret_cast<const void*>(&year), sizeof(int16_t));
buf_[offset + sizeof(int16_t)] = month;
buf_[offset + sizeof(int16_t) + sizeof(int8_t)] = day;
break;
case meta::cpp2::PropertyType::DATETIME:
memcpy(&buf_[offset], reinterpret_cast<const void*>(&year), sizeof(int16_t));
buf_[offset + sizeof(int16_t)] = month;
Expand Down
43 changes: 43 additions & 0 deletions tests/tck/features/bugfix/InsertMismatchedTypeDateTime.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Datetime insert mismatched type

# issue https://github.com/vesoft-inc/nebula-graph/issues/1318
Scenario: DateTime insert mismatched type
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | FIXED_STRING(30) |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
create tag ddl_tag1(col1 date default date("2017-03-04"),
col2 datetime default datetime("2017-03-04T00:00:01"),
col3 time default time("11:11:11"));
"""
Then the execution should be successful
When try to execute query:
"""
INSERT VERTEX ddl_tag1() VALUES 'test':()
"""
Then the execution should be successful
When executing query:
"""
INSERT VERTEX ddl_tag1(col1, col2, col3) VALUES 'test':(date("2019-01-02"), date('2019-01-02'), time('11:11:11'))
"""
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
When executing query:
"""
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'))
"""
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
When executing query:
"""
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'))
"""
Then a ExecutionError should be raised at runtime: Storage Error: The data type does not meet the requirements. Use the correct type of data.
Then drop the used space
4 changes: 4 additions & 0 deletions tests/tck/features/bugfix/TimeDefaultValue.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Datetime default value

Scenario: DateTime Default Value
Expand Down

0 comments on commit 76a97d8

Please sign in to comment.