@@ -94,6 +94,7 @@ public class SubstraitRelNodeConverter
94
94
protected final RelBuilder relBuilder ;
95
95
protected final RexBuilder rexBuilder ;
96
96
private final TypeConverter typeConverter ;
97
+ private final SubstraitRelNodeConverterDdmlValidator substraitRelNodeConverterDdmlValidator ;
97
98
98
99
public SubstraitRelNodeConverter (
99
100
SimpleExtension .ExtensionCollection extensions ,
@@ -142,6 +143,7 @@ public SubstraitRelNodeConverter(
142
143
this .aggregateFunctionConverter = aggregateFunctionConverter ;
143
144
this .expressionRexConverter = expressionRexConverter ;
144
145
this .expressionRexConverter .setRelNodeConverter (this );
146
+ this .substraitRelNodeConverterDdmlValidator = new SubstraitRelNodeConverterDdmlValidator (relBuilder , this );
145
147
}
146
148
147
149
public static RelNode convert (
@@ -554,8 +556,10 @@ public RelNode visit(NamedUpdate update, Context context) {
554
556
555
557
@ Override
556
558
public RelNode visit (NamedDdl namedDdl , Context context ) {
557
- if (namedDdl .getViewDefinition ().isEmpty ()) {
558
- throw new IllegalArgumentException ("no view definition found" );
559
+ final ValidationResult validationResult = namedDdl .accept (substraitRelNodeConverterDdmlValidator , context );
560
+ if (!validationResult .isValid ()) {
561
+ throw new IllegalArgumentException (
562
+ String .join (System .lineSeparator (), validationResult .getMessages ()));
559
563
}
560
564
Rel viewDefinition = namedDdl .getViewDefinition ().get ();
561
565
RelNode relNode = viewDefinition .accept (this , context );
@@ -565,7 +569,6 @@ public RelNode visit(NamedDdl namedDdl, Context context) {
565
569
566
570
@ Override
567
571
public RelNode visit (VirtualTableScan virtualTableScan , Context context ) {
568
-
569
572
final RelDataType typeInfoOnly =
570
573
typeConverter .toCalcite (typeFactory , virtualTableScan .getInitialSchema ().struct ());
571
574
@@ -609,6 +612,11 @@ private RelNode handleCreateTableAs(NamedWrite namedWrite, Context context) {
609
612
610
613
@ Override
611
614
public RelNode visit (NamedWrite write , Context context ) {
615
+ final ValidationResult validationResult = write .accept (substraitRelNodeConverterDdmlValidator , context );
616
+ if (!validationResult .isValid ()) {
617
+ throw new IllegalArgumentException (
618
+ String .join (System .lineSeparator (), validationResult .getMessages ()));
619
+ }
612
620
RelNode input = write .getInput ().accept (this , context );
613
621
assert relBuilder .getRelOptSchema () != null ;
614
622
final RelOptTable targetTable =
@@ -625,16 +633,12 @@ public RelNode visit(NamedWrite write, Context context) {
625
633
case CTAS :
626
634
return handleCreateTableAs (write , context );
627
635
default :
628
- throw new UnsupportedOperationException (
629
- "Write operation '"
630
- + write .getOperation ()
631
- + "' is not supported by the NamedWrite visitor. "
632
- + "Check if a more specific relation type (e.g., NamedUpdate) should be used." );
636
+ // checked by validation
637
+ throw new IllegalArgumentException ("Couldn't determine operation" );
633
638
}
634
639
635
- if (targetTable == null ) {
636
- throw new IllegalStateException ("Table not found in Calcite catalog: " + write .getNames ());
637
- }
640
+ // checked by validation
641
+ assert targetTable != null ;
638
642
639
643
return LogicalTableModify .create (
640
644
targetTable ,
0 commit comments