com.clickzetta.platform.common.AcidSchemaConvert 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.common;
import cz.proto.FieldRef;
import cz.proto.FieldSchema;
import cz.proto.MetadataEntity;
import java.util.*;
public class AcidSchemaConvert extends SchemaConvert {
@Override
public Schema convertToExternalSchema(MetadataEntity.Entity meta) {
List fields = meta.getTable().getTableSchema().getFieldsList();
List columns = new ArrayList<>();
List keyColumns = new ArrayList<>();
List sortColumns = new ArrayList<>();
Map fieldIndexMap = new HashMap<>();
for (FieldSchema field : fields) {
fieldIndexMap.put(field.getType().getFieldId(), field);
}
Set keyIndexSet = new LinkedHashSet<>();
for (FieldRef pkField : meta.getTable().getPrimaryKeySpec().getPrimaryKey().getFieldsList()) {
keyIndexSet.add(pkField.getFieldId());
}
columns.add(buildVirtualColumnSchema(Constant.VIRTUAL_BUCKET_KEY));
for (Integer keyIndex : keyIndexSet) {
columns.add(buildColumnSchema(fieldIndexMap.get(keyIndex), true));
keyColumns.add(buildColumnSchema(fieldIndexMap.get(keyIndex), true));
}
for (FieldSchema field : fields) {
if (!keyIndexSet.contains(field.getType().getFieldId())) {
columns.add(buildColumnSchema(field, false));
}
}
return new Schema(columns, keyColumns, sortColumns);
}
@Override
public Schema convertToExternalKeySchema(MetadataEntity.Entity meta) {
List fields = meta.getTable().getTableSchema().getFieldsList();
List columns = new ArrayList<>();
List keyColumns = new ArrayList<>();
List sortColumns = new ArrayList<>();
Map fieldIndexMap = new HashMap<>();
for (FieldSchema field : fields) {
fieldIndexMap.put(field.getType().getFieldId(), field);
}
Set keyIndexSet = new LinkedHashSet<>();
for (FieldRef pkField : meta.getTable().getPrimaryKeySpec().getPrimaryKey().getFieldsList()) {
keyIndexSet.add(pkField.getFieldId());
}
columns.add(buildVirtualColumnSchema(Constant.VIRTUAL_BUCKET_KEY));
for (Integer keyIndex : keyIndexSet) {
columns.add(buildColumnSchema(fieldIndexMap.get(keyIndex), false));
keyColumns.add(buildColumnSchema(fieldIndexMap.get(keyIndex), false));
}
return new Schema(columns, keyColumns, sortColumns);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy