All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickzetta.platform.test.MultiCDCMockMeta Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.platform.test;

import cz.proto.DataType;
import cz.proto.DataTypeCategory;
import cz.proto.ingestion.v2.IngestionV2;

import java.util.BitSet;

public class MultiCDCMockMeta {

  public static IngestionV2.StreamSchema getPkStreamSchema(String columnPrefix, int fieldSize,
                                                           DataTypeCategory dataTypeCategory,
                                                           BitSet nullableBitset) {
    // build stream schema base.
    IngestionV2.StreamSchema.Builder streamSchemaBuilder = IngestionV2.StreamSchema.newBuilder();
    int fieldId = 1;
    for (int i = 0; i < fieldSize; i++) {
      String columnName = columnPrefix + (i + 1);
      boolean nullable = false;
      if (nullableBitset != null && i < nullableBitset.size()) {
        nullable = nullableBitset.get(i);
      }
      IngestionV2.DataField.Builder dataFieldBuilder = IngestionV2.DataField.newBuilder();
      dataFieldBuilder.setName(columnName).setType(
          DataType.newBuilder()
              .setCategory(dataTypeCategory)
              .setNullable(nullable)
              .setFieldId(fieldId++).build());
      streamSchemaBuilder.addDataFields(dataFieldBuilder.build());
    }
    // build DistributionSpec.
    IngestionV2.DistributionSpec distributionSpec = IngestionV2.DistributionSpec.newBuilder()
        .addFieldIds(1)
        .setNumBuckets(1)
        .build();

    // build PrimaryKeySpec.
    IngestionV2.PrimaryKeySpec primaryKeySpec = IngestionV2.PrimaryKeySpec.newBuilder()
        .addFieldIds(1)
        .build();

    // build pk table schema & info.
    streamSchemaBuilder.setDistSpec(distributionSpec)
        .setPrimaryKeySpec(primaryKeySpec).build();
    return streamSchemaBuilder.build();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy