Skip to content

Commit beb5abc

Browse files
authored
Merge pull request #41 from chdb-io/40-segfault-on-handled-exceptions
Fix empty buffer or memoryview handling
2 parents b4ee80b + 9f59081 commit beb5abc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

chdb/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def to_arrowTable(res):
3535
print(f'ImportError: {e}')
3636
print('Please install pyarrow and pandas via "pip install pyarrow pandas"')
3737
raise ImportError('Failed to import pyarrow or pandas') from None
38-
38+
if len(res.get_memview()) == 0:
39+
return pa.Table.from_batches([], schema=pa.schema([]))
3940
return pa.RecordBatchFileReader(res.get_memview()).read_all()
4041

4142

programs/local/LocalServer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace DB
6161
namespace ErrorCodes
6262
{
6363
extern const int BAD_ARGUMENTS;
64+
extern const int UNKNOWN_FORMAT;
6465
extern const int CANNOT_LOAD_CONFIG;
6566
extern const int FILE_ALREADY_EXISTS;
6667
}
@@ -557,6 +558,11 @@ void LocalServer::processConfig()
557558
global_context->setMacros(std::make_unique<Macros>(config(), "macros", log));
558559

559560
format = config().getString("output-format", config().getString("format", is_interactive ? "PrettyCompact" : "TSV"));
561+
562+
/// Check format is supported before the engine runs too far
563+
if (!FormatFactory::instance().isOutputFormat(format))
564+
throw Exception(ErrorCodes::UNKNOWN_FORMAT, "Unknown output format {}", format);
565+
560566
insert_format = "Values";
561567

562568
/// Setting value from cmd arg overrides one from config

0 commit comments

Comments
 (0)