} else { return Types.GENERIC(Object.class);
private TypeInformation<?> convertAny() { nextToken(TokenType.BEGIN); // check if ANY(class) or ANY(class, serialized) if (isNextToken(2, TokenType.SEPARATOR)) { // any type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.SEPARATOR); nextToken(TokenType.LITERAL); final String serialized = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); final TypeInformation<?> typeInfo = EncodingUtils.decodeStringToObject(serialized, TypeInformation.class); if (!clazz.equals(typeInfo.getTypeClass())) { throw new ValidationException("Class '" + clazz + "' does no correspond to serialized data."); } return typeInfo; } else { // generic type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); return Types.GENERIC(clazz); } }
@Test public void testAvroStringAccess() throws Exception { ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); BatchTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env, config()); Table t = tEnv.fromDataSet(testData(env)); Table result = t.select("name"); List<Utf8> results = tEnv.toDataSet(result, Types.GENERIC(Utf8.class)).collect(); String expected = "Charlie\n" + "Terminator\n" + "Whatever"; TestBaseUtils.compareResultAsText(results, expected); }
Types.MAP(Types.STRING, Types.LONG), Types.PRIMITIVE_ARRAY(Types.BYTE), Types.GENERIC(Object.class), address, Types.PRIMITIVE_ARRAY(Types.BYTE),
@Test public void testTypeInfoParser() { TypeInformation<Tuple3<String, Long, Object>> type1 = Types.TUPLE(Types.STRING, Types.LONG, Types.GENERIC(Object.class)); Assert.assertNotNull(type1); TypeInformation<Tuple4<String, Long, Object, InnerPojo>> type2 = Types.TUPLE(Types.STRING, Types.LONG, Types.GENERIC(Object.class), Types.GENERIC(InnerPojo.class)); Assert.assertNotNull(type2); }
} else { return Types.GENERIC(Object.class);
} else { return Types.GENERIC(Object.class);
@Test public void testStreamTupleSerializerWithTuple() { TypeInformation<Tuple4> typeInfo = Types.GENERIC(Tuple4.class); StreamSchema<Tuple4> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price"); assertEquals(Tuple4.class, schema.getTypeInfo().getTypeClass()); TypeInformation<Tuple2<String, Tuple4>> tuple2TypeInformation = Types.TUPLE(Types.STRING, schema.getTypeInfo()); assertEquals("Java Tuple2<String, GenericType<" + Tuple4.class.getName() + ">>", tuple2TypeInformation.toString()); }
@Test public void testStreamTupleSerializerWithPojo() { TypeInformation<Event> typeInfo = TypeInformation.of(Event.class); assertTrue("Type information should be PojoTypeInfo", typeInfo instanceof PojoTypeInfo); StreamSchema<Event> schema = new StreamSchema<>(typeInfo, "id", "timestamp", "name", "price"); assertEquals(Event.class, schema.getTypeInfo().getTypeClass()); TypeInformation<Tuple2<String, Event>> tuple2TypeInformation = Types.TUPLE(Types.STRING, Types.GENERIC(schema.getTypeInfo().getTypeClass())); assertEquals("Java Tuple2<String, GenericType<" + Event.class.getName() + ">>", tuple2TypeInformation.toString()); }
private TypeInformation<?> convertAny() { nextToken(TokenType.BEGIN); // check if ANY(class) or ANY(class, serialized) if (isNextToken(2, TokenType.SEPARATOR)) { // any type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.SEPARATOR); nextToken(TokenType.LITERAL); final String serialized = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); final TypeInformation<?> typeInfo = EncodingUtils.decodeStringToObject(serialized, TypeInformation.class); if (!clazz.equals(typeInfo.getTypeClass())) { throw new ValidationException("Class '" + clazz + "' does no correspond to serialized data."); } return typeInfo; } else { // generic type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); return Types.GENERIC(clazz); } }
private TypeInformation<?> convertAny() { nextToken(TokenType.BEGIN); // check if ANY(class) or ANY(class, serialized) if (isNextToken(2, TokenType.SEPARATOR)) { // any type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.SEPARATOR); nextToken(TokenType.LITERAL); final String serialized = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); final TypeInformation<?> typeInfo = EncodingUtils.decodeStringToObject(serialized, TypeInformation.class); if (!clazz.equals(typeInfo.getTypeClass())) { throw new ValidationException("Class '" + clazz + "' does no correspond to serialized data."); } return typeInfo; } else { // generic type information nextToken(TokenType.LITERAL); final String className = token().literal; nextToken(TokenType.END); final Class<?> clazz = EncodingUtils.loadClass(className); return Types.GENERIC(clazz); } }