Search in sources :

Example 16 with CoderRegistry

use of org.apache.beam.sdk.coders.CoderRegistry in project beam by apache.

the class KafkaIOTest method testInferKeyCoderFailure.

@Test
public void testInferKeyCoderFailure() throws Exception {
    cannotInferException.expect(RuntimeException.class);
    CoderRegistry registry = CoderRegistry.createDefault();
    KafkaIO.inferCoder(registry, NonInferableObjectDeserializer.class);
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) Test(org.junit.Test)

Example 17 with CoderRegistry

use of org.apache.beam.sdk.coders.CoderRegistry in project beam by apache.

the class LocalDeserializerProviderTest method testInferKeyCoder.

@Test
public void testInferKeyCoder() {
    CoderRegistry registry = CoderRegistry.createDefault();
    assertTrue(LocalDeserializerProvider.of(LongDeserializer.class).getCoder(registry).getValueCoder() instanceof VarLongCoder);
    assertTrue(LocalDeserializerProvider.of(StringDeserializer.class).getCoder(registry).getValueCoder() instanceof StringUtf8Coder);
    assertTrue(LocalDeserializerProvider.of(InstantDeserializer.class).getCoder(registry).getValueCoder() instanceof InstantCoder);
    assertTrue(LocalDeserializerProvider.of(DeserializerWithInterfaces.class).getCoder(registry).getValueCoder() instanceof VarLongCoder);
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) VarLongCoder(org.apache.beam.sdk.coders.VarLongCoder) InstantCoder(org.apache.beam.sdk.coders.InstantCoder) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) Test(org.junit.Test)

Example 18 with CoderRegistry

use of org.apache.beam.sdk.coders.CoderRegistry in project beam by apache.

the class DataTokenizationTest method fileSystemIORead.

private PCollection<Row> fileSystemIORead(String inputGcsFilePattern, FORMAT inputGcsFileFormat) throws IOException {
    DataTokenizationOptions options = PipelineOptionsFactory.create().as(DataTokenizationOptions.class);
    options.setDataSchemaPath(SCHEMA_FILE_PATH);
    options.setInputFilePattern(inputGcsFilePattern);
    options.setInputFileFormat(inputGcsFileFormat);
    if (inputGcsFileFormat == FORMAT.CSV) {
        options.setCsvContainsHeaders(Boolean.FALSE);
    }
    SchemasUtils testSchemaUtils = new SchemasUtils(options.getDataSchemaPath(), StandardCharsets.UTF_8);
    CoderRegistry coderRegistry = testPipeline.getCoderRegistry();
    coderRegistry.registerCoderForType(FAILSAFE_ELEMENT_CODER.getEncodedTypeDescriptor(), FAILSAFE_ELEMENT_CODER);
    coderRegistry.registerCoderForType(RowCoder.of(testSchemaUtils.getBeamSchema()).getEncodedTypeDescriptor(), RowCoder.of(testSchemaUtils.getBeamSchema()));
    /*
     * Row/Row Coder for FailsafeElement.
     */
    FailsafeElementCoder<Row, Row> coder = FailsafeElementCoder.of(RowCoder.of(testSchemaUtils.getBeamSchema()), RowCoder.of(testSchemaUtils.getBeamSchema()));
    coderRegistry.registerCoderForType(coder.getEncodedTypeDescriptor(), coder);
    return new TokenizationFileSystemIO(options).read(testPipeline, testSchemaUtils);
}
Also used : SchemasUtils(org.apache.beam.examples.complete.datatokenization.utils.SchemasUtils) CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) TokenizationFileSystemIO(org.apache.beam.examples.complete.datatokenization.transforms.io.TokenizationFileSystemIO) DataTokenizationOptions(org.apache.beam.examples.complete.datatokenization.options.DataTokenizationOptions) Row(org.apache.beam.sdk.values.Row)

Example 19 with CoderRegistry

use of org.apache.beam.sdk.coders.CoderRegistry in project beam by apache.

the class ReduceFnTester method combining.

/**
 * Creates a {@link ReduceFnTester} for the given {@link WindowingStrategy} and {@link CombineFn},
 * creating a {@link TriggerStateMachine} from the {@link Trigger} in the {@link
 * WindowingStrategy}.
 */
public static <W extends BoundedWindow, AccumT, OutputT> ReduceFnTester<Integer, OutputT, W> combining(WindowingStrategy<?, W> strategy, CombineFn<Integer, AccumT, OutputT> combineFn, Coder<OutputT> outputCoder) throws Exception {
    CoderRegistry registry = CoderRegistry.createDefault();
    // Ensure that the CombineFn can be converted into an AppliedCombineFn
    AppliedCombineFn.withInputCoder(combineFn, registry, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()));
    return combining(strategy, TriggerStateMachines.stateMachineForTrigger(TriggerTranslation.toProto(strategy.getTrigger())), combineFn, outputCoder);
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry)

Example 20 with CoderRegistry

use of org.apache.beam.sdk.coders.CoderRegistry in project beam by apache.

the class ReduceFnTester method combining.

/**
 * Creates a {@link ReduceFnTester} for the given {@link WindowingStrategy}, {@link CombineFn},
 * and {@link TriggerStateMachine}, for mocking the interaction between {@link ReduceFnRunner} and
 * the {@link TriggerStateMachine}. Ignores the {@link Trigger} in the {@link WindowingStrategy}.
 */
public static <W extends BoundedWindow, AccumT, OutputT> ReduceFnTester<Integer, OutputT, W> combining(WindowingStrategy<?, W> strategy, TriggerStateMachine triggerStateMachine, CombineFn<Integer, AccumT, OutputT> combineFn, Coder<OutputT> outputCoder) throws Exception {
    CoderRegistry registry = CoderRegistry.createDefault();
    AppliedCombineFn<String, Integer, AccumT, OutputT> fn = AppliedCombineFn.withInputCoder(combineFn, registry, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of()));
    return new ReduceFnTester<>(strategy, triggerStateMachine, SystemReduceFn.combining(StringUtf8Coder.of(), fn), outputCoder, PipelineOptionsFactory.create(), NullSideInputReader.empty());
}
Also used : CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry)

Aggregations

CoderRegistry (org.apache.beam.sdk.coders.CoderRegistry)24 Test (org.junit.Test)16 DoFn (org.apache.beam.sdk.transforms.DoFn)5 FakeArgumentProvider (org.apache.beam.sdk.transforms.reflect.DoFnInvoker.FakeArgumentProvider)4 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)3 RestrictionTracker (org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker)3 IOException (java.io.IOException)2 TokenizationFileSystemIO (org.apache.beam.examples.complete.datatokenization.transforms.io.TokenizationFileSystemIO)2 SchemasUtils (org.apache.beam.examples.complete.datatokenization.utils.SchemasUtils)2 KeyedWorkItem (org.apache.beam.runners.core.KeyedWorkItem)2 ListOutputManager (org.apache.beam.runners.dataflow.worker.util.ListOutputManager)2 InstantCoder (org.apache.beam.sdk.coders.InstantCoder)2 VarLongCoder (org.apache.beam.sdk.coders.VarLongCoder)2 HasDefaultWatermarkEstimator (org.apache.beam.sdk.transforms.splittabledofn.HasDefaultWatermarkEstimator)2 WatermarkEstimator (org.apache.beam.sdk.transforms.splittabledofn.WatermarkEstimator)2 KV (org.apache.beam.sdk.values.KV)2 Instant (org.joda.time.Instant)2 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 Arrays (java.util.Arrays)1