Skip to content

Commit

Permalink
Add main table in online query mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tobegit3hub committed Jan 4, 2024
1 parent 6dff3f0 commit 57eab0a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 25 deletions.
49 changes: 45 additions & 4 deletions frontend/src/components/featureservice/OnlineQueryModePage.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<template>
<a-drawer
v-model:visible="isOpenTableDrawer"
size="large"
:title="$t('Table') + $t('Detail')">
<TableDetail :db="currentDrawerDatabase" :name="currentDrawerTable" :key="currentDrawerDatabase+currentDrawerTable"></TableDetail>
</a-drawer>

<div>

Expand All @@ -7,9 +13,11 @@
<a-descriptions-item :span="24" :label="$t('Name')">{{ name }}</a-descriptions-item>
<a-descriptions-item :span="24" :label="$t('Version')"> {{ version }}</a-descriptions-item>
<a-descriptions-item :span="24" :label="$t('Feature Names')">{{ featureNames }}</a-descriptions-item>

<a-descriptions-item :span="24" :label="$t('Feature Table')">
<a-button type="link" @click="openTableDrawer(mainTable.database, mainTable.table)">{{ mainTable.database + "." + mainTable.table }}</a-button>
</a-descriptions-item>
</a-descriptions>

<br/>
<!-- Test form -->
<a-form :model="formState"
Expand Down Expand Up @@ -61,8 +69,13 @@
<script>
import axios from 'axios'
import { notification } from 'ant-design-vue'
import TableDetail from '@/components/table/TableDetail.vue'
export default {
components: {
TableDetail
},
props: {
name: {
type: String,
Expand All @@ -77,7 +90,13 @@
data() {
return {
featureNames: null,
mainTable: {},
isOpenTableDrawer: false,
currentDrawerDatabase: "",
currentDrawerTable: "",
formState: {
chooseColumnNames: [],
Expand All @@ -101,6 +120,7 @@
methods: {
init() {
axios.get(`/api/featureservices/${this.name}/${this.version}`)
.then(response => {
this.featureNames = response.data.featureNames;
Expand All @@ -116,9 +136,24 @@
description: errorMessage
});
})
axios.get(`/api/featureservices/${this.name}/${this.version}/maintable`)
.then(response => {
this.mainTable = response.data;
})
.catch(error => {
var errorMessage = error.message;
if (error.response && error.response.data) {
errorMessage = error.response.data;
}
notification["error"]({
message: this.$t('Execute Fail'),
description: errorMessage
});
})
axios.get(`/api/featureservices/${this.name}/${this.version}/indexes`)
axios.get(`/api/featureservices/${this.name}/${this.version}/indexes`)
.then(response => {
this.allIndexColumnNamesList = response.data;
})
Expand Down Expand Up @@ -164,6 +199,12 @@
this.formInputColumns = this.mainTableColumns.filter(item => columnNameList.includes(item.name));
},
openTableDrawer(db, table) {
this.isOpenTableDrawer = true;
this.currentDrawerDatabase = db;
this.currentDrawerTable = table;
},
submitForm() {
var requestJson = {}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/importdata/ImportDataMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
<router-link to='/developprocess/import/offline'>{{ $t('Import Offline Data')}}</router-link>
</a-menu-item>

<!--
<a-menu-item key="5">
<router-link to='/developprocess/import/index'>{{ $t('Add Index')}}</router-link>
</a-menu-item>
-->

</a-menu>

<router-view></router-view>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
"Add Index": "Add Index",
"Request Feature Service": "Request Feature Service",
"Choose Index": "Choose Index",
"Online Query Feature Result": "Online Query Feature Result"
"Online Query Feature Result": "Online Query Feature Result",
"Feature Table": "Feature Table"

}
3 changes: 2 additions & 1 deletion frontend/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
"Add Index": "添加索引",
"Request Feature Service": "请求特征服务",
"Choose Index": "选择索引",
"Online Query Feature Result": "在线查询特征结果"
"Online Query Feature Result": "在线查询特征结果",
"Feature Table": "特征表"

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com._4paradigm.openmldb.featureplatform.controller;

import com._4paradigm.openmldb.featureplatform.dao.model.DatabaseTable;
import com._4paradigm.openmldb.featureplatform.service.FeatureServiceService;
import com._4paradigm.openmldb.featureplatform.dao.model.FeatureService;
import com._4paradigm.openmldb.featureplatform.dao.model.UpdateLatestVersionRequest;
Expand Down Expand Up @@ -278,5 +279,15 @@ public ResponseEntity<List<String>> getIndexNames(@PathVariable String name, @Pa
}
}

@GetMapping("/{name}/{version}/maintable")
public ResponseEntity<DatabaseTable> getMainTable(@PathVariable String name, @PathVariable String version) throws SQLException {
try {
return new ResponseEntity<>(featureServiceService.getMainTable(name, version), HttpStatus.OK);
} catch (SQLException e) {
logger.info(String.format("Call getRequestSchema with %s and %s but get exception: %s", name, version, e.getMessage()));
throw new SQLException(e.getMessage());
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com._4paradigm.openmldb.featureplatform.dao.model;

import lombok.Data;

@Data
public class DatabaseTable {

private String database;
private String table;

public DatabaseTable() {
}

public DatabaseTable(String database, String table) {
this.database = database;
this.table = table;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,30 +373,39 @@ public List<List<String>> requestOnlineQueryMode(String name, String version, St

String querySql = OpenmldbSqlUtil.removeDeployFromSql(deploymentSql);

Schema schema = OpenmldbTableUtil.getMainTableSchema(sqlExecutor, querySql, db);

Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(requestData, JsonObject.class);
JsonArray dataJsonArray = jsonObject.getAsJsonArray("data");
JsonArray indexJsonArray = jsonObject.getAsJsonArray("index");

// TODO: Support only one index now
String indexName = indexJsonArray.get(0).getAsString();
String indexDataValue = dataJsonArray.getAsJsonArray().get(0).getAsString();
// TODO: Only Support one row, need to support 'select * from t1 where (name, gender) in (("tobe", "male"))'

boolean isIndexStringType = false;
for (Column column: schema.getColumnList()) {
if (column.getColumnName().equals(indexName)) {
if(column.getSqlType() == Types.CHAR || column.getSqlType() == Types.VARCHAR) {
isIndexStringType = true;
}
List<String> indexNames = new ArrayList<>();
for (JsonElement element: indexJsonArray) {
indexNames.add(element.getAsString());
}

List<String> indexDataValues = new ArrayList<>();


for (JsonElement dataElement : dataJsonArray) {
JsonArray innerArray = dataElement.getAsJsonArray();

for (JsonElement innerElement : innerArray) {
indexDataValues.add(innerElement.getAsString());
}
}

String finalSql = String.format("%s WHERE %s = %s", querySql, indexName, indexDataValue);
if (isIndexStringType) {
// TODO: Handle single quote and double quote
finalSql = String.format("%s WHERE %s = '%s'", querySql, indexName, indexDataValue);
String finalSql = querySql;
for (int i=0; i<indexNames.size(); ++i) {

if (i == 0) {
// TODO: Handle single quote and double quote
finalSql += String.format(" WHERE %s = '%s'", indexNames.get(i), indexDataValues.get(i));
} else {
finalSql += String.format(" AND %s = '%s'", indexNames.get(i), indexDataValues.get(i));
}

}

Statement statement = sqlExecutor.getStatement();
Expand All @@ -413,7 +422,6 @@ public List<List<String>> requestOnlineQueryMode(String name, String version, St
resultSet.close();

return returnList;

}

public List<String> getIndexNames(String name, String version) throws SQLException {
Expand Down Expand Up @@ -547,4 +555,14 @@ public Schema getOutputSchema(String serviceName) throws SQLException {
String latestVersion = getLatestVersion(serviceName);
return getOutputSchema(serviceName, latestVersion);
}

public DatabaseTable getMainTable(String name, String version) throws SQLException {
FeatureService featureService = getFeatureServiceByNameAndVersion(name, version);
String sql = featureService.getSql();
String db = featureService.getDb();

String selectSql = OpenmldbSqlUtil.removeDeployFromSql(sql);

return OpenmldbTableUtil.getMainTable(sqlExecutor, selectSql, db);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public List<List<String>> executeOnlineSql(String sql, String sparkConfig) throw
}

String lastSql = sqls[sqls.length - 1].trim();
if (lastSql.isEmpty()) {
if (lastSql.isEmpty() && sqls.length >= 2) {
lastSql = sqls[sqls.length - 2].trim();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com._4paradigm.openmldb.featureplatform.utils;

import com._4paradigm.openmldb.common.Pair;
import com._4paradigm.openmldb.featureplatform.dao.model.DatabaseTable;
import com._4paradigm.openmldb.sdk.Schema;
import com._4paradigm.openmldb.sdk.impl.SqlClusterExecutor;

Expand Down Expand Up @@ -52,4 +53,13 @@ public static String getMainTableName(SqlClusterExecutor sqlExecutor, String sql
return mainTable;
}

public static DatabaseTable getMainTable(SqlClusterExecutor sqlExecutor, String sql, String db) throws SQLException {
List<Pair<String, String>> tables = SqlClusterExecutor.getDependentTables(sql, db,
OpenmldbTableUtil.getSystemSchemaMaps(sqlExecutor));

Pair<String, String> mainTablePair = tables.get(0);

return new DatabaseTable(mainTablePair.getKey(), mainTablePair.getValue());
}

}

0 comments on commit 57eab0a

Please sign in to comment.