From f4f962edca97885843a6d55b19949d17966b551b Mon Sep 17 00:00:00 2001 From: Matt Gara <570356+mattgara@users.noreply.github.com> Date: Mon, 5 Jul 2021 21:56:24 -0700 Subject: [PATCH] ODBC: fetch data in batches --- Catalog/ForeignTable.h | 4 +++- Tests/CreateAndDropTableDdlTest.cpp | 30 +++++++++++++++++++++++++++++ Tests/ForeignTableDmlTest.cpp | 13 +++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Catalog/ForeignTable.h b/Catalog/ForeignTable.h index d8ee0dd470..affabcab19 100644 --- a/Catalog/ForeignTable.h +++ b/Catalog/ForeignTable.h @@ -43,6 +43,7 @@ struct ForeignTable : public TableDescriptor, public OptionsContainer { static constexpr const char* REFRESH_START_DATE_TIME_KEY = "REFRESH_START_DATE_TIME"; static constexpr const char* REFRESH_INTERVAL_KEY = "REFRESH_INTERVAL"; static constexpr const char* REFRESH_UPDATE_TYPE_KEY = "REFRESH_UPDATE_TYPE"; + static constexpr const char* BUFFER_SIZE_KEY = "BUFFER_SIZE"; // Option values static constexpr const char* ALL_REFRESH_UPDATE_TYPE = "ALL"; static constexpr const char* APPEND_REFRESH_UPDATE_TYPE = "APPEND"; @@ -69,7 +70,8 @@ struct ForeignTable : public TableDescriptor, public OptionsContainer { inline static const std::set alterable_options{REFRESH_TIMING_TYPE_KEY, REFRESH_START_DATE_TIME_KEY, REFRESH_INTERVAL_KEY, - REFRESH_UPDATE_TYPE_KEY}; + REFRESH_UPDATE_TYPE_KEY, + BUFFER_SIZE_KEY}; /** @brief Verifies the values for mapped options are valid. diff --git a/Tests/CreateAndDropTableDdlTest.cpp b/Tests/CreateAndDropTableDdlTest.cpp index ee56290876..497119552b 100644 --- a/Tests/CreateAndDropTableDdlTest.cpp +++ b/Tests/CreateAndDropTableDdlTest.cpp @@ -1195,6 +1195,36 @@ class CreateForeignTableTest : public CreateAndDropTableDdlTest { dropTestUser(); CreateAndDropTableDdlTest::TearDown(); } + + void assertOptionEquals(const foreign_storage::ForeignTable* table, + const std::string& key, + const std::string& value) { + if (const auto& opt_it = table->options.find(key); opt_it != table->options.end()) { + ASSERT_EQ(opt_it->second, value); + } else { + FAIL() << "Expected value for option " << key; + } + } + + const foreign_storage::ForeignTable* getForeignTable( + const std::string& filename) const { + auto table = getCatalog().getMetadataForTable(filename, false); + CHECK(table); + auto foreign_table = dynamic_cast(table); + return foreign_table; + } + + std::unique_ptr getForeignTableFromStorage( + const std::string& filename) const { + return getCatalog().getForeignTableFromStorage(getForeignTable(filename)->tableId); + } + + // Asserts option is as expected for in-memory table then again in catalog storage. + void assertOptionEquals(const std::string& key, const std::string& value) { + assertOptionEquals(getForeignTable("test_foreign_table"), key, value); + assertOptionEquals( + getForeignTableFromStorage("test_foreign_table").get(), key, value); + } }; TEST_F(CreateForeignTableTest, NonExistentServer) { diff --git a/Tests/ForeignTableDmlTest.cpp b/Tests/ForeignTableDmlTest.cpp index 60599a083c..6a3eb1ec3c 100644 --- a/Tests/ForeignTableDmlTest.cpp +++ b/Tests/ForeignTableDmlTest.cpp @@ -4690,6 +4690,10 @@ class AlterForeignTableTest : public ScheduledRefreshTest { } query += ");"; sql(query); + populateForeignTable(); + } + + void populateForeignTable() { cat_ = &getCatalog(); auto table = getCatalog().getMetadataForTable("test_foreign_table", false); CHECK(table); @@ -4873,6 +4877,15 @@ TEST_F(AlterForeignTableTest, RefreshStartDateTimeScheduledInPastError) { assertOptionNotEquals("REFRESH_START_DATE_TIME", start_time); } +TEST_F(AlterForeignTableTest, CsvBufferSizeOption) { + sql("CREATE FOREIGN TABLE test_foreign_table (i INTEGER) SERVER omnisci_local_csv WITH " + "(file_path='" + + getDataFilesPath() + "/1.csv');"); + populateForeignTable(); + sql("ALTER FOREIGN TABLE test_foreign_table SET (BUFFER_SIZE = '4');"); + assertOptionEquals("BUFFER_SIZE", "4"); +} + // TODO(Misiu): Implement these skeleton tests for full alter foreign table support. TEST_F(AlterForeignTableTest, FilePath) { createScheduledTable("manual");