Skip to content

Commit

Permalink
Update DuckDB to latest (#23)
Browse files Browse the repository at this point in the history
Summary:
Pick up improvements to complex type support (lists and structs). It should be possible now to create and query tables with columns of type list or struct.

allow-large-files

Pull Request resolved: #23

Reviewed By: kgpai

Differential Revision: D30256242

Pulled By: mbasmanova

fbshipit-source-id: ac2579f2cc77fdc94050a41b91f2c4a630ce55f1
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Aug 11, 2021
1 parent 894d7de commit f2f35c4
Show file tree
Hide file tree
Showing 14 changed files with 111,654 additions and 95,201 deletions.
3 changes: 2 additions & 1 deletion velox/duckdb/conversion/DuckConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ struct DuckDateConversion {
return ::duckdb::Timestamp::GetDate(veloxTimestampToDuckDB(input));
}
static Timestamp toVelox(const ::duckdb::date_t& input) {
return duckdbTimestampToVelox(::duckdb::Timestamp::FromDatetime(input, 0));
return duckdbTimestampToVelox(
::duckdb::Timestamp::FromDatetime(input, ::duckdb::dtime_t(0)));
}
};

Expand Down
19 changes: 19 additions & 0 deletions velox/duckdb/conversion/DuckParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace facebook::velox::duckdb {

using ::duckdb::BetweenExpression;
using ::duckdb::CaseExpression;
using ::duckdb::CastExpression;
using ::duckdb::ColumnRefExpression;
Expand Down Expand Up @@ -149,6 +150,21 @@ std::shared_ptr<const core::IExpr> parseComparisonExpr(ParsedExpression& expr) {
std::move(params));
}

// Parse x between lower and upper
std::shared_ptr<const core::IExpr> parseBetweenExpr(ParsedExpression& expr) {
const auto& betweenExpr = dynamic_cast<BetweenExpression&>(expr);
return callExpr(
"and",
{
callExpr(
"gte",
{parseExpr(*betweenExpr.input), parseExpr(*betweenExpr.lower)}),
callExpr(
"lte",
{parseExpr(*betweenExpr.input), parseExpr(*betweenExpr.upper)}),
});
}

// Parse a conjunction (AND or OR).
std::shared_ptr<const core::IExpr> parseConjunctionExpr(
ParsedExpression& expr) {
Expand Down Expand Up @@ -289,6 +305,9 @@ std::shared_ptr<const core::IExpr> parseExpr(ParsedExpression& expr) {
case ExpressionClass::COMPARISON:
return parseComparisonExpr(expr);

case ExpressionClass::BETWEEN:
return parseBetweenExpr(expr);

case ExpressionClass::CONJUNCTION:
return parseConjunctionExpr(expr);

Expand Down
11 changes: 7 additions & 4 deletions velox/duckdb/conversion/DuckWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,22 @@ VectorPtr toVeloxVector(
return convert<DuckNumericConversion<double>>(
duckVector, veloxType, size, pool);
case LogicalTypeId::DECIMAL: {
uint8_t width;
uint8_t scale;
type.GetDecimalProperties(width, scale);
switch (type.InternalType()) {
case PhysicalType::INT16:
return convertDecimalToDouble<int16_t>(
duckVector, size, veloxType, pool, type.scale());
duckVector, size, veloxType, pool, scale);
case PhysicalType::INT32:
return convertDecimalToDouble<int32_t>(
duckVector, size, veloxType, pool, type.scale());
duckVector, size, veloxType, pool, scale);
case PhysicalType::INT64:
return convertDecimalToDouble<int64_t>(
duckVector, size, veloxType, pool, type.scale());
duckVector, size, veloxType, pool, scale);
case PhysicalType::INT128:
return convertDecimalToDouble<hugeint_t>(
duckVector, size, veloxType, pool, type.scale());
duckVector, size, veloxType, pool, scale);
default:
throw std::runtime_error(
"unrecognized internal type for decimal (this shouldn't happen");
Expand Down
12 changes: 5 additions & 7 deletions velox/duckdb/conversion/tests/DuckConversionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ TEST(DuckConversionTest, duckValueToVariant) {
}

TEST(DuckConversionTest, duckValueToVariantUnsupported) {
auto unsupported = {
LogicalType::TIME,
std::vector<LogicalType> unsupported = {
LogicalType::TIME,
LogicalType::TIMESTAMP,
LogicalType::INTERVAL,

LogicalType::STRUCT,
LogicalType::LIST,
LogicalType::BLOB,
};
LogicalType::LIST({LogicalType::INTEGER}),
LogicalType::STRUCT(
{{"a", LogicalType::INTEGER}, {"b", LogicalType::TINYINT}}),
LogicalType::BLOB};

for (const auto& i : unsupported) {
EXPECT_THROW(duckValueToVariant(Value(i)), std::runtime_error);
Expand Down
2 changes: 1 addition & 1 deletion velox/duckdb/functions/DuckFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ struct DuckDBFunctionData {
std::vector<LogicalType> inputTypes;
// dummy stuff, necessary to call the function but not actually used
BoundConstantExpression expr;
ExpressionExecutorState executor_state;
ExpressionExecutorState executor_state{"N/A"};
ExpressionState state;
};

Expand Down
2 changes: 1 addition & 1 deletion velox/exec/tests/QueryAssertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ velox::variant rowVariantAt(
const std::shared_ptr<const Type>& rowType) {
std::vector<velox::variant> values;
for (size_t i = 0; i < vector.struct_value.size(); ++i) {
auto currChild = vector.struct_value[i].second;
auto currChild = vector.struct_value[i];
auto currType = rowType->childAt(i)->kind();
if (currChild.is_null) {
values.push_back(variant(currType));
Expand Down
Loading

0 comments on commit f2f35c4

Please sign in to comment.