com.clickzetta.platform.schema.SchemaConvert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickzetta-java Show documentation
Show all versions of clickzetta-java Show documentation
The java SDK for clickzetta's Lakehouse
package com.clickzetta.platform.schema;
import com.clickzetta.platform.client.api.ProtocolType;
import com.clickzetta.platform.common.Schema;
import com.clickzetta.platform.common.*;
import com.google.common.base.Preconditions;
import cz.proto.DataType;
import cz.proto.DataTypeCategory;
import cz.proto.FieldSchema;
import cz.proto.MetadataEntity;
import cz.proto.ingestion.Ingestion.IGSTableType;
import org.apache.kudu.KuduCommon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.Tuple3;
import java.util.*;
public interface SchemaConvert {
static SchemaConvert getInstance(IGSTableType igsTableType, ProtocolType protocolType) {
switch (igsTableType) {
case NORMAL:
// return new CommonSchemaConvert();
case CLUSTER:
// return new ClusterSchemaConvert();
case ACID:
// return new AcidSchemaConvert();
default:
throw new UnsupportedOperationException("not support schema convert with table type: " + igsTableType);
}
}
/**
* format like server side kudu schemaPb. used for in memory tablet schema double check.
*
* @param meta
* @param schema
* @return
*/
KuduCommon.SchemaPB convertToExternalSchemaPB(MetadataEntity.Entity meta, Schema schema);
/**
* format like server side kudu key schemaPb. used for in memory tablet schema double check.
*
* @param meta
* @param keySchema
* @return
*/
KuduCommon.SchemaPB convertToExternalKeySchemaPB(MetadataEntity.Entity meta, Schema keySchema);
KuduCommon.ColumnSchemaPB buildVirtualColumnSchemaPB(int beginId, String virtualKeyType);
KuduCommon.ColumnSchemaPB buildColumnSchemaPB(FieldSchema field, boolean isKey, int beginId);
KuduCommon.ColumnSchemaPB buildColumnSchemaPB(FieldSchema field, boolean isKey, int beginId,
ColumnTypeAttributes.ColumnSpecialType columnSpecialType);
/**
* client side schema. only used for row operation encode.
*
* @param meta
* @return
*/
Schema convertToExternalSchema(MetadataEntity.Entity meta);
/**
* client side key schema. only used for key row operation encode.
*
* @param meta
* @return
*/
Schema convertToExternalKeySchema(MetadataEntity.Entity meta);
ColumnSchema buildVirtualColumnSchema(String virtualKeyType);
ColumnSchema buildColumnSchema(FieldSchema fieldSchema, boolean isKey);
default Type convertToExternalType(DataType type) {
switch (type.getCategoryValue()) {
case DataTypeCategory.INT8_VALUE:
return Type.INT8;
case DataTypeCategory.INT16_VALUE:
return Type.INT16;
case DataTypeCategory.INT32_VALUE:
return Type.INT32;
case DataTypeCategory.INT64_VALUE:
return Type.INT64;
case DataTypeCategory.FLOAT32_VALUE:
return Type.FLOAT;
case DataTypeCategory.FLOAT64_VALUE:
return Type.DOUBLE;
case DataTypeCategory.DECIMAL_VALUE:
return Type.DECIMAL;
case DataTypeCategory.BOOLEAN_VALUE:
return Type.BOOL;
case DataTypeCategory.VARCHAR_VALUE:
case DataTypeCategory.CHAR_VALUE:
return Type.VARCHAR;
case DataTypeCategory.STRING_VALUE:
return Type.STRING;
case DataTypeCategory.BINARY_VALUE:
return Type.BINARY;
case DataTypeCategory.DATE_VALUE:
return Type.DATE;
case DataTypeCategory.TIMESTAMP_LTZ_VALUE:
return Type.UNIXTIME_MICROS;
default:
throw new UnsupportedOperationException("not support dataType: " + type);
}
}
/**
* User-facing schema to create row object for writing data.
* It returns pure table schema without adding any extra virtual columns.
*
* @param meta
* @return
*/
default com.clickzetta.platform.common.Schema convertToPureExternalSchema(MetadataEntity.Entity meta) {
List fields = meta.getTable().getTableSchema().getFieldsList();
List columns = new ArrayList<>(fields.size());
for (FieldSchema field : fields) {
if (field.hasHidden() && field.getHidden()) {
continue;
}
if (field.hasVirtual() && field.getVirtual()) {
continue;
}
columns.add(buildColumnSchema(field, false));
}
return new Schema(columns, Collections.emptyList(), Collections.emptyList());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy