Skip to content

Commit

Permalink
Make field reference work for expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Mar 23, 2015
1 parent df8ddd7 commit b2ee04e
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 106 deletions.
Expand Up @@ -194,7 +194,6 @@ public class FunctionRegistry
{
private static final String MAGIC_LITERAL_FUNCTION_PREFIX = "$literal$";
private static final String OPERATOR_PREFIX = "$operator$";
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,11 +683,6 @@ public static String mangleOperatorName(String operatorName)
return OPERATOR_PREFIX + operatorName;
}

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

@VisibleForTesting
public static OperatorType unmangleOperator(String mangledName)
{
Expand Down
Expand Up @@ -29,7 +29,7 @@
import java.util.Map;
import java.util.Optional;

import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldReference;
import static com.facebook.presto.sql.QueryUtil.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;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import java.util.List;
import java.util.Map;

import static com.facebook.presto.metadata.FunctionRegistry.mangleFieldReference;
import static com.facebook.presto.sql.QueryUtil.mangleFieldReference;

/**
* Keeps track of fields and expressions and their mapping to symbols in the current plan
Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.testng.annotations.Test;

import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
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,10 +70,10 @@ public void testRowToJson()
public void testFieldAccessor()
throws Exception
{
String mangledName1 = mangleFieldReference("col0");
String mangledName2 = mangleFieldReference("col1");
assertFunction('"' + mangledName1 + "\"(test_row(1, 2))", 1);
assertFunction('"' + mangledName2 + "\"(test_row(1, 'kittens'))", "kittens");
assertFunction("test_row(1, 2).col0", 1);
assertFunction("test_row(1, 'kittens').col1", "kittens");
assertFunction("test_row(1, 2).\"col1\"", 2);
assertFunction("array[test_row(1, 2)][1].col1", 2);
}

@Test
Expand Down
Expand Up @@ -215,6 +215,7 @@ primaryExpression
| TRY_CAST '(' expression AS type ')' #cast
| ARRAY '[' (expression (',' expression)*)? ']' #arrayConstructor
| value=primaryExpression '[' index=valueExpression ']' #subscript
| value=primaryExpression '.' fieldName=identifier #fieldReference
| name=CURRENT_DATE #specialDateTimeFunction
| name=CURRENT_TIME ('(' precision=INTEGER_VALUE ')')? #specialDateTimeFunction
| name=CURRENT_TIMESTAMP ('(' precision=INTEGER_VALUE ')')? #specialDateTimeFunction
Expand Down

0 comments on commit b2ee04e

Please sign in to comment.