From 2fc2f7123d60bce4824a1e3f65ad88b23a0794ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3?= <150132506+iddqdex@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:28:29 +0300 Subject: [PATCH] read decimals from csv (#5983) --- ydb/core/formats/arrow/converter.cpp | 2 +- ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ydb/core/formats/arrow/converter.cpp b/ydb/core/formats/arrow/converter.cpp index da851281f72b..1bd0c92e2ceb 100644 --- a/ydb/core/formats/arrow/converter.cpp +++ b/ydb/core/formats/arrow/converter.cpp @@ -48,7 +48,7 @@ static bool ConvertData(TCell& cell, const NScheme::TTypeInfo& colType, TMemoryP static arrow::Status ConvertColumn(const NScheme::TTypeInfo colType, std::shared_ptr& column, std::shared_ptr& field) { switch (colType.GetTypeId()) { case NScheme::NTypeIds::Decimal: - return arrow::Status::TypeError("Cannot convert Decimal type"); + return arrow::Status::OK(); case NScheme::NTypeIds::JsonDocument: { const static TSet jsonDocArrowTypes{ arrow::Type::BINARY, arrow::Type::STRING }; if (!jsonDocArrowTypes.contains(column->type()->id())) { diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index 75c1fe2d628d..ebf24af8bbda 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -7055,6 +7055,36 @@ Y_UNIT_TEST_SUITE(KqpOlapTypes) { testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id > 5 ORDER BY dec", "[[\"-inf\"];[\"1.1\"];[\"2.1\"];[\"12.1\"];[\"15.1\"];[\"inf\"]]"); } + Y_UNIT_TEST(DecimalCsv) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + + TTestHelper testHelper(runnerSettings); + + TVector schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int64).SetNullable(false), + TTestHelper::TColumnSchema().SetName("dec").SetType(NScheme::NTypeIds::Decimal).SetNullable(false), + }; + + TTestHelper::TColumnTable testTable; + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id", "dec"}).SetSharding({"id", "dec"}).SetSchema(schema); + testHelper.CreateTable(testTable); + + { + TStringBuilder builder; + builder << "1, 10.1" << Endl; + builder << "6, 1.1" << Endl; + builder << "7, 12.1" << Endl; + builder << "10, 2" << Endl; + builder << "11, 15.1" << Endl; + const auto result = testHelper.GetKikimr().GetTableClient().BulkUpsert(testTable.GetName(), EDataFormat::CSV, builder).GetValueSync(); + UNIT_ASSERT_C(result.IsSuccess() , result.GetIssues().ToString()); + } + testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id=1", "[[\"10.1\"]]"); + testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"10.1\" As Decimal(22,9))", "[[1]]"); + testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id > 5 ORDER BY dec", "[[\"1.1\"];[\"2\"];[\"12.1\"];[\"15.1\"]]"); + } + Y_UNIT_TEST(TimestampCmpErr) { TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false;