Skip to content

Commit

Permalink
Local naming convention for table names (#361)
Browse files Browse the repository at this point in the history
Local naming convention for tables

Signed-off-by: Daniel Henneberger <git@danielhenneberger.com>
  • Loading branch information
henneberger authored Oct 9, 2023
1 parent 6a18b44 commit 569d1b4
Show file tree
Hide file tree
Showing 191 changed files with 1,578 additions and 1,583 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SqrlFramework {
private RelMetadataProvider relMetadataProvider;
private AtomicInteger uniqueMacroInt = new AtomicInteger(0);
private AtomicInteger uniqueTableInt = new AtomicInteger(0);
private Map<Name, AtomicInteger> tableNameToIdMap = new HashMap<>();
private AtomicInteger uniqueColumnInt = new AtomicInteger(0);
private Map<Name,AtomicInteger> tableNameShadowing = new HashMap<Name,AtomicInteger>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CalciteTableFactory {

@Inject
public CalciteTableFactory(SqrlFramework framework) {
this.tableIdFactory = new TableIdFactory(framework.getUniqueTableInt());
this.tableIdFactory = new TableIdFactory(framework.getTableNameToIdMap());
this.tableConverter = new TableConverter(framework.getTypeFactory(), framework.getNameCanonicalizer());
}
public CalciteTableFactory(TableIdFactory tableIdFactory, TableConverter tableConverter) {
Expand All @@ -39,13 +39,13 @@ public CalciteTableFactory(TableIdFactory tableIdFactory, TableConverter tableCo

public ImportedRelationalTableImpl createImportedTable(RelDataType rootType,
TableSource tableSource, Name tableName) {
Name importName = tableIdFactory.createImportTableId(tableName);
Name importName = tableIdFactory.createTableId(tableName);
return new ImportedRelationalTableImpl(importName, rootType, tableSource);
}

public ProxyImportRelationalTable createProxyTable(RelDataType rootType, UniversalTable rootTable,
ImportedRelationalTableImpl importedTable) {
Name proxyName = tableIdFactory.createQueryTableId(rootTable.getName());
Name proxyName = tableIdFactory.createTableId(rootTable.getName());
TimestampInference tsInference = getTimestampInference(rootTable);
return new ProxyImportRelationalTable(
proxyName,
Expand All @@ -58,7 +58,7 @@ public ProxyImportRelationalTable createProxyTable(RelDataType rootType, Univers
}

public PhysicalRelationalTable createPhysicalRelTable(Name name, LPAnalysis analyzedLP) {
Name tableId = tableIdFactory.createQueryTableId(name);
Name tableId = tableIdFactory.createTableId(name);
return new QueryRelationalTable(tableId, name, analyzedLP);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.datasqrl.plan.table;

import com.datasqrl.canonicalizer.Name;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;

@AllArgsConstructor
public class TableIdFactory {
AtomicInteger uniqueTableId;
private Map<Name, AtomicInteger> tableNameToIdMap;

public Name createTableId(@NonNull Name name) {
return createTableId(name, null);
Expand All @@ -18,14 +19,7 @@ public Name createTableId(@NonNull Name name, String type) {
if (!StringUtils.isEmpty(type)) {
name = name.suffix(type);
}
return name.suffix(Integer.toString(uniqueTableId.incrementAndGet()));
}

public Name createImportTableId(Name name) {
return createTableId(name, "i");
}

public Name createQueryTableId(Name name) {
return createTableId(name, "q");
AtomicInteger counter = tableNameToIdMap.computeIfAbsent(name, k -> new AtomicInteger(0));
return name.suffix(Integer.toString(counter.incrementAndGet()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
>>>product$q$2
LogicalTableScan(table=[[product$i$1]])
>>>product$2
LogicalTableScan(table=[[product$1]])

>>>x$q$4
>>>x$1
LogicalProject(_uuid=[$0], productid=[$2], _ingest_time=[$1])
LogicalTableScan(table=[[product$q$2]])
LogicalTableScan(table=[[product$2]])

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>x$q$7
>>>x$1
LogicalProject(_uuid=[$0], _idx=[$6], discount=[$10], time=[$4])
LogicalCorrelate(correlation=[$cor4], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor4.entries])
LogicalValues(tuples=[[{ 0 }]])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
>>>customer$q$2
LogicalTableScan(table=[[customer$i$1]])
>>>customer$2
LogicalTableScan(table=[[customer$1]])

>>>orders$q$5
LogicalTableScan(table=[[orders$i$4]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>product$q$11
LogicalTableScan(table=[[product$i$10]])
>>>product$2
LogicalTableScan(table=[[product$1]])

>>>x$q$13
>>>x$1
LogicalProject(_uuid=[$0], _ingest_time=[$1], customerid=[$2], email=[$3], name=[$4], lastUpdated=[$5])
LogicalFilter(condition=[=($2, ?0)])
LogicalTableScan(table=[[customer$q$2]])
LogicalTableScan(table=[[customer$2]])

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>stats$q$7
>>>stats$1
LogicalProject(___uuid$pk$1=[$0], num=[$2], total=[$3], time=[$1])
LogicalAggregate(group=[{0, 4}], num=[COUNT()], total=[SUM($10)])
LogicalCorrelate(correlation=[$cor5], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor5.entries])
LogicalValues(tuples=[[{ 0 }]])

>>>x$q$10
>>>x$1
LogicalProject(_uuid=[$0], id=[$2], customerid=[$3], num=[$7], time=[$4])
LogicalJoin(condition=[AND(=($0, $6), =($9, $4))], joinType=[left])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[stats$q$7]])
LogicalTableScan(table=[[orders$2]])
LogicalTableScan(table=[[stats$1]])

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>stats$q$7
>>>stats$1
LogicalProject(___uuid$pk$1=[$0], num=[$2], total=[$3], time=[$1])
LogicalAggregate(group=[{0, 4}], num=[COUNT()], total=[SUM($10)])
LogicalCorrelate(correlation=[$cor5], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor5.entries])
LogicalValues(tuples=[[{ 0 }]])

>>>x$q$10
>>>x$1
LogicalProject(_uuid=[$0], id=[$2], customerid=[$3], num=[$7], time=[$4])
LogicalJoin(condition=[AND(=($0, $6), =($9, $4))], joinType=[left])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[stats$q$7]])
LogicalTableScan(table=[[orders$2]])
LogicalTableScan(table=[[stats$1]])

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>x$q$7
>>>x$1
LogicalProject(_uuid=[$0], _idx=[$6], productid=[$7], quantity=[$8], unit_price=[$9], discount=[$10], __timestamp=[$4])
LogicalCorrelate(correlation=[$cor4], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor4.entries])
LogicalValues(tuples=[[{ 0 }]])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
>>>customer$q$2
LogicalTableScan(table=[[customer$i$1]])
>>>customer$2
LogicalTableScan(table=[[customer$1]])

>>>customernames$q$13
>>>customernames$1
LogicalProject(_uuid=[$0], _idx=[$6], productid=[$7], quantity=[$8], unit_price=[$9], discount=[$10], __timestamp=[$4], EXPR$7=[CASE(IS NULL($10), 0:DOUBLE, $10)])
LogicalCorrelate(correlation=[$cor4], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$5]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor4.entries])
LogicalValues(tuples=[[{ 0 }]])

>>>orders$q$5
LogicalTableScan(table=[[orders$i$4]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>product$q$11
LogicalTableScan(table=[[product$i$10]])
>>>product$2
LogicalTableScan(table=[[product$1]])

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
>>>orders$q$2
>>>orders$2
LogicalProject(_uuid=[$0], _ingest_time=[$1], id=[$2], customerid=[$3], time=[$4], entries=[$5], x=['1':VARCHAR(2147483647) CHARACTER SET "UTF-16LE"])
LogicalTableScan(table=[[orders$i$1]])
LogicalTableScan(table=[[orders$1]])

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>x$q$11
>>>x$1
LogicalProject(_uuid=[$0], cast1=['1':VARCHAR(2147483647) CHARACTER SET "UTF-16LE"], time=[$4])
LogicalTableScan(table=[[orders$2]])

>>>x$2
LogicalProject(_uuid=[$0], cast2=[false], time=[$4])
LogicalTableScan(table=[[orders$2]])

>>>x$3
LogicalProject(_uuid=[$0], cast3=[1:DOUBLE], time=[$4])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])

>>>x$q$13
>>>x$4
LogicalProject(_uuid=[$0], cast4=[1:BIGINT], time=[$4])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])

>>>x$q$15
>>>x$5
LogicalProject(_uuid=[$0], cast5=[1970-01-01 00:00:00.001:TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)], time=[$4])
LogicalTableScan(table=[[orders$q$2]])

>>>x$q$7
LogicalProject(_uuid=[$0], cast1=['1':VARCHAR(2147483647) CHARACTER SET "UTF-16LE"], time=[$4])
LogicalTableScan(table=[[orders$q$2]])

>>>x$q$9
LogicalProject(_uuid=[$0], cast2=[false], time=[$4])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
>>>category$q$13
>>>category$1
LogicalProject(name=[$5], _ingest_time=[$1])
LogicalTableScan(table=[[product$q$11]])
LogicalTableScan(table=[[product$2]])

>>>customer$q$2
LogicalTableScan(table=[[customer$i$1]])
>>>customer$2
LogicalTableScan(table=[[customer$1]])

>>>orders$q$5
LogicalTableScan(table=[[orders$i$4]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>product$q$11
LogicalTableScan(table=[[product$i$10]])
>>>product$2
LogicalTableScan(table=[[product$1]])

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
>>>product$q$2
LogicalTableScan(table=[[product$i$1]])
>>>product$2
LogicalTableScan(table=[[product$1]])

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
>>>customer$q$2
LogicalTableScan(table=[[customer$i$1]])
>>>customer$2
LogicalTableScan(table=[[customer$1]])

>>>orders$q$5
LogicalTableScan(table=[[orders$i$4]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>product$q$11
LogicalTableScan(table=[[product$i$10]])
>>>product$2
LogicalTableScan(table=[[product$1]])

>>>x$q$13
>>>x$1
LogicalProject(_uuid=[$0], _ingest_time=[$1], customerid=[$2], email=[$3], name=[$4], lastUpdated=[$5], x=[1])
LogicalFilter(condition=[=($2, ?0)])
LogicalTableScan(table=[[customer$q$2]])
LogicalTableScan(table=[[customer$2]])

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
>>>entries_2$q$7
>>>entries_2$1
LogicalProject(___uuid$pk$1=[$0], discount=[$1], cnt=[$3], time=[$2])
LogicalAggregate(group=[{0, 1, 4}], cnt=[COUNT()])
LogicalProject(___uuid$pk$1=[$0], discount=[COALESCE($10, 0:DOUBLE)], _idx=[$6], _ingest_time=[$1], time=[$4])
LogicalCorrelate(correlation=[$cor4], joinType=[inner], requiredColumns=[{5}])
LogicalTableScan(table=[[orders$q$2]])
LogicalTableScan(table=[[orders$2]])
Uncollect
LogicalProject($f0=[$cor4.entries])
LogicalValues(tuples=[[{ 0 }]])

>>>orders$q$2
LogicalTableScan(table=[[orders$i$1]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
>>>product$q$2
LogicalTableScan(table=[[product$i$1]])
>>>product$2
LogicalTableScan(table=[[product$1]])

>>>product2$q$5
>>>product2$1
LogicalProject(_uuid=[$0], _uuid0=[$6], _uuid00=[$12], _ingest_time=[$1], productid=[$2], name=[$3], description=[$4], category=[$5], _ingest_time0=[$13], productid0=[$14], name0=[$15], description0=[$16], category0=[$17], __timestamp19=[CASE(<($1, $18), $18, $1)])
LogicalJoin(condition=[true], joinType=[inner])
LogicalTableScan(table=[[product$q$2]])
LogicalTableScan(table=[[product$2]])
LogicalProject(_uuid=[$0], _ingest_time=[$1], productid=[$2], name=[$3], description=[$4], category=[$5], _uuid0=[$6], _ingest_time0=[$7], productid0=[$8], name0=[$9], description0=[$10], category0=[$11], __timestamp=[CASE(<($1, $7), $7, $1)])
LogicalJoin(condition=[=($2, $8)], joinType=[inner])
LogicalTableScan(table=[[product$q$2]])
LogicalTableScan(table=[[product$q$2]])
LogicalTableScan(table=[[product$2]])
LogicalTableScan(table=[[product$2]])

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
>>>customer$q$13
LogicalProject(customerid=[$2], _uuid=[$0], _ingest_time=[$1], email=[$3], name=[$4], lastUpdated=[$5])
LogicalTableScan(table=[[customer$q$2]])
>>>customer$2
LogicalTableScan(table=[[customer$1]])

>>>customer$q$2
LogicalTableScan(table=[[customer$i$1]])
>>>customer$3
LogicalProject(customerid=[$2], _uuid=[$0], _ingest_time=[$1], email=[$3], name=[$4], lastUpdated=[$5])
LogicalTableScan(table=[[customer$2]])

>>>orders$q$5
LogicalTableScan(table=[[orders$i$4]])
>>>orders$2
LogicalTableScan(table=[[orders$1]])

>>>product$q$11
LogicalTableScan(table=[[product$i$10]])
>>>product$2
LogicalTableScan(table=[[product$1]])

Loading

0 comments on commit 569d1b4

Please sign in to comment.