[Core] [DataSet] Support sampling key

This commit is contained in:
qianmoQ 2024-02-21 17:23:53 +08:00
parent 2deb5056b0
commit 155cf6e5a5
3 changed files with 14 additions and 0 deletions

View File

@ -394,6 +394,7 @@ public class DataSetServiceImpl
TableBuilder.Companion.ORDER_BY(columnEntities.stream().filter(DataSetColumnEntity::isOrderByKey).map(DataSetColumnEntity::getName).collect(Collectors.toList()));
TableBuilder.Companion.PARTITION_BY(columnEntities.stream().filter(DataSetColumnEntity::isPartitionKey).map(DataSetColumnEntity::getName).collect(Collectors.toList()));
TableBuilder.Companion.PRIMARY_KEY(columnEntities.stream().filter(DataSetColumnEntity::isPrimaryKey).map(DataSetColumnEntity::getName).collect(Collectors.toList()));
TableBuilder.Companion.SAMPLING_KEY(columnEntities.stream().filter(DataSetColumnEntity::isSamplingKey).map(DataSetColumnEntity::getName).collect(Collectors.toList()));
String sql = TableBuilder.Companion.SQL();
log.info("Create table sql \n {} \n on dataset [ {} ]", sql, entity.getName());

View File

@ -163,6 +163,11 @@ abstract class AbstractSql<T> {
return getSelf()
}
fun SAMPING_KEY(columns: List<String>): T {
sql().samplingKey.addAll(columns.map { item -> "\t$item" })
return getSelf()
}
fun FROM(table: String?): T {
sql().tables.add(table)
return getSelf()
@ -533,6 +538,7 @@ abstract class AbstractSql<T> {
var orderByKey: MutableList<String?> = ArrayList()
val partitionByKey: MutableList<String?> = ArrayList()
val primaryKey: MutableList<String?> = ArrayList()
val samplingKey: MutableList<String?> = ArrayList()
init {
// Prevent Synthetic Access
@ -688,6 +694,9 @@ abstract class AbstractSql<T> {
if (primaryKey.isNotEmpty()) {
sqlClause(builder, "PRIMARY KEY", primaryKey, "(", ")", ", ")
}
if (samplingKey.isNotEmpty()) {
sqlClause(builder, "SAMPLE BY", samplingKey, "(", ")", ", ")
}
if (end) {
builder.append(";")
}

View File

@ -46,6 +46,10 @@ class TableBuilder {
sql().PRIMARY_KEY(values)
}
fun SAMPLING_KEY(values: List<String>) {
sql().SAMPING_KEY(values)
}
fun END() {
sql().END()
}