Skip to content

Commit

Permalink
Rename field accessor to field reference
Browse files Browse the repository at this point in the history
This matches the name used in the SQL spec
  • Loading branch information
cberner committed Mar 23, 2015
1 parent d5c25d9 commit df8ddd7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Expand Up @@ -194,7 +194,7 @@ public class FunctionRegistry
{
private static final String MAGIC_LITERAL_FUNCTION_PREFIX = "$literal$";
private static final String OPERATOR_PREFIX = "$operator$";
private static final String FIELD_ACCESSOR_PREFIX = "$field_accessor$";
private static final String FIELD_REFERENCE_PREFIX = "$field_reference$";

// hack: java classes for types that can be used with magic literals
private static final Set<Class<?>> SUPPORTED_LITERAL_TYPES = ImmutableSet.<Class<?>>of(long.class, double.class, Slice.class, boolean.class);
Expand Down Expand Up @@ -684,9 +684,9 @@ public static String mangleOperatorName(String operatorName)
return OPERATOR_PREFIX + operatorName;
}

public static String mangleFieldAccessor(String fieldName)
public static String mangleFieldReference(String fieldName)
{
return FIELD_ACCESSOR_PREFIX + fieldName;
return FIELD_REFERENCE_PREFIX + fieldName;
}

@VisibleForTesting
Expand Down
Expand Up @@ -29,13 +29,13 @@
import java.util.Map;
import java.util.Optional;

import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldAccessor;
import static com.facebook.presto.type.TypeUtils.readStructuralBlock;
import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldReference;
import static com.facebook.presto.type.RowType.RowField;
import static com.facebook.presto.type.TypeUtils.readStructuralBlock;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;

public class RowFieldAccessor
public class RowFieldReference
extends ParametricScalar
{
private static final Map<String, MethodHandle> METHOD_HANDLE_MAP;
Expand All @@ -45,14 +45,14 @@ public class RowFieldAccessor

static {
ImmutableMap.Builder<String, MethodHandle> builder = ImmutableMap.builder();
builder.put("long", Reflection.methodHandle(RowFieldAccessor.class, "longAccessor", Type.class, Integer.class, Slice.class));
builder.put("double", Reflection.methodHandle(RowFieldAccessor.class, "doubleAccessor", Type.class, Integer.class, Slice.class));
builder.put("boolean", Reflection.methodHandle(RowFieldAccessor.class, "booleanAccessor", Type.class, Integer.class, Slice.class));
builder.put("slice", Reflection.methodHandle(RowFieldAccessor.class, "sliceAccessor", Type.class, Integer.class, Slice.class));
builder.put("long", Reflection.methodHandle(RowFieldReference.class, "longAccessor", Type.class, Integer.class, Slice.class));
builder.put("double", Reflection.methodHandle(RowFieldReference.class, "doubleAccessor", Type.class, Integer.class, Slice.class));
builder.put("boolean", Reflection.methodHandle(RowFieldReference.class, "booleanAccessor", Type.class, Integer.class, Slice.class));
builder.put("slice", Reflection.methodHandle(RowFieldReference.class, "sliceAccessor", Type.class, Integer.class, Slice.class));
METHOD_HANDLE_MAP = builder.build();
}

public RowFieldAccessor(RowType type, String fieldName)
public RowFieldReference(RowType type, String fieldName)
{
Type returnType = null;
int index = 0;
Expand All @@ -64,7 +64,7 @@ public RowFieldAccessor(RowType type, String fieldName)
index++;
}
checkNotNull(returnType, "%s not found in row type %s", fieldName, type);
signature = new Signature(mangleFieldAccessor(fieldName), returnType.getTypeSignature(), type.getTypeSignature());
signature = new Signature(mangleFieldReference(fieldName), returnType.getTypeSignature(), type.getTypeSignature());

String stackType = returnType.getJavaType().getSimpleName().toLowerCase();
checkState(METHOD_HANDLE_MAP.containsKey(stackType), "method handle missing for %s stack type", stackType);
Expand Down
Expand Up @@ -68,7 +68,7 @@ public class Analysis

private final IdentityHashMap<Table, TableHandle> tables = new IdentityHashMap<>();

private final IdentityHashMap<Expression, Boolean> rowFieldAccesors = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Boolean> rowFieldReferences = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Type> types = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Type> coercions = new IdentityHashMap<>();
private final IdentityHashMap<FunctionCall, FunctionInfo> functionInfo = new IdentityHashMap<>();
Expand Down Expand Up @@ -128,9 +128,9 @@ public IdentityHashMap<Expression, Type> getTypes()
return new IdentityHashMap<>(types);
}

public boolean isRowFieldAccessor(QualifiedNameReference qualifiedNameReference)
public boolean isRowFieldReference(QualifiedNameReference qualifiedNameReference)
{
return rowFieldAccesors.containsKey(qualifiedNameReference);
return rowFieldReferences.containsKey(qualifiedNameReference);
}

public Type getType(Expression expression)
Expand Down Expand Up @@ -290,9 +290,9 @@ public void addTypes(IdentityHashMap<Expression, Type> types)
this.types.putAll(types);
}

public void addRowFieldAccessors(IdentityHashMap<Expression, Boolean> rowFieldAccesors)
public void addRowFieldReferences(IdentityHashMap<Expression, Boolean> rowFieldReferences)
{
this.rowFieldAccesors.putAll(rowFieldAccesors);
this.rowFieldReferences.putAll(rowFieldReferences);
}

public void addCoercion(Expression expression, Type type)
Expand Down
Expand Up @@ -126,7 +126,7 @@ public class ExpressionAnalyzer
private final IdentityHashMap<FunctionCall, FunctionInfo> resolvedFunctions = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Type> expressionTypes = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Type> expressionCoercions = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Boolean> rowFieldAccessors = new IdentityHashMap<>();
private final IdentityHashMap<Expression, Boolean> rowFieldReferences = new IdentityHashMap<>();
private final Set<InPredicate> subqueryInPredicates = newIdentityHashSet();

public ExpressionAnalyzer(Analysis analysis, Session session, Metadata metadata, SqlParser sqlParser, boolean experimentalSyntaxEnabled)
Expand Down Expand Up @@ -158,9 +158,9 @@ public IdentityHashMap<Expression, Type> getExpressionCoercions()
return expressionCoercions;
}

public IdentityHashMap<Expression, Boolean> getRowFieldAccessors()
public IdentityHashMap<Expression, Boolean> getRowFieldReferences()
{
return rowFieldAccessors;
return rowFieldReferences;
}

public Set<InPredicate> getSubqueryInPredicates()
Expand Down Expand Up @@ -321,7 +321,7 @@ else if (matches.size() > 1) {
int fieldIndex = tupleDescriptor.indexOf(field);
resolvedNames.put(node.getName(), fieldIndex);
expressionTypes.put(node, rowFieldType);
rowFieldAccessors.put(node, true);
rowFieldReferences.put(node, true);

return rowFieldType;
}
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public static ExpressionAnalysis analyzeExpression(
analysis.addTypes(expressionTypes);
analysis.addCoercions(expressionCoercions);
analysis.addFunctionInfos(resolvedFunctions);
analysis.addRowFieldAccessors(analyzer.getRowFieldAccessors());
analysis.addRowFieldReferences(analyzer.getRowFieldReferences());

for (Expression subExpression : expressionTypes.keySet()) {
analysis.addResolvedNames(subExpression, analyzer.getResolvedNames());
Expand Down
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.Map;

import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldAccessor;
import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldReference;

/**
* Keeps track of fields and expressions and their mapping to symbols in the current plan
Expand Down Expand Up @@ -198,8 +198,8 @@ public Expression rewriteQualifiedNameReference(QualifiedNameReference node, Voi

Expression rewrittenExpression = new QualifiedNameReference(symbol.toQualifiedName());

if (analysis.isRowFieldAccessor(node)) {
QualifiedName mangledName = QualifiedName.of(mangleFieldAccessor(node.getName().getSuffix()));
if (analysis.isRowFieldReference(node)) {
QualifiedName mangledName = QualifiedName.of(mangleFieldReference(node.getName().getSuffix()));
rewrittenExpression = new FunctionCall(mangledName, ImmutableList.of(rewrittenExpression));
}

Expand Down
Expand Up @@ -14,7 +14,7 @@
package com.facebook.presto.type;

import com.facebook.presto.metadata.ParametricFunction;
import com.facebook.presto.operator.scalar.RowFieldAccessor;
import com.facebook.presto.operator.scalar.RowFieldReference;
import com.facebook.presto.spi.type.StandardTypes;
import com.facebook.presto.spi.type.Type;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -65,7 +65,7 @@ public List<ParametricFunction> createFunctions(Type type)
ImmutableList.Builder<ParametricFunction> builder = ImmutableList.builder();
for (RowField field : rowType.getFields()) {
field.getName()
.ifPresent(name -> builder.add(new RowFieldAccessor(rowType, field.getName().get())));
.ifPresent(name -> builder.add(new RowFieldReference(rowType, field.getName().get())));
}
return builder.build();
}
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.testng.annotations.Test;

import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldAccessor;
import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldReference;
import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
Expand Down Expand Up @@ -71,8 +71,8 @@ public void testRowToJson()
public void testFieldAccessor()
throws Exception
{
String mangledName1 = mangleFieldAccessor("col0");
String mangledName2 = mangleFieldAccessor("col1");
String mangledName1 = mangleFieldReference("col0");
String mangledName2 = mangleFieldReference("col1");
assertFunction('"' + mangledName1 + "\"(test_row(1, 2))", 1);
assertFunction('"' + mangledName2 + "\"(test_row(1, 'kittens'))", "kittens");
}
Expand Down

0 comments on commit df8ddd7

Please sign in to comment.