Skip to content

Commit 74602e7

Browse files
committed
first clean
1 parent 3adcce3 commit 74602e7

File tree

8 files changed

+25
-44
lines changed

8 files changed

+25
-44
lines changed

fdb-relational-api/src/main/java/com/apple/foundationdb/relational/api/metadata/DataType.java

+3-19
Original file line numberDiff line numberDiff line change
@@ -957,17 +957,13 @@ public static final class StructType extends DataType implements Named {
957957
@Nonnull
958958
private final String name;
959959

960-
@Nonnull
961-
private final Map<String, FunctionDefinition> userDefinedFunctions;
962-
963960
@Nonnull
964961
private final Supplier<Boolean> resolvedSupplier = Suppliers.memoize(this::calculateResolved);
965962

966-
private StructType(@Nonnull final String name, boolean isNullable, @Nonnull final List<Field> fields, @Nonnull final Map<String, FunctionDefinition> userDefinedOperators) {
963+
private StructType(@Nonnull final String name, boolean isNullable, @Nonnull final List<Field> fields) {
967964
super(isNullable, false, Code.STRUCT);
968965
this.name = name;
969966
this.fields = ImmutableList.copyOf(fields);
970-
this.userDefinedFunctions = ImmutableMap.copyOf(userDefinedOperators);
971967
}
972968

973969
@Nonnull
@@ -981,11 +977,6 @@ public String getName() {
981977
return name;
982978
}
983979

984-
@Nonnull
985-
public Map<String, FunctionDefinition> getUserDefinedFunctions() {
986-
return ImmutableMap.copyOf(userDefinedFunctions);
987-
}
988-
989980
public static class Field {
990981
@Nonnull
991982
private final Supplier<Integer> hashCodeSupplier = Suppliers.memoize(this::computeHashCode);
@@ -1056,14 +1047,7 @@ public String toString() {
10561047

10571048
@Nonnull
10581049
public static StructType from(@Nonnull final String name, @Nonnull final List<Field> fields, boolean isNullable) {
1059-
return new StructType(name, isNullable, fields, ImmutableMap.of());
1060-
}
1061-
1062-
@Nonnull
1063-
public StructType withFunctionDefinition(FunctionDefinition functionDefinition) {
1064-
Map<String, FunctionDefinition> newUserDefinedFunctions = new java.util.HashMap<>(userDefinedFunctions);
1065-
newUserDefinedFunctions.put(functionDefinition.getName(), functionDefinition);
1066-
return new StructType(name, isNullable(), fields, newUserDefinedFunctions);
1050+
return new StructType(name, isNullable, fields);
10671051
}
10681052

10691053
@Override
@@ -1072,7 +1056,7 @@ public StructType withNullable(boolean isNullable) {
10721056
if (isNullable == isNullable()) {
10731057
return this;
10741058
}
1075-
return new StructType(name, isNullable, fields, userDefinedFunctions);
1059+
return new StructType(name, isNullable, fields);
10761060
}
10771061

10781062
private boolean calculateResolved() {

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/catalog/RecordLayerStoreSchemaTemplateCatalog.java

-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ private static Tuple getSchemaTemplatePrimaryKey(String schemaTemplateName) {
160160
@Override
161161
public SchemaTemplate loadSchemaTemplate(@Nonnull Transaction txn, @Nonnull String templateName)
162162
throws RelationalException {
163-
System.out.println("RLStoreSchemaTemplateCatalog loadSchemaTemplate called with templateName:" + templateName);
164163
Tuple key = getSchemaTemplatePrimaryKey(templateName);
165164
var recordStore = RecordLayerStoreUtils.openRecordStore(txn, this.catalogSchemaPath,
166165
this.catalogRecordMetaDataProvider);
@@ -203,7 +202,6 @@ public SchemaTemplate loadSchemaTemplate(@Nonnull Transaction txn, @Nonnull Stri
203202
*/
204203
@Nonnull
205204
private static SchemaTemplate toSchemaTemplate(@Nonnull Message m) throws InvalidProtocolBufferException {
206-
System.out.println("RecordLayerStoreSchemaTemplateCatalog::toSchemaTemplate called");
207205
Descriptors.Descriptor d = m.getDescriptorForType();
208206
ByteString bs = (ByteString) m.getField(d.findFieldByName(SchemaTemplateSystemTable.METADATA));
209207
RecordMetaData metaData = RecordMetaData.build(RecordMetaDataProto.MetaData.parseFrom(bs.toByteArray()));

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metadata/RecordLayerSchemaTemplate.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ public Builder addAuxiliaryType(@Nonnull DataType.Named auxiliaryType) {
402402
Assert.thatUnchecked(!tables.containsKey(auxiliaryType.getName()), ErrorCode.INVALID_SCHEMA_TEMPLATE, TABLE_ALREADY_EXISTS, auxiliaryType.getName());
403403
Assert.thatUnchecked(!auxiliaryTypes.containsKey(auxiliaryType.getName()), ErrorCode.INVALID_SCHEMA_TEMPLATE, TYPE_WITH_NAME_ALREADY_EXISTS, auxiliaryType.getName());
404404
auxiliaryTypes.put(auxiliaryType.getName(), auxiliaryType);
405-
System.out.println("auxiliaryTypes name:" + auxiliaryType.getName());
406405
return this;
407406
}
408407

@@ -420,6 +419,19 @@ public Builder addAuxiliaryTypes(@Nonnull Collection<DataType.Named> auxiliaryTy
420419
return this;
421420
}
422421

422+
@Nonnull
423+
public Builder addUDF(@Nonnull UDF udf) {
424+
Assert.thatUnchecked(!udfMap.containsKey(udf.getUdfName()), ErrorCode.INVALID_SCHEMA_TEMPLATE, TABLE_ALREADY_EXISTS, udf.getUdfName());
425+
udfMap.put(udf.getUdfName(), udf);
426+
return this;
427+
}
428+
429+
@Nonnull
430+
public Builder addUDFs(@Nonnull Collection<UDF> udf) {
431+
udf.forEach(this::addUDF);
432+
return this;
433+
}
434+
423435
@Nonnull
424436
Builder setCachedMetadata(@Nonnull final RecordMetaData metadata) {
425437
this.cachedMetadata = metadata;

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/PlanGenerator.java

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ private Plan<?> getPlanInternal(@Nonnull String query, @Nonnull KeyValueLogMessa
153153
QueryPlan.PhysicalQueryPlan.getValidPlanHashModes(options);
154154
final PlanHashable.PlanHashMode currentPlanHashMode = QueryPlan.PhysicalQueryPlan.getCurrentPlanHashMode(options);
155155
final var astHashResult = AstNormalizer.normalizeQuery(planContext, query, isCaseSensitive(), currentPlanHashMode);
156-
// rewrite the query with operationDefinition
157156
RelationalLoggingUtil.publishNormalizeQueryLogs(message, stepTimeMicros(), astHashResult.getQueryCacheKey().getHash(),
158157
astHashResult.getQueryCacheKey().getCanonicalQueryString());
159158
options = options.withChild(astHashResult.getQueryOptions());

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/functions/SqlFunctionCatalog.java

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ public static SqlFunctionCatalog instance() {
115115
return INSTANCE;
116116
}
117117

118+
public BuiltInFunction<? extends Typed> addFunction(UserDefinedFunctionDefinition functionDefinition) {
119+
final var func = functionDefinition.getBuiltInFunction();
120+
udfMap.put(functionDefinition.getName(), func);
121+
return func;
122+
}
123+
118124
/**
119125
* A utility method that transforms a single-item {@link RecordConstructorValue} value into its inner {@link Value}.
120126
* This is mainly used for deterministically distinguishing between:

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/visitors/ExpressionVisitor.java

+3-19
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,13 @@ public Expression visitCaseFunctionCall(@Nonnull RelationalParser.CaseFunctionCa
254254
@Nonnull
255255
@Override
256256
public Expression visitUserDefinedFunctionCall(@Nonnull RelationalParser.UserDefinedFunctionCallContext ctx) {
257-
System.out.println("visitUserDefinedFunctionCall called");
258257
final var functionName = ctx.userDefinedFunctionName.getText();
259258
// special case for user-defined functions where we want to exclude the first argument from
260259
// being literal-stripped.
261260
@Nonnull Expressions arguments;
261+
// check if this function exists in schema template
262+
UDF udf = getDelegate().getCatalog().getUDF(functionName);
263+
// look up in FunctionCatalog
262264
boolean isUdf = getDelegate().getSemanticAnalyzer().isUdfFunction(functionName);
263265
if (isUdf) {
264266
final var argumentNodes = ctx.functionArgs().children.stream()
@@ -285,7 +287,6 @@ public Expression visitUserDefinedFunctionCall(@Nonnull RelationalParser.UserDef
285287
@Nonnull
286288
@Override
287289
public Expression visitFunctionCallExpressionAtom(@Nonnull RelationalParser.FunctionCallExpressionAtomContext ctx) {
288-
System.out.println("ExpressionVisitor::visitFunctionCallExpressionAtom:" + ctx.getText() + " ctx class:" + ctx.getClass());
289290
return parseChild(ctx);
290291
}
291292

@@ -500,20 +501,8 @@ public Expression visitBitExpressionAtom(@Nonnull RelationalParser.BitExpression
500501
@Nonnull
501502
@Override
502503
public Expression visitBinaryComparisonPredicate(@Nonnull RelationalParser.BinaryComparisonPredicateContext ctx) {
503-
// if comparison operator is overriden, and left.dataType = RLUDOperator.getStructName,
504-
// for example, ctx = (a = b)
505-
// RLUDoperator.getExpressionCtx = (x.string_value = y.string_value and x.long_value = y.long_value);
506-
// rewrite the function, change ctx -> a.string_value = b.string_value and a.long_value = b.long_value
507-
System.out.println("get into visitBinaryComparisonPredicate");
508504
final var left = Assert.castUnchecked(ctx.left.accept(this), Expression.class);
509505
final var right = Assert.castUnchecked(ctx.right.accept(this), Expression.class);
510-
System.out.println("left dataType:" + left.getDataType() + " left:" + left + " left.getClass:" + left.getDataType().getClass());
511-
System.out.println("right dataType:" + right.getDataType());
512-
513-
if (left.getDataType() instanceof DataType.StructType) {
514-
FunctionDefinition operationDefinition = getDelegate().getCatalog().getOperationDefinition(ctx.comparisonOperator().getText(), (DataType.StructType) left.getDataType());
515-
System.out.println("operationDefinition:" + operationDefinition);
516-
}
517506
return getDelegate().resolveFunction(ctx.comparisonOperator().getText(), left, right);
518507
}
519508

@@ -869,11 +858,6 @@ Optional<LogicalPlanFragment.State> getStateMaybe() {
869858

870859
@Nonnull
871860
private Expression parseChild(@Nonnull ParserRuleContext context) {
872-
Expressions expressions = (Expressions) visitChildren(context);
873-
for (int i = 0; i < context.getChildCount(); i++) {
874-
System.out.println("ith:" + i + " child:" + context.getChild(i).getText());
875-
}
876-
System.out.println("expressions:" + expressions);
877861
return Assert.castUnchecked(visitChildren(context), Expression.class);
878862
}
879863

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/visitors/IdentifierVisitor.java

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public Identifier visitTableName(@Nonnull RelationalParser.TableNameContext tabl
5454
@Nonnull
5555
@Override
5656
public Identifier visitFullId(@Nonnull RelationalParser.FullIdContext fullIdContext) {
57-
System.out.println("identifierVisitor visitFullId called");
5857
Assert.thatUnchecked(!fullIdContext.uid().isEmpty());
5958
final ImmutableList.Builder<String> qualifierBuilder = ImmutableList.builder();
6059
for (int i = 0; i < fullIdContext.uid().size() - 1; i++) {

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/api/DriverManagerTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import java.sql.DriverManager;
3232
import java.sql.SQLException;
33-
import java.util.stream.Collectors;
3433

3534
import static org.mockito.ArgumentMatchers.any;
3635
import static org.mockito.Mockito.when;

0 commit comments

Comments
 (0)