Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.metadata;
 
 
 import static com.facebook.presto.metadata.Signature.comparableTypeParameter;
 import static com.facebook.presto.metadata.Signature.typeParameter;
 import static com.facebook.presto.metadata.Signature.withVariadicBound;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
 import static com.facebook.presto.spi.type.HyperLogLogType.HYPER_LOG_LOG;
 import static com.facebook.presto.spi.type.TypeSignature.parseTypeSignature;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 
 public class TestSignature
 {
     @Test
     public void testRoundTrip()
     {
         ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider();
         objectMapperProvider.setJsonDeserializers(ImmutableMap.<Class<?>, JsonDeserializer<?>>of(Type.classnew TypeDeserializer(new TypeRegistry())));
         JsonCodec<Signaturecodec = new JsonCodecFactory(objectMapperProvidertrue).jsonCodec(Signature.class);
 
         Signature expected = new Signature("function"., ImmutableList.of(...));
 
         String json = codec.toJson(expected);
         Signature actual = codec.fromJson(json);
 
         assertEquals(actual.getName(), expected.getName());
         assertEquals(actual.getReturnType(), expected.getReturnType());
         assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes());
     }
 
     @Test
     public void testBasic()
             throws Exception
     {
         TypeManager typeManager = new TypeRegistry();
         Signature signature = new Signature("foo", ImmutableList.of(typeParameter("T")), "T", ImmutableList.of("T"), falsetrue);
         assertNotNull(signature.bindTypeParameters(ImmutableList.<Type>of(), truetypeManager));
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>"))), truetypeManager));
     }
 
     @Test
     public void testNonParametric()
             throws Exception
     {
         TypeManager typeManager = new TypeRegistry();
         Signature signature = new Signature("foo", ImmutableList.<TypeParameter>of(), "boolean", ImmutableList.of("bigint"), falsetrue);
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>"))), truetypeManager));
     }
 
     @Test
     public void testArray()
             throws Exception
     {
         TypeManager typeManager = new TypeRegistry();
         Signature signature = new Signature("get", ImmutableList.of(typeParameter("T")), "T", ImmutableList.of("array<T>"), falsetrue);
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>"))), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
 
         signature = new Signature("contains", ImmutableList.of(comparableTypeParameter("T")), "T", ImmutableList.of("array<T>""T"), falsetrue);
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>")), ), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>")), ), truetypeManager));
         assertNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<HyperLogLog>")), ), truetypeManager));
 
         signature = new Signature("foo", ImmutableList.of(typeParameter("T")), "T", ImmutableList.of("array<T>""array<T>"), falsetrue);
         assertNotNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>")), typeManager.getType(parseTypeSignature("array<bigint>"))), truetypeManager));
        assertNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("array<bigint>")), typeManager.getType(parseTypeSignature("array<varchar>"))), truetypeManager));
    }
    @Test
    public void testMap()
            throws Exception
    {
        TypeManager typeManager = new TypeRegistry();
        Signature signature = new Signature("get", ImmutableList.of(typeParameter("K"), typeParameter("V")), "V", ImmutableList.of("map<K,V>""K"), falsetrue);
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("map<bigint,varchar>")), ), truetypeManager));
        assertNull(signature.bindTypeParameters(ImmutableList.of(typeManager.getType(parseTypeSignature("map<bigint,varchar>")), ), truetypeManager));
    }
    @Test
    public void testVariadic()
            throws Exception
    {
        TypeManager typeManager = new TypeRegistry();
        Type mapType = typeManager.getType(parseTypeSignature("map<bigint,bigint>"));
        Type arrayType = typeManager.getType(parseTypeSignature("array<bigint>"));
        Signature signature = new Signature("foo", ImmutableList.of(withVariadicBound("T""map")), "bigint", ImmutableList.of("T"), truetrue);
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(mapType), truetypeManager));
        assertNull(signature.bindTypeParameters(ImmutableList.of(arrayType), truetypeManager));
    }
    @Test
    public void testVarArgs()
            throws Exception
    {
        TypeManager typeManager = new TypeRegistry();
        Signature signature = new Signature("foo", ImmutableList.of(typeParameter("T")), "boolean", ImmutableList.of("T"), truetrue);
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
    }
    @Test
    public void testCoercion()
            throws Exception
    {
        TypeManager typeManager = new TypeRegistry();
        Signature signature = new Signature("foo", ImmutableList.of(typeParameter("T")), "boolean", ImmutableList.of("T""double"), truetrue);
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNotNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
        assertNull(signature.bindTypeParameters(ImmutableList.of(), truetypeManager));
    }
New to GrepCode? Check out our FAQ X