当前位置: 首页>>代码示例>>Java>>正文


Java SchemaBuilder.struct方法代码示例

本文整理汇总了Java中org.apache.kafka.connect.data.SchemaBuilder.struct方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaBuilder.struct方法的具体用法?Java SchemaBuilder.struct怎么用?Java SchemaBuilder.struct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.connect.data.SchemaBuilder的用法示例。


在下文中一共展示了SchemaBuilder.struct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DelimitedTextFileReader

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
public DelimitedTextFileReader(FileSystem fs, Path filePath, Map<String, Object> config) throws IOException {
    super(fs, filePath, new DelimitedTxtToStruct(), config);

    //mapping encoding for text file reader
    if (config.get(FILE_READER_DELIMITED_ENCODING) != null) {
        config.put(TextFileReader.FILE_READER_TEXT_ENCODING, config.get(FILE_READER_DELIMITED_ENCODING));
    }
    this.inner = new TextFileReader(fs, filePath, config);
    this.offset = new DelimitedTextOffset(0, hasHeader);

    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    if (hasNext()) {
        String firstLine = inner.nextRecord().getValue();
        String columns[] = firstLine.split(token);
        IntStream.range(0, columns.length).forEach(index -> {
            String columnName = hasHeader ? columns[index] : DEFAULT_COLUMN_NAME + "_" + ++index;
            schemaBuilder.field(columnName, SchemaBuilder.STRING_SCHEMA);
        });

        if (!hasHeader) {
            //back to the first line
            inner.seek(this.offset);
        }
    }
    this.schema = schemaBuilder.build();
}
 
开发者ID:mmolimar,项目名称:kafka-connect-fs,代码行数:27,代码来源:DelimitedTextFileReader.java

示例2: valueSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
public static Schema valueSchema(SObjectDescriptor descriptor) {
  String name = String.format("%s.%s", SObjectHelper.class.getPackage().getName(), descriptor.name());
  SchemaBuilder builder = SchemaBuilder.struct();
  builder.name(name);

  for (SObjectDescriptor.Field field : descriptor.fields()) {
    if (isTextArea(field)) {
      continue;
    }
    Schema schema = schema(field);
    builder.field(field.name(), schema);
  }

  builder.field(FIELD_OBJECT_TYPE, Schema.OPTIONAL_STRING_SCHEMA);
  builder.field(FIELD_EVENT_TYPE, Schema.OPTIONAL_STRING_SCHEMA);

  return builder.build();
}
 
开发者ID:jcustenborder,项目名称:kafka-connect-salesforce,代码行数:19,代码来源:SObjectHelper.java

示例3: buildAggregateSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
private Schema buildAggregateSchema(final Schema schema,
                                    final FunctionRegistry functionRegistry) {
  final SchemaBuilder schemaBuilder = SchemaBuilder.struct();
  final List<Field> fields = schema.fields();
  for (int i = 0; i < getRequiredColumnList().size(); i++) {
    schemaBuilder.field(fields.get(i).name(), fields.get(i).schema());
  }
  for (int aggFunctionVarSuffix = 0;
       aggFunctionVarSuffix < getFunctionList().size(); aggFunctionVarSuffix++) {
    Schema fieldSchema;
    String udafName = getFunctionList().get(aggFunctionVarSuffix).getName()
        .getSuffix();
    KsqlAggregateFunction aggregateFunction = functionRegistry.getAggregateFunction(udafName,
        getFunctionList()
            .get(aggFunctionVarSuffix).getArguments(), schema);
    fieldSchema = aggregateFunction.getReturnType();
    schemaBuilder.field(AggregateExpressionRewriter.AGGREGATE_FUNCTION_VARIABLE_PREFIX
        + aggFunctionVarSuffix, fieldSchema);
  }

  return schemaBuilder.build();
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:23,代码来源:AggregateNode.java

示例4: testOptionalFieldStruct

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testOptionalFieldStruct() {
    final Flatten<SourceRecord> xform = new Flatten.Value<>();
    xform.configure(Collections.<String, String>emptyMap());

    SchemaBuilder builder = SchemaBuilder.struct();
    builder.field("opt_int32", Schema.OPTIONAL_INT32_SCHEMA);
    Schema supportedTypesSchema = builder.build();

    builder = SchemaBuilder.struct();
    builder.field("B", supportedTypesSchema);
    Schema oneLevelNestedSchema = builder.build();

    Struct supportedTypes = new Struct(supportedTypesSchema);
    supportedTypes.put("opt_int32", null);

    Struct oneLevelNestedStruct = new Struct(oneLevelNestedSchema);
    oneLevelNestedStruct.put("B", supportedTypes);

    SourceRecord transformed = xform.apply(new SourceRecord(null, null,
            "topic", 0,
            oneLevelNestedSchema, oneLevelNestedStruct));

    assertEquals(Schema.Type.STRUCT, transformed.valueSchema().type());
    Struct transformedStruct = (Struct) transformed.value();
    assertNull(transformedStruct.get("B.opt_int32"));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:28,代码来源:FlattenTest.java

示例5: testEnforceLong

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceLong() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);

    try { 
      genericRowValueTypeEnforcer.enforceLong(Boolean.FALSE);
      fail("Expecting exception: KsqlException");
    } catch(KsqlException e) {
       assertEquals(GenericRowValueTypeEnforcer.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:13,代码来源:GenericRowValueTypeEnforcerTest.java

示例6: testEnforceLongThrowsNumberFormatExceptionOne

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceLongThrowsNumberFormatExceptionOne() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    Charset charset = Charset.defaultCharset();
    ByteBuffer byteBuffer = charset.encode("$f{D5-44`A");
    CharBuffer charBuffer = charset.decode(byteBuffer);

    try { 
      genericRowValueTypeEnforcer.enforceLong(charBuffer);
      fail("Expecting exception: NumberFormatException");
    } catch(NumberFormatException e) {
       assertEquals(NumberFormatException.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:16,代码来源:GenericRowValueTypeEnforcerTest.java

示例7: testEnforceDoubleAndEnforceDoubleTwo

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceDoubleAndEnforceDoubleTwo() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);

    assertEquals(0.0,  genericRowValueTypeEnforcer.enforceDouble(0.0F), 0.01);
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:8,代码来源:GenericRowValueTypeEnforcerTest.java

示例8: testEnforceLongReturningLongWhereShortValueIsNegative

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceLongReturningLongWhereShortValueIsNegative() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);

    assertEquals(-446L, (long) genericRowValueTypeEnforcer.enforceLong(-446.28F));
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:8,代码来源:GenericRowValueTypeEnforcerTest.java

示例9: testEnforceDoubleThrowsNumberFormatExceptionTwo

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test(expected = NumberFormatException.class)
public void testEnforceDoubleThrowsNumberFormatExceptionTwo() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);

    genericRowValueTypeEnforcer.enforceDouble("0x");

}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:9,代码来源:GenericRowValueTypeEnforcerTest.java

示例10: removeImplicitRowTimeRowKeyFromSchema

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
public static Schema removeImplicitRowTimeRowKeyFromSchema(Schema schema) {
  SchemaBuilder schemaBuilder = SchemaBuilder.struct();
  for (Field field: schema.fields()) {
    String fieldName = field.name();
    fieldName = fieldName.substring(fieldName.indexOf('.') + 1);
    if (!fieldName.equalsIgnoreCase(SchemaUtil.ROWTIME_NAME)
        && !fieldName.equalsIgnoreCase(SchemaUtil.ROWKEY_NAME)) {
      schemaBuilder.field(fieldName, field.schema());
    }
  }
  return schemaBuilder.build();
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:13,代码来源:SchemaUtil.java

示例11: testEnforceDoubleThrowsNumberFormatExceptionOne

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test(expected = NumberFormatException.class)
public void testEnforceDoubleThrowsNumberFormatExceptionOne() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    Charset charset = Charset.defaultCharset();
    ByteBuffer byteBuffer = charset.encode("");
    CharBuffer charBuffer = charset.decode(byteBuffer);

    genericRowValueTypeEnforcer.enforceDouble(charBuffer);

}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:12,代码来源:GenericRowValueTypeEnforcerTest.java

示例12: getSchemaWithNoAlias

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
/**
 * Remove the alias when reading/writing from outside
 *
 * @param schema
 * @return
 */
public static Schema getSchemaWithNoAlias(Schema schema) {
  SchemaBuilder schemaBuilder = SchemaBuilder.struct();
  for (Field field: schema.fields()) {
    String name = field.name();
    if (name.contains(".")) {
      schemaBuilder.field(name.substring(name.indexOf(".") + 1), field.schema());
    } else {
      schemaBuilder.field(name, field.schema());
    }
  }

  return schemaBuilder.build();
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:20,代码来源:SchemaUtil.java

示例13: testEnforceDouble

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceDouble() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    Object object = new Object();

    try { 
      genericRowValueTypeEnforcer.enforceDouble(object);
      fail("Expecting exception: KsqlException");
    } catch(KsqlException e) {
       assertEquals(GenericRowValueTypeEnforcer.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:14,代码来源:GenericRowValueTypeEnforcerTest.java

示例14: testEnforceFieldTypeTaking1And1WithNull

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceFieldTypeTaking1And1WithNull() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);
    Schema.Type schema_Type = Schema.Type.BOOLEAN;
    ConnectSchema connectSchema = new ConnectSchema(schema_Type);

    try { 
      genericRowValueTypeEnforcer.enforceFieldType(connectSchema,  null);
      fail("Expecting exception: KsqlException");
    } catch(KsqlException e) {
       assertEquals(GenericRowValueTypeEnforcer.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:15,代码来源:GenericRowValueTypeEnforcerTest.java

示例15: testEnforceBooleanReturningBooleanWhereBooleanValueIsFalse

import org.apache.kafka.connect.data.SchemaBuilder; //导入方法依赖的package包/类
@Test
public void testEnforceBooleanReturningBooleanWhereBooleanValueIsFalse() {
    SchemaBuilder schemaBuilder = SchemaBuilder.struct();
    GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schemaBuilder);

    assertFalse(genericRowValueTypeEnforcer.enforceBoolean("0x"));
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:8,代码来源:GenericRowValueTypeEnforcerTest.java


注:本文中的org.apache.kafka.connect.data.SchemaBuilder.struct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。