com.clickzetta.platform.test.MockMeta 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.test;
import cz.proto.*;
import cz.proto.ingestion.Ingestion;
import scala.Tuple2;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MockMeta {
private static final Map, Ingestion.IGSTableType> tableNameMaps = new HashMap<>();
private static final Map tableMetaMaps = new HashMap<>();
static {
// tableNameMaps
tableNameMaps.put(new Tuple2<>("mock-db", "mock-tbl-common"), Ingestion.IGSTableType.NORMAL);
tableNameMaps.put(new Tuple2<>("mock-db", "mock-tbl-cluster"), Ingestion.IGSTableType.CLUSTER);
tableNameMaps.put(new Tuple2<>("mock-db", "mock-tbl-pk"), Ingestion.IGSTableType.ACID);
// build common table schema & info.
tableMetaMaps.put(Ingestion.IGSTableType.NORMAL, MetadataEntity.Entity.newBuilder()
.setTable(TableMeta.newBuilder()
.setTableId(123)
.setTableType(TableType.MANAGED_TABLE)
.setTableSchema(
TableSchema.newBuilder()
.addFields(FieldSchema.newBuilder()
.setName("col1")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(false).setFieldId(1).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col2")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(true).setFieldId(2).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col3")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.STRING).setNullable(true).setFieldId(3).build())
.build()).build())
.build())
.build());
// build cluster table schema & info.
tableMetaMaps.put(Ingestion.IGSTableType.CLUSTER, MetadataEntity.Entity.newBuilder()
.setTable(TableMeta.newBuilder()
.setTableId(456)
.setTableType(TableType.MANAGED_TABLE)
.setTableSchema(
TableSchema.newBuilder()
.addFields(FieldSchema.newBuilder()
.setName("col1")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(false).setFieldId(1).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col2")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(true).setFieldId(2).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col3")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.STRING).setNullable(true).setFieldId(3).build())
.build()).build())
.addClusterInfoSpec(0,
FieldSpec.newBuilder().setClusterInfo(
ClusterInfo.newBuilder().setClusterType(ClusterType.HASH).setBucketsCount(2)
.addClusteredFields(0, FieldRef.newBuilder().setFieldId(1).build()).build())
.build())
.build())
.build());
// build pk table schema & info.
tableMetaMaps.put(Ingestion.IGSTableType.ACID, MetadataEntity.Entity.newBuilder()
.setTable(TableMeta.newBuilder()
.setTableId(789)
.setTableType(TableType.MANAGED_TABLE)
.setTableSchema(
TableSchema.newBuilder()
.addFields(FieldSchema.newBuilder()
.setName("col1")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(false).setFieldId(1).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col2")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.INT32).setNullable(true).setFieldId(2).build())
.build())
.addFields(FieldSchema.newBuilder()
.setName("col3")
.setType(DataType.newBuilder().setCategory(DataTypeCategory.STRING).setNullable(true).setFieldId(3).build())
.build()).build())
.addClusterInfoSpec(0,
FieldSpec.newBuilder().setClusterInfo(
ClusterInfo.newBuilder().setClusterType(ClusterType.HASH).setBucketsCount(2)
.addClusteredFields(0, FieldRef.newBuilder().setFieldId(1).build()).build())
.build())
.setPrimaryKeySpec(FieldSpec.newBuilder().setPrimaryKey(
PrimaryKey.newBuilder().addFields(0, FieldRef.newBuilder().setFieldId(1).build()).build())
.build())
.build())
.build());
}
public static MetadataEntity.Entity getTableMeta(Ingestion.IGSTableType tableType) {
return tableMetaMaps.get(tableType);
}
public static Ingestion.IGSTableType getTableType(String dbName, String tblName) {
return tableNameMaps.get(new Tuple2<>(dbName, tblName));
}
public static Tuple2 getTableNameByType(Ingestion.IGSTableType tableType) {
Tuple2 tuple2 = null;
for (Map.Entry, Ingestion.IGSTableType> entry : tableNameMaps.entrySet()) {
if (entry.getValue() == tableType) {
tuple2 = entry.getKey();
break;
}
}
return tuple2;
}
public static List getAllIGSTableTypes() {
return new ArrayList() {{
add(Ingestion.IGSTableType.NORMAL);
add(Ingestion.IGSTableType.CLUSTER);
add(Ingestion.IGSTableType.ACID);
}};
}
public static List> getAllTables() {
return new ArrayList<>(tableNameMaps.keySet());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy