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

Fix the error which insert mismatched datetime type. #2527

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
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