Skip to content

Commit

Permalink
remove presto internal usage of legacy type syntax (<>)
Browse files Browse the repository at this point in the history
  • Loading branch information
willshen authored and martint committed Sep 11, 2019
1 parent 9831b3c commit 90d796f
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class MapUnionAggregation

public MapUnionAggregation()
{
super(NAME, ImmutableList.of(comparableTypeParameter("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map<K,V>"), ImmutableList.of(parseTypeSignature("map<K,V>")));
super(NAME, ImmutableList.of(comparableTypeParameter("K"), typeVariable("V")), ImmutableList.of(), parseTypeSignature("map(K,V)"), ImmutableList.of(parseTypeSignature("map(K,V)")));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void validateImplementationDependencyAnnotation(AnnotatedElement element,

static void checkTypeParameters(TypeSignature typeSignature, Set<String> typeParameterNames, AnnotatedElement element)
{
// Check recursively if `typeSignature` contains something like `T<bigint>`
// Check recursively if `typeSignature` contains something like `T(bigint)`
if (typeParameterNames.contains(typeSignature.getBase())) {
checkArgument(typeSignature.getParameters().isEmpty(), "Expected type parameter not to take parameters, but got %s on method [%s]", typeSignature.getBase(), element);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static Slice regexpReplace(@SqlType("varchar(x)") Slice source, @SqlType(
@Description("string(s) extracted using the given pattern")
@ScalarFunction
@LiteralParameters("x")
@SqlType("array<varchar(x)>")
@SqlType("array(varchar(x))")
public static Block regexpExtractAll(@SqlType("varchar(x)") Slice source, @SqlType(Re2JRegexpType.NAME) Re2JRegexp pattern)
{
return regexpExtractAll(source, pattern, 0);
Expand All @@ -75,7 +75,7 @@ public static Block regexpExtractAll(@SqlType("varchar(x)") Slice source, @SqlTy
@Description("group(s) extracted using the given pattern")
@ScalarFunction
@LiteralParameters("x")
@SqlType("array<varchar(x)>")
@SqlType("array(varchar(x))")
public static Block regexpExtractAll(@SqlType("varchar(x)") Slice source, @SqlType(Re2JRegexpType.NAME) Re2JRegexp pattern, @SqlType(StandardTypes.BIGINT) long groupIndex)
{
return pattern.extractAll(source, groupIndex);
Expand Down Expand Up @@ -104,7 +104,7 @@ public static Slice regexpExtract(@SqlType("varchar(x)") Slice source, @SqlType(
@ScalarFunction
@Description("returns array of strings split by pattern")
@LiteralParameters("x")
@SqlType("array<varchar(x)>")
@SqlType("array(varchar(x))")
public static Block regexpSplit(@SqlType("varchar(x)") Slice source, @SqlType(Re2JRegexpType.NAME) Re2JRegexp pattern)
{
return pattern.split(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public class SplitToMapFunction
{
private final PageBuilder pageBuilder;

public SplitToMapFunction(@TypeParameter("map<varchar,varchar>") Type mapType)
public SplitToMapFunction(@TypeParameter("map(varchar,varchar)") Type mapType)
{
pageBuilder = new PageBuilder(ImmutableList.of(mapType));
}

@SqlType("map<varchar,varchar>")
public Block splitToMap(@TypeParameter("map<varchar,varchar>") Type mapType, @SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice entryDelimiter, @SqlType(StandardTypes.VARCHAR) Slice keyValueDelimiter)
@SqlType("map(varchar,varchar)")
public Block splitToMap(@TypeParameter("map(varchar,varchar)") Type mapType, @SqlType(StandardTypes.VARCHAR) Slice string, @SqlType(StandardTypes.VARCHAR) Slice entryDelimiter, @SqlType(StandardTypes.VARCHAR) Slice keyValueDelimiter)
{
checkCondition(entryDelimiter.length() > 0, INVALID_FUNCTION_ARGUMENT, "entryDelimiter is empty");
checkCondition(keyValueDelimiter.length() > 0, INVALID_FUNCTION_ARGUMENT, "keyValueDelimiter is empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String getDisplayName()
ImmutableList<String> names = getTypeParameters().stream()
.map(Type::getDisplayName)
.collect(toImmutableList());
return "function<" + Joiner.on(",").join(names) + ">";
return "function(" + Joiner.on(",").join(names) + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static double jaccardIndex(@SqlType(SetDigestType.NAME) Slice slice1, @Sq

@ScalarFunction
@SqlType("map(bigint,smallint)")
public static Block hashCounts(@TypeParameter("map<bigint,smallint>") Type mapType, @SqlType(SetDigestType.NAME) Slice slice)
public static Block hashCounts(@TypeParameter("map(bigint,smallint)") Type mapType, @SqlType(SetDigestType.NAME) Slice slice)
{
SetDigest digest = SetDigest.newInstance(slice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,9 +1068,7 @@ public void testBindParameters()
assertThat("T2", boundVariables, "bigint");
assertThat("array(T1)", boundVariables, "array(double)");
assertThat("array(T3)", boundVariables, "array(decimal(5,3))");
assertThat("array<T1>", boundVariables, "array(double)");
assertThat("map(T1,T2)", boundVariables, "map(double,bigint)");
assertThat("map<T1,T2>", boundVariables, "map(double,bigint)");
assertThat("bla(T1,42,T2)", boundVariables, "bla(double,42,bigint)");
assertThat("varchar(p)", boundVariables, "varchar(1)");
assertThat("char(p)", boundVariables, "char(1)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TestFunctionType
@Test
public void testDisplayName()
{
Type function = createTestMetadataManager().getType(TypeSignature.parseTypeSignature("function<row(field double),bigint>"));
assertEquals(function.getDisplayName(), "function<row(field double),bigint>");
Type function = createTestMetadataManager().getType(TypeSignature.parseTypeSignature("function(row(field double),bigint)"));
assertEquals(function.getDisplayName(), "function(row(field double),bigint)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void combine(@AggregationState LearnState state, @AggregationState
throw new UnsupportedOperationException("LEARN must run on a single machine");
}

@OutputFunction("Classifier<bigint>")
@OutputFunction("Classifier(bigint)")
public static void output(@AggregationState LearnState state, BlockBuilder out)
{
LearnLibSvmClassifierAggregation.output(state, out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void combine(@AggregationState LearnState state, @AggregationState
throw new UnsupportedOperationException("LEARN must run on a single machine");
}

@OutputFunction("Classifier<bigint>")
@OutputFunction("Classifier(bigint)")
public static void output(@AggregationState LearnState state, BlockBuilder out)
{
Dataset dataset = new Dataset(state.getLabels(), state.getFeatureVectors(), state.getLabelEnumeration().inverse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void combine(@AggregationState LearnState state, @AggregationState
throw new UnsupportedOperationException("LEARN must run on a single machine");
}

@OutputFunction("Classifier<varchar>")
@OutputFunction("Classifier(varchar)")
public static void output(@AggregationState LearnState state, BlockBuilder out)
{
Dataset dataset = new Dataset(state.getLabels(), state.getFeatureVectors(), state.getLabelEnumeration().inverse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void combine(@AggregationState LearnState state, @AggregationState
throw new UnsupportedOperationException("LEARN must run on a single machine");
}

@OutputFunction("Classifier<varchar>")
@OutputFunction("Classifier(varchar)")
public static void output(@AggregationState LearnState state, BlockBuilder out)
{
LearnLibSvmVarcharClassifierAggregation.output(state, out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ private MLFunctions()

@ScalarFunction("classify")
@SqlType(StandardTypes.VARCHAR)
public static Slice varcharClassify(@SqlType(MAP_BIGINT_DOUBLE) Block featuresMap, @SqlType("Classifier<varchar>") Slice modelSlice)
public static Slice varcharClassify(@SqlType(MAP_BIGINT_DOUBLE) Block featuresMap, @SqlType("Classifier(varchar)") Slice modelSlice)
{
FeatureVector features = ModelUtils.toFeatures(featuresMap);
Model model = getOrLoadModel(modelSlice);
checkArgument(model.getType().equals(VARCHAR_CLASSIFIER), "model is not a classifier<varchar>");
checkArgument(model.getType().equals(VARCHAR_CLASSIFIER), "model is not a Classifier(varchar)");
Classifier<String> varcharClassifier = (Classifier<String>) model;
return Slices.utf8Slice(varcharClassifier.classify(features));
}

@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long classify(@SqlType(MAP_BIGINT_DOUBLE) Block featuresMap, @SqlType("Classifier<bigint>") Slice modelSlice)
public static long classify(@SqlType(MAP_BIGINT_DOUBLE) Block featuresMap, @SqlType("Classifier(bigint)") Slice modelSlice)
{
FeatureVector features = ModelUtils.toFeatures(featuresMap);
Model model = getOrLoadModel(modelSlice);
checkArgument(model.getType().equals(BIGINT_CLASSIFIER), "model is not a classifier<bigint>");
checkArgument(model.getType().equals(BIGINT_CLASSIFIER), "model is not a Classifier(bigint)");
Classifier<Integer> classifier = (Classifier<Integer>) model;
return classifier.classify(features);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"fields": [
{
"name": "c_array",
"type": "ARRAY<BIGINT>",
"type": "ARRAY(BIGINT)",
"mapping": "a_array"
},
{
"name": "c_map",
"type": "MAP<VARCHAR, VARCHAR>",
"type": "MAP(VARCHAR, VARCHAR)",
"mapping": "a_map"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TableMetadataSystemTable(@ForMetadata IDBI dbi, TypeManager typeManager)
this.dao = onDemandDao(dbi, MetadataDao.class);
requireNonNull(typeManager, "typeManager is null");

Type arrayOfVarchar = typeManager.getType(parseTypeSignature("array<varchar>"));
Type arrayOfVarchar = typeManager.getType(parseTypeSignature("array(varchar)"));
this.tableMetadata = new ConnectorTableMetadata(
new SchemaTableName("system", "tables"),
ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class TestAvroDecoder
private static final AvroRowDecoderFactory DECODER_FACTORY = new AvroRowDecoderFactory();

private static final Metadata METADATA = createTestMetadataManager();
private static final Type VACHAR_MAP_TYPE = METADATA.getType(parseTypeSignature("map<varchar,varchar>"));
private static final Type DOUBLE_MAP_TYPE = METADATA.getType(parseTypeSignature("map<varchar,double>"));
private static final Type REAL_MAP_TYPE = METADATA.getType(parseTypeSignature("map<varchar,real>"));
private static final Type VACHAR_MAP_TYPE = METADATA.getType(parseTypeSignature("map(varchar,varchar)"));
private static final Type DOUBLE_MAP_TYPE = METADATA.getType(parseTypeSignature("map(varchar,double)"));
private static final Type REAL_MAP_TYPE = METADATA.getType(parseTypeSignature("map(varchar,real)"));

private static String getAvroSchema(String name, String dataType)
{
Expand Down

0 comments on commit 90d796f

Please sign in to comment.