Skip to content

Commit 611d92b

Browse files
authored
feat: Return not implemented errors instead of internal errors (#153)
1 parent e171424 commit 611d92b

File tree

2 files changed

+222
-12
lines changed

2 files changed

+222
-12
lines changed

src/from_substrait.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Value TransformLiteralToValue(const substrait::Expression_Literal &literal) {
137137
case PhysicalType::INT128:
138138
return Value::DECIMAL(substrait_value, substrait_decimal.precision(), substrait_decimal.scale());
139139
default:
140-
throw InternalException("Not accepted internal type for decimal");
140+
throw NotImplementedException("Unsupported internal type for decimal: %s", decimal_type.ToString());
141141
}
142142
}
143143
case substrait::Expression_Literal::LiteralTypeCase::kBoolean: {
@@ -174,7 +174,8 @@ Value TransformLiteralToValue(const substrait::Expression_Literal &literal) {
174174
case substrait::Expression_Literal::LiteralTypeCase::kVarChar:
175175
return {literal.var_char().value()};
176176
default:
177-
throw SyntaxException("literals of this type number are not implemented: " + to_string(literal.literal_type_case()));
177+
throw NotImplementedException("literals of this type are not implemented: %s",
178+
substrait::Expression_Literal::GetDescriptor()->FindFieldByNumber(literal.literal_type_case())->name());
178179
}
179180
}
180181

@@ -184,7 +185,7 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformLiteralExpr(const subst
184185

185186
unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformSelectionExpr(const substrait::Expression &sexpr) {
186187
if (!sexpr.selection().has_direct_reference() || !sexpr.selection().direct_reference().has_struct_field()) {
187-
throw InternalException("Can only have direct struct references in selections");
188+
throw SyntaxException("Can only have direct struct references in selections");
188189
}
189190
return make_uniq<PositionalReferenceExpression>(sexpr.selection().direct_reference().struct_field().field() + 1);
190191
}
@@ -322,7 +323,8 @@ LogicalType SubstraitToDuckDB::SubstraitToDuckType(const substrait::Type &s_type
322323
case substrait::Type::KindCase::kFp64:
323324
return {LogicalTypeId::DOUBLE};
324325
default:
325-
throw NotImplementedException("Substrait type not yet supported");
326+
throw NotImplementedException("Substrait type not yet supported: %s",
327+
substrait::Type::GetDescriptor()->FindFieldByNumber(s_type.kind_case())->name());
326328
}
327329
}
328330

@@ -408,13 +410,15 @@ unique_ptr<ParsedExpression> SubstraitToDuckDB::TransformExpr(const substrait::E
408410
return TransformNested(sexpr, iterator);
409411
case substrait::Expression::RexTypeCase::kSubquery:
410412
default:
411-
throw InternalException("Unsupported expression type " + to_string(sexpr.rex_type_case()));
413+
throw NotImplementedException("Unsupported expression type %s",
414+
substrait::Expression::GetDescriptor()->FindFieldByNumber(sexpr.rex_type_case())->name());
412415
}
413416
}
414417

415418
string SubstraitToDuckDB::FindFunction(uint64_t id) {
416419
if (functions_map.find(id) == functions_map.end()) {
417-
throw InternalException("Could not find aggregate function " + to_string(id));
420+
throw NotImplementedException("Could not find aggregate function %s",
421+
to_string(id));
418422
}
419423
return functions_map[id];
420424
}
@@ -442,7 +446,8 @@ OrderByNode SubstraitToDuckDB::TransformOrder(const substrait::SortField &sordf)
442446
dnullorder = OrderByNullType::NULLS_LAST;
443447
break;
444448
default:
445-
throw InternalException("Unsupported ordering " + to_string(sordf.direction()));
449+
throw NotImplementedException("Unsupported ordering %s",
450+
substrait::SortField::GetDescriptor()->FindFieldByNumber(sordf.direction())->name());
446451
}
447452

448453
return {dordertype, dnullorder, TransformExpr(sordf.expr())};
@@ -472,7 +477,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformJoinOp(const substrait::Rel &so
472477
djointype = JoinType::OUTER;
473478
break;
474479
default:
475-
throw InternalException("Unsupported join type");
480+
throw NotImplementedException("Unsupported join type: %s",
481+
substrait::JoinRel::GetDescriptor()->FindFieldByNumber(sjoin.type())->name());
476482
}
477483
unique_ptr<ParsedExpression> join_condition = TransformExpr(sjoin.expression());
478484
return make_shared_ptr<JoinRelation>(TransformOp(sjoin.left())->Alias("left"),
@@ -543,7 +549,8 @@ const substrait::RelCommon* GetCommon(const substrait::Rel &sop) {
543549
case substrait::Rel::RelTypeCase::kUpdate:
544550
case substrait::Rel::RelTypeCase::kDdl:
545551
default:
546-
throw InternalException("Unsupported relation type " + to_string(sop.rel_type_case()));
552+
throw NotImplementedException("Unsupported relation type %s",
553+
substrait::Rel::GetDescriptor()->FindFieldByNumber(sop.rel_type_case())->name());
547554
}
548555
}
549556

@@ -840,7 +847,8 @@ static SetOperationType TransformSetOperationType(substrait::SetRel_SetOp setop)
840847
return SetOperationType::INTERSECT;
841848
}
842849
default: {
843-
throw NotImplementedException("SetOperationType transform not implemented for SetRel_SetOp type %d", setop);
850+
throw NotImplementedException("SetOperationType transform not implemented for SetRel_SetOp type %s",
851+
substrait::SetRel::GetDescriptor()->FindFieldByNumber(setop)->name());
844852
}
845853
}
846854
}
@@ -903,7 +911,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformWriteOp(const substrait::Rel &s
903911
}
904912
}
905913
default:
906-
throw NotImplementedException("Unsupported write operation " + to_string(swrite.op()));
914+
throw NotImplementedException("Unsupported write operation %s",
915+
substrait::WriteRel::GetDescriptor()->FindFieldByNumber(swrite.op())->name());
907916
}
908917
}
909918

@@ -931,7 +940,8 @@ shared_ptr<Relation> SubstraitToDuckDB::TransformOp(const substrait::Rel &sop,
931940
case substrait::Rel::RelTypeCase::kWrite:
932941
return TransformWriteOp(sop);
933942
default:
934-
throw InternalException("Unsupported relation type " + to_string(sop.rel_type_case()));
943+
throw NotImplementedException("Unsupported relation type %s",
944+
substrait::Rel::GetDescriptor()->FindFieldByNumber(sop.rel_type_case())->name());
935945
}
936946
}
937947

0 commit comments

Comments
 (0)