Skip to content

Commit

Permalink
Merge pull request #41 from chdb-io/40-segfault-on-handled-exceptions
Browse files Browse the repository at this point in the history
Fix empty buffer or memoryview handling
  • Loading branch information
auxten authored Jun 15, 2023
2 parents b4ee80b + 9f59081 commit beb5abc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def to_arrowTable(res):
print(f'ImportError: {e}')
print('Please install pyarrow and pandas via "pip install pyarrow pandas"')
raise ImportError('Failed to import pyarrow or pandas') from None

if len(res.get_memview()) == 0:
return pa.Table.from_batches([], schema=pa.schema([]))
return pa.RecordBatchFileReader(res.get_memview()).read_all()


Expand Down
6 changes: 6 additions & 0 deletions programs/local/LocalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace DB
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
extern const int UNKNOWN_FORMAT;
extern const int CANNOT_LOAD_CONFIG;
extern const int FILE_ALREADY_EXISTS;
}
Expand Down Expand Up @@ -557,6 +558,11 @@ void LocalServer::processConfig()
global_context->setMacros(std::make_unique<Macros>(config(), "macros", log));

format = config().getString("output-format", config().getString("format", is_interactive ? "PrettyCompact" : "TSV"));

/// Check format is supported before the engine runs too far
if (!FormatFactory::instance().isOutputFormat(format))
throw Exception(ErrorCodes::UNKNOWN_FORMAT, "Unknown output format {}", format);

insert_format = "Values";

/// Setting value from cmd arg overrides one from config
Expand Down

0 comments on commit beb5abc

Please sign in to comment.