org.apache.flink.api.common.typeinfo.Types.GENERIC()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.apache.flink.api.common.typeinfo.Types.GENERIC()方法的一些代码示例,展示了Types.GENERIC()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.GENERIC()方法的具体详情如下:
包路径:org.apache.flink.api.common.typeinfo.Types
类名称:Types
方法名:GENERIC

Types.GENERIC介绍

[英]Returns generic type information for any Java object. The serialization logic will use the general purpose serializer Kryo.

Generic types are black-boxes for Flink, but allow any object and null values in fields.

By default, serialization of this type is not very efficient. Please read the documentation about how to improve efficiency (namely by pre-registering classes).
[中]返回任何Java对象的通用类型信息。序列化逻辑将使用通用序列化程序Kryo。
泛型类型是Flink的黑匣子,但允许字段中有任何对象和空值。
默认情况下,这种类型的序列化不是很有效。请阅读有关如何提高效率(即通过预先注册课程)的文档。

代码示例

代码示例来源:origin: apache/flink

} else {
  return Types.GENERIC(Object.class);

代码示例来源:origin: apache/flink

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);
  }
}

代码示例来源:origin: apache/flink

@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);
}

代码示例来源:origin: apache/flink

Types.MAP(Types.STRING, Types.LONG),
Types.PRIMITIVE_ARRAY(Types.BYTE),
Types.GENERIC(Object.class),
address,
Types.PRIMITIVE_ARRAY(Types.BYTE),

代码示例来源:origin: apache/bahir-flink

@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);
}

代码示例来源:origin: com.alibaba.blink/flink-avro

} else {
  return Types.GENERIC(Object.class);

代码示例来源:origin: org.apache.flink/flink-avro

} else {
  return Types.GENERIC(Object.class);

代码示例来源:origin: apache/bahir-flink

@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());
}

代码示例来源:origin: apache/bahir-flink

@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());
}

代码示例来源:origin: com.alibaba.blink/flink-table-common

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);
  }
}

代码示例来源:origin: org.apache.flink/flink-table-common

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);
  }
}

相关文章