Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit 15046f0

Browse files
Devjiuienkovich
authored andcommitted
[Null schema] Support emty data table.
This commit supports empty table. Used default table schema, so has_nulls is false in this case, min/max are default. Resolves: #393 Signed-off-by: Dmitrii Makarenko <[email protected]>
1 parent 1006e9b commit 15046f0

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

omniscidb/ArrowStorage/ArrowStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ ChunkStats ArrowStorage::computeStats(std::shared_ptr<arrow::ChunkedArray> arr,
926926
chunk->data()->GetValues<int8_t>(1, chunk->data()->offset * elem_type->size()),
927927
chunk->length(),
928928
true);
929-
} else {
929+
} else if (chunk->length() != 0) {
930930
encoder->updateStatsEncoded(
931931
chunk->data()->GetValues<int8_t>(1, chunk->data()->offset * elem_type->size()),
932932
chunk->length());

omniscidb/Tests/ArrowStorageTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,21 @@ TEST_F(ArrowStorageTest, CreateTable_WrongDictId) {
721721
ASSERT_THROW(storage.createTable("table1", {{"col1", type}}), std::runtime_error);
722722
}
723723

724+
TEST_F(ArrowStorageTest, ImportArrowTable) {
725+
ArrowStorage storage(TEST_SCHEMA_ID, "test", TEST_DB_ID);
726+
auto col_a = std::make_shared<arrow::Field>("A", arrow::null());
727+
auto schema = arrow::schema({col_a});
728+
729+
std::shared_ptr<arrow::Array> empty_array;
730+
arrow::NumericBuilder<arrow::FloatType> float64_builder;
731+
float64_builder.AppendValues({});
732+
float64_builder.Finish(&empty_array);
733+
auto table = arrow::Table::Make(schema, {empty_array});
734+
ASSERT_NO_THROW(
735+
storage.importArrowTable(table, "test_empty", ArrowStorage::TableOptions{1}));
736+
storage.dropTable("test_empty");
737+
}
738+
724739
TEST_F(ArrowStorageTest, DropTable) {
725740
ArrowStorage storage(TEST_SCHEMA_ID, "test", TEST_DB_ID);
726741
auto tinfo = storage.createTable("table1",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright 2023 Intel Corporation.
5+
#
6+
# SPDX-License-Identifier: Apache-2.0
7+
8+
import pytest
9+
import pyhdk
10+
import pyarrow
11+
12+
13+
class TestImport:
14+
def test_null_schema(self):
15+
table = pyarrow.table(
16+
[[]], schema=pyarrow.schema([pyarrow.field("A", pyarrow.null())])
17+
)
18+
opt = pyhdk.storage.TableOptions(2)
19+
hdk = pyhdk.init()
20+
ht = hdk.import_arrow(table)
21+
hdk.drop_table(ht)

0 commit comments

Comments
 (0)