Search in sources :

Example 1 with FieldInfo

use of org.apache.inlong.sort.protocol.FieldInfo in project incubator-inlong by apache.

the class SourceInfoUtils method createPulsarSourceInfo.

/**
 * Create source info for Pulsar
 */
private static SourceInfo createPulsarSourceInfo(PulsarClusterInfo pulsarCluster, ClusterBean clusterBean, InlongGroupInfo groupInfo, InlongStreamInfo streamInfo, DeserializationInfo deserializationInfo, List<FieldInfo> fieldInfos) {
    String topicName = streamInfo.getMqResourceObj();
    InlongGroupPulsarInfo pulsarInfo = (InlongGroupPulsarInfo) groupInfo.getMqExtInfo();
    String tenant = clusterBean.getDefaultTenant();
    if (StringUtils.isNotEmpty(pulsarInfo.getTenant())) {
        tenant = pulsarInfo.getTenant();
    }
    final String namespace = groupInfo.getMqResourceObj();
    // Full name of topic in Pulsar
    final String fullTopicName = "persistent://" + tenant + "/" + namespace + "/" + topicName;
    final String consumerGroup = clusterBean.getAppName() + "_" + topicName + "_consumer_group";
    FieldInfo[] fieldInfosArr = fieldInfos.toArray(new FieldInfo[0]);
    String type = pulsarCluster.getType();
    if (StringUtils.isNotEmpty(type) && Constant.MIDDLEWARE_TDMQ_PULSAR.equals(type)) {
        return new TDMQPulsarSourceInfo(pulsarCluster.getBrokerServiceUrl(), fullTopicName, consumerGroup, pulsarCluster.getToken(), deserializationInfo, fieldInfosArr);
    } else {
        return new PulsarSourceInfo(pulsarCluster.getAdminUrl(), pulsarCluster.getBrokerServiceUrl(), fullTopicName, consumerGroup, deserializationInfo, fieldInfosArr, pulsarCluster.getToken());
    }
}
Also used : InlongGroupPulsarInfo(org.apache.inlong.manager.common.pojo.group.InlongGroupPulsarInfo) TDMQPulsarSourceInfo(org.apache.inlong.sort.protocol.source.TDMQPulsarSourceInfo) PulsarSourceInfo(org.apache.inlong.sort.protocol.source.PulsarSourceInfo) TDMQPulsarSourceInfo(org.apache.inlong.sort.protocol.source.TDMQPulsarSourceInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 2 with FieldInfo

use of org.apache.inlong.sort.protocol.FieldInfo in project incubator-inlong by apache.

the class FieldMappingRuleTest method init.

@Override
public void init() {
    expectedObject = new FieldMappingRule(new FieldMappingRule.FieldMappingUnit[] { new FieldMappingRule.FieldMappingUnit(new FieldInfo("f1", StringFormatInfo.INSTANCE), new FieldInfo("f2", DoubleFormatInfo.INSTANCE)) });
    expectedJson = "{\n" + "    \"type\":\"field_mapping\",\n" + "    \"field_mapping_units\":[\n" + "        {\n" + "            \"source_field\":{\n" + "                \"type\":\"base\",\n" + "                \"name\":\"f1\",\n" + "                \"format_info\":{\n" + "                    \"type\":\"string\"\n" + "                }\n" + "            },\n" + "            \"sink_field\":{\n" + "                \"type\":\"base\",\n" + "                \"name\":\"f2\",\n" + "                \"format_info\":{\n" + "                    \"type\":\"double\"\n" + "                }\n" + "            }\n" + "        }\n" + "    ]\n" + "}";
    equalObj1 = expectedObject;
    equalObj2 = new FieldMappingRule(new FieldMappingRule.FieldMappingUnit[] { new FieldMappingRule.FieldMappingUnit(new FieldInfo("f1", StringFormatInfo.INSTANCE), new FieldInfo("f2", DoubleFormatInfo.INSTANCE)) });
    unequalObj = new FieldMappingRule(new FieldMappingRule.FieldMappingUnit[] { new FieldMappingRule.FieldMappingUnit(new FieldInfo("f1", StringFormatInfo.INSTANCE), new FieldInfo("f3", DoubleFormatInfo.INSTANCE)) });
}
Also used : FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 3 with FieldInfo

use of org.apache.inlong.sort.protocol.FieldInfo in project incubator-inlong by apache.

the class HiveSinkITCase method prepareSinkSchema.

private HiveSinkInfo prepareSinkSchema() {
    final FieldInfo f1 = new FieldInfo(fieldName1, new TimestampFormatInfo("MILLIS"));
    final FieldInfo f2 = new FieldInfo(fieldName2, IntFormatInfo.INSTANCE);
    final FieldInfo f3 = new FieldInfo(fieldName3, StringFormatInfo.INSTANCE);
    final FieldInfo f4 = new FieldInfo(fieldName4, StringFormatInfo.INSTANCE);
    final HiveTimePartitionInfo timePartition = new HiveTimePartitionInfo(f1.getName(), timePartitionFormat);
    final HiveFieldPartitionInfo fieldPartition = new HiveFieldPartitionInfo(f2.getName());
    return new HiveSinkInfo(new FieldInfo[] { f1, f2, f3, f4 }, hiveMetastoreUrl, hiveDb, hiveTable, hiveUsername, hivePassword, dfsSchema + hdfsDataDir, new HivePartitionInfo[] { timePartition, fieldPartition }, new TextFileFormat("\t".charAt(0)));
}
Also used : HiveFieldPartitionInfo(org.apache.inlong.sort.protocol.sink.HiveSinkInfo.HiveFieldPartitionInfo) TimestampFormatInfo(org.apache.inlong.sort.formats.common.TimestampFormatInfo) HiveTimePartitionInfo(org.apache.inlong.sort.protocol.sink.HiveSinkInfo.HiveTimePartitionInfo) HiveSinkInfo(org.apache.inlong.sort.protocol.sink.HiveSinkInfo) TextFileFormat(org.apache.inlong.sort.protocol.sink.HiveSinkInfo.TextFileFormat) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 4 with FieldInfo

use of org.apache.inlong.sort.protocol.FieldInfo in project incubator-inlong by apache.

the class RecordTransformerTest method testRecordMatchSerializer.

@Test
public void testRecordMatchSerializer() throws Exception {
    final int bufferSize = 1024;
    final RecordTransformer transformer = new RecordTransformer(bufferSize);
    final FieldInfo field1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo field2 = new FieldInfo("field2", new StringFormatInfo());
    final TestingSinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { field1, field2 });
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), sinkInfo);
    transformer.addDataFlow(dataFlowInfo);
    Map<Long, RowSerializer> rowSerializers = transformer.getRowSerializers();
    final Row row = new Row(2);
    row.setField(0, 1024L);
    row.setField(1, "9527");
    final Record record = new Record(1L, System.currentTimeMillis(), row);
    assertSame(record, transformer.matchRecordAndSerializerField(record, rowSerializers.get(1L)));
}
Also used : RowSerializer(org.apache.flink.api.java.typeutils.runtime.RowSerializer) SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) EmptySourceInfo(org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 5 with FieldInfo

use of org.apache.inlong.sort.protocol.FieldInfo in project incubator-inlong by apache.

the class RecordTransformerTest method testRecordNotMatchSerializer.

@Test
public void testRecordNotMatchSerializer() throws Exception {
    final int bufferSize = 1024;
    final RecordTransformer transformer = new RecordTransformer(bufferSize);
    final FieldInfo field1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo field2 = new FieldInfo("field2", new StringFormatInfo());
    final TestingSinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { field1, field2 });
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), sinkInfo);
    transformer.addDataFlow(dataFlowInfo);
    Map<Long, RowSerializer> rowSerializers = transformer.getRowSerializers();
    final Row oneFieldRow = new Row(1);
    oneFieldRow.setField(0, 1024L);
    final Record oneFieldRecord = new Record(1L, System.currentTimeMillis(), oneFieldRow);
    assertEquals(2, transformer.matchRecordAndSerializerField(oneFieldRecord, rowSerializers.get(1L)).getRow().getArity());
    final Row threeFieldRow = new Row(3);
    threeFieldRow.setField(0, 1024L);
    threeFieldRow.setField(1, "9527");
    threeFieldRow.setField(2, 2048);
    final Record threeFieldRecord = new Record(1L, System.currentTimeMillis(), threeFieldRow);
    assertEquals(2, transformer.matchRecordAndSerializerField(threeFieldRecord, rowSerializers.get(1L)).getRow().getArity());
}
Also used : RowSerializer(org.apache.flink.api.java.typeutils.runtime.RowSerializer) SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) EmptySourceInfo(org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Aggregations

FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)54 Test (org.junit.Test)22 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)19 Row (org.apache.flink.types.Row)18 BuiltInFieldInfo (org.apache.inlong.sort.protocol.BuiltInFieldInfo)18 LongFormatInfo (org.apache.inlong.sort.formats.common.LongFormatInfo)11 DataFlowInfo (org.apache.inlong.sort.protocol.DataFlowInfo)10 Record (org.apache.inlong.sort.flink.Record)9 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)8 TimestampFormatInfo (org.apache.inlong.sort.formats.common.TimestampFormatInfo)8 ArrayList (java.util.ArrayList)7 TestingSinkInfo (org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo)7 HashMap (java.util.HashMap)5 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)5 SerializedRecord (org.apache.inlong.sort.flink.SerializedRecord)5 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)5 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)5 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)5 Timestamp (java.sql.Timestamp)4 BooleanFormatInfo (org.apache.inlong.sort.formats.common.BooleanFormatInfo)4