From 76a97d81d836527f5936efe068a146d6edeed65f Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 17 Aug 2021 19:25:32 +0800 Subject: [PATCH] Fix the error which insert mismatched datetime type (#2527) * Fix the error which insert mismatched datetime type. * Add test cases. Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com> --- src/codec/RowWriterV2.cpp | 13 ------ .../InsertMismatchedTypeDateTime.feature | 43 +++++++++++++++++++ .../features/bugfix/TimeDefaultValue.feature | 4 ++ 3 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 tests/tck/features/bugfix/InsertMismatchedTypeDateTime.feature diff --git a/src/codec/RowWriterV2.cpp b/src/codec/RowWriterV2.cpp index 7662c6fd325..9b3723284fe 100644 --- a/src/codec/RowWriterV2.cpp +++ b/src/codec/RowWriterV2.cpp @@ -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(&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; } @@ -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(&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(&year), sizeof(int16_t)); buf_[offset + sizeof(int16_t)] = month; diff --git a/tests/tck/features/bugfix/InsertMismatchedTypeDateTime.feature b/tests/tck/features/bugfix/InsertMismatchedTypeDateTime.feature new file mode 100644 index 00000000000..de26057125e --- /dev/null +++ b/tests/tck/features/bugfix/InsertMismatchedTypeDateTime.feature @@ -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 diff --git a/tests/tck/features/bugfix/TimeDefaultValue.feature b/tests/tck/features/bugfix/TimeDefaultValue.feature index a12482e046c..a1d6187568a 100644 --- a/tests/tck/features/bugfix/TimeDefaultValue.feature +++ b/tests/tck/features/bugfix/TimeDefaultValue.feature @@ -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