DarkWanderer / ClickHouse.Client

.NET client for ClickHouse
MIT License
303 stars 58 forks source link

DataTable.Load fails with System.InvalidCastException exception #428

Closed i-sinister closed 5 months ago

i-sinister commented 5 months ago

DataTable.Load does not work, checked with 6.3 and 6.8.1:

        [Test]
        public async Task check_loading_results_into_DataTable()
        {
            var cancellationToken = CancellationToken.None;
            // using Testcontainers and Testcontainers.ClickHouse packages
            await using var clickhouseContainer = new ClickHouseBuilder()
                .WithImage("clickhouse/clickhouse-server:23.3-alpine")
                .Build();
            await clickhouseContainer.StartAsync(cancellationToken);
            using var connection = new ClickHouseConnection(clickhouseContainer.GetConnectionString());
            await connection.OpenAsync(cancellationToken);
            using var command = connection.CreateCommand();
            command.CommandText = "SELECT 1 as SOMEID FROM numbers(10)";
            await using var reader = await command.ExecuteReaderAsync(cancellationToken);
            var table = new DataTable();
            table.Load(reader);
        }

Expected: DataTable to be filled with the results of the query

Actual: test fails with following error

Message:  System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.Type'.

Stack Trace:  DbSchemaRow.get_DataType() SchemaMapping.SetupSchemaWithKeyInfo(MissingMappingAction mappingAction, MissingSchemaAction schemaAction, Boolean gettingData, DataColumn parentChapterColumn, Object chapterValue) SchemaMapping.ctor(DataAdapter adapter, DataSet dataset, DataTable datatable, DataReaderContainer dataReader, Boolean keyInfo, SchemaType schemaType, String sourceTableName, Boolean gettingData, DataColumn parentChapterColumn, Object parentChapterValue) DataAdapter.FillMappingInternal(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) DataAdapter.FillMapping(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 schemaCount, DataColumn parentChapterColumn, Object parentChapterValue) DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) DataTable.Load(IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler) DataTable.Load(IDataReader reader)

DarkWanderer commented 5 months ago

Hi. Thanks for reporting this - fix released in v7.0, please let me know if something doesn't work

i-sinister commented 5 months ago

Any chance to fix this issue for 6.x as well?