Skip to content

Commit

Permalink
read decimals from csv (#5983)
Browse files Browse the repository at this point in the history
  • Loading branch information
iddqdex authored Jun 26, 2024
1 parent 808e65b commit 2fc2f71
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ydb/core/formats/arrow/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<arrow::Array>& column, std::shared_ptr<arrow::Field>& 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<arrow::Type::type> jsonDocArrowTypes{ arrow::Type::BINARY, arrow::Type::STRING };
if (!jsonDocArrowTypes.contains(column->type()->id())) {
Expand Down
30 changes: 30 additions & 0 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TTestHelper::TColumnSchema> 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;
Expand Down

0 comments on commit 2fc2f71

Please sign in to comment.