Skip to content

Commit f722c72

Browse files
committed
[SQL] Add the value of the property 'skip_unused_columns' for the table to the generated Rust code
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 1984c3a commit f722c72

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/backend/rust/ToRustVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package org.dbsp.sqlCompiler.compiler.backend.rust;
2525

2626
import com.fasterxml.jackson.databind.JsonNode;
27+
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
2728
import com.fasterxml.jackson.databind.node.ObjectNode;
2829
import org.dbsp.sqlCompiler.circuit.DBSPCircuit;
2930
import org.dbsp.sqlCompiler.circuit.operator.DBSPApplyNOperator;
@@ -88,6 +89,7 @@
8889
import org.dbsp.sqlCompiler.compiler.errors.UnimplementedException;
8990
import org.dbsp.sqlCompiler.compiler.frontend.calciteCompiler.ProgramIdentifier;
9091
import org.dbsp.sqlCompiler.compiler.frontend.calciteObject.CalciteObject;
92+
import org.dbsp.sqlCompiler.compiler.frontend.statements.CreateTableStatement;
9193
import org.dbsp.sqlCompiler.compiler.frontend.statements.IHasSchema;
9294
import org.dbsp.sqlCompiler.compiler.visitors.VisitDecision;
9395
import org.dbsp.sqlCompiler.compiler.visitors.inner.CanonicalForm;
@@ -603,6 +605,8 @@ void registerTable(DBSPSourceMultisetOperator operator, DBSPOperator materialize
603605
.append("::<_, ");
604606
IHasSchema tableDescription = this.metadata.getTableDescription(operator.tableName);
605607
JsonNode j = tableDescription.asJson(true);
608+
if (operator.metadata.skipUnusedColumns != null)
609+
((ObjectNode) j).put(CreateTableStatement.SKIP_UNUSED_COLUMNS, operator.metadata.skipUnusedColumns);
606610
j = this.stripProperties(j);
607611
DBSPStrLiteral json = new DBSPStrLiteral(j.toString(), true);
608612
operator.originalRowType.accept(this.innerVisitor);

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/CatalogTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
import org.dbsp.sqlCompiler.circuit.operator.DBSPSinkOperator;
99
import org.dbsp.sqlCompiler.compiler.CompilerOptions;
1010
import org.dbsp.sqlCompiler.compiler.DBSPCompiler;
11+
import org.dbsp.sqlCompiler.compiler.backend.rust.ToRustVisitor;
12+
import org.dbsp.sqlCompiler.compiler.backend.rust.multi.ProjectDeclarations;
1113
import org.dbsp.sqlCompiler.compiler.frontend.calciteCompiler.ProgramIdentifier;
1214
import org.dbsp.sqlCompiler.compiler.frontend.calciteObject.CalciteObject;
1315
import org.dbsp.sqlCompiler.compiler.sql.tools.BaseSQLTests;
1416
import org.dbsp.sqlCompiler.compiler.visitors.inner.InnerVisitor;
1517
import org.dbsp.sqlCompiler.compiler.visitors.outer.CircuitVisitor;
18+
import org.dbsp.sqlCompiler.compiler.visitors.outer.LateMaterializations;
1619
import org.dbsp.sqlCompiler.ir.type.DBSPType;
1720
import org.dbsp.sqlCompiler.ir.type.derived.DBSPTypeStruct;
1821
import org.dbsp.sqlCompiler.ir.type.derived.DBSPTypeTuple;
1922
import org.dbsp.sqlCompiler.ir.type.primitive.DBSPTypeInteger;
2023
import org.dbsp.sqlCompiler.ir.type.primitive.DBSPTypeString;
2124
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeArray;
2225
import org.dbsp.sqlCompiler.ir.type.user.DBSPTypeZSet;
26+
import org.dbsp.util.IndentStreamBuilder;
2327
import org.dbsp.util.Linq;
2428
import org.junit.Assert;
2529
import org.junit.Test;
@@ -37,6 +41,17 @@ public CompilerOptions testOptions() {
3741
return result;
3842
}
3943

44+
@Test
45+
public void issue5957() {
46+
var cc = this.getCC("CREATE TABLE T(used INTEGER, unused INTEGER) with ('skip_unused_columns' = 'true', 'connectors' = '[]');");
47+
IndentStreamBuilder builder = new IndentStreamBuilder();
48+
ToRustVisitor visitor = new ToRustVisitor(
49+
cc.compiler, builder, cc.getCircuit().getMetadata(),
50+
new ProjectDeclarations(), new LateMaterializations(cc.compiler));
51+
visitor.apply(cc.getCircuit());
52+
Assert.assertTrue(builder.toString().contains("\"skip_unused_columns\":true"));
53+
}
54+
4055
@Test
4156
public void issue5350() {
4257
this.getCCS("""

0 commit comments

Comments
 (0)