Skip to content

Commit

Permalink
[Core] [DataSet] Support primary key (close #624)
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ committed Feb 2, 2024
1 parent cb07171 commit fe3ed40
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/datacap-server/src/main/schema/2024.02.1/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# If you are upgrading to 2024.02.1 from a different version, execute the following SQL statement
# Если вы обновляетесь до версии 2024.02.1 с другой версии, выполните следующую инструкцию SQL
# 如果您是通过其他版本升级到 2024.02.1, 请执行以下 SQL 语句

USE `datacap`;

ALTER TABLE `datacap_dataset_column`
ADD COLUMN `is_primary_key` VARCHAR(100) DEFAULT FALSE;
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class DataSetColumnEntity
@Column(name = "is_partition_key")
private boolean partitionKey;

@Column(name = "is_primary_key")
private boolean primaryKey;

@Column(name = "column_mode")
@Enumerated(EnumType.STRING)
private ColumnMode mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ private void createTable(DataSetEntity entity)
TableBuilder.Companion.ENGINE(tableDefaultEngine);
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()));
String sql = TableBuilder.Companion.SQL();
log.info("Create table sql \n {} \n on dataset [ {} ]", sql, entity.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ abstract class AbstractSql<T> {
return getSelf()
}

fun PRIMARY_KEY(columns: List<String>): T {
sql().primaryKey.addAll(columns.map { item -> "\t$item" })
return getSelf()
}

fun FROM(table: String?): T {
sql().tables.add(table)
return getSelf()
Expand Down Expand Up @@ -527,6 +532,7 @@ abstract class AbstractSql<T> {
var engine: String? = null
var orderByKey: MutableList<String?> = ArrayList()
val partitionByKey: MutableList<String?> = ArrayList()
val primaryKey: MutableList<String?> = ArrayList()

init {
// Prevent Synthetic Access
Expand Down Expand Up @@ -679,6 +685,9 @@ abstract class AbstractSql<T> {
if (partitionByKey.isNotEmpty()) {
sqlClause(builder, "PARTITION BY", partitionByKey, "(", ")", ", ")
}
if (primaryKey.isNotEmpty()) {
sqlClause(builder, "PRIMARY KEY", primaryKey, "(", ")", ", ")
}
if (end) {
builder.append(";")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class TableBuilder {
sql().PARTITION_BY_KEY(values)
}

fun PRIMARY_KEY(values: List<String>) {
sql().PRIMARY_KEY(values)
}

fun END() {
sql().END()
}
Expand Down
1 change: 1 addition & 0 deletions core/datacap-web/src/i18n/langs/en/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
columnLength: 'Length',
columnIsOrderByKey: 'Sort key',
columnIsPartitionKey: 'Partition key',
columnIsPrimaryKey: 'Primary key',
columnExpression: 'Expression',
columnMode: 'Column Mode',
columnModeMetric: 'Metric',
Expand Down
1 change: 1 addition & 0 deletions core/datacap-web/src/i18n/langs/zhCn/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
columnLength: '列长度',
columnIsOrderByKey: '排序键',
columnIsPartitionKey: '分区键',
columnIsPrimaryKey: '主键',
columnExpression: '表达式',
columnMode: '列模式',
columnModeMetric: '指标',
Expand Down
5 changes: 5 additions & 0 deletions core/datacap-web/src/views/admin/dataset/DatasetInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<Col class="w100 center">{{ $t('dataset.columnIsNullable') }}</Col>
<Col class="w100 center">{{ $t('dataset.columnIsOrderByKey') }}</Col>
<Col class="w100 center">{{ $t('dataset.columnIsPartitionKey') }}</Col>
<Col class="w100 center">{{ $t('dataset.columnIsPrimaryKey') }}</Col>
<Col class="w100 center">{{ $t('dataset.columnLength') }}</Col>
<Col class="w200">{{ $t('dataset.columnComment') }}</Col>
</Row>
Expand Down Expand Up @@ -89,6 +90,9 @@
<Col class="w100 center">
<Switch v-model="item.partitionKey"/>
</Col>
<Col class="w100 center">
<Switch v-model="item.primaryKey"/>
</Col>
<Col class="w100 center">
<InputNumber v-model="item.length"
min="0"
Expand Down Expand Up @@ -281,6 +285,7 @@ export default defineComponent({
original: header,
orderByKey: false,
partitionKey: false,
primaryKey: false,
mode: 'DIMENSION'
}
this.formState.columns.push(column)
Expand Down

0 comments on commit fe3ed40

Please sign in to comment.