Skip to content

Commit

Permalink
Merge pull request #35 from meta-d/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
meta-d authored Jul 5, 2024
2 parents dc33680 + fe764a4 commit 30eba29
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .deploy/api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ocap-server",
"author": "Metad",
"version": "2.4.2",
"version": "2.4.3",
"scripts": {
"start": "nx serve",
"build": "nx build",
Expand Down
6 changes: 3 additions & 3 deletions .deploy/k8s/ali-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ spec:
spec:
containers:
- name: metad-prod-api
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-api:2.4.1
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-api:2.4.2
# imagePullPolicy: Always
envFrom:
- secretRef:
Expand Down Expand Up @@ -233,7 +233,7 @@ spec:
spec:
containers:
- name: metad-prod-webapp
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-webapp:2.4.1
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-webapp:2.4.2
# imagePullPolicy: Always
ports:
- containerPort: 80
Expand Down Expand Up @@ -281,7 +281,7 @@ spec:
spec:
containers:
- name: metad-prod-olap
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-olap:2.4.1
image: registry.cn-hangzhou.aliyuncs.com/metad/ocap-olap:2.4.2
ports:
- containerPort: 8080
protocol: TCP
Expand Down
2 changes: 1 addition & 1 deletion .deploy/webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ocap",
"version": "2.4.2",
"version": "2.4.3",
"description": "",
"license": "AGPL-3.0",
"homepage": "https://mtda.cloud",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/adapter",
"version": "2.4.2",
"version": "2.4.3",
"dependencies": {
"@sap/hana-client": "^2.20.20",
"axios": "^0.21.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/analytics",
"version": "2.4.2",
"version": "2.4.3",
"type": "commonjs",
"license": "MIT",
"scripts": {
Expand Down
168 changes: 84 additions & 84 deletions packages/analytics/src/model/ocap/types.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
import { AgentType, ISemanticModel } from "@metad/contracts"
import { DataSourceOptions, Syntax } from "@metad/ocap-core"
import { isNil, omit } from "lodash"
import { SemanticModel } from "../../core/entities/internal"
import { NgmDSCoreService } from "./core.service"
import { AgentType, ISemanticModel } from '@metad/contracts'
import { DataSourceOptions, Syntax } from '@metad/ocap-core'
import { isNil, omit } from 'lodash'
import { SemanticModel } from '../../core/entities/internal'
import { NgmDSCoreService } from './core.service'

export const OCAP_AGENT_TOKEN = 'OCAP_AGENT_TOKEN'
export const OCAP_DATASOURCE_TOKEN = 'OCAP_DATASOURCE_TOKEN'
export const OCAP_MODEL_TOKEN = 'OCAP_MODEL_TOKEN'

export function getSemanticModelKey(model: ISemanticModel) {
return model.id
return model.id
}

export function registerModel(model: SemanticModel, dsCoreService: NgmDSCoreService) {
const modelKey = getSemanticModelKey(model)
const agentType = isNil(model.dataSource)
? AgentType.Wasm
: model.dataSource.useLocalAgent
? AgentType.Local
: AgentType.Server
const dialect =
model.dataSource?.type?.type === 'agent'
? 'sqlite'
: agentType === AgentType.Wasm
? 'duckdb'
: model.dataSource?.type?.type
const catalog = agentType === AgentType.Wasm ? model.catalog || 'main' : model.catalog
const semanticModel = {
...omit(model, 'indicators'),
name: modelKey,
catalog,
dialect,
agentType,
settings: {
dataSourceInfo: model.dataSource?.options?.data_source_info as string
} as any,
schema: {
...(model.options?.schema ?? {}),
indicators: model.indicators
}
} as DataSourceOptions
const modelKey = getSemanticModelKey(model)
const agentType = isNil(model.dataSource)
? AgentType.Wasm
: model.dataSource.useLocalAgent
? AgentType.Local
: AgentType.Server
const dialect =
model.dataSource?.type?.type === 'agent'
? 'sqlite'
: agentType === AgentType.Wasm
? 'duckdb'
: model.dataSource?.type?.type
const catalog = agentType === AgentType.Wasm ? model.catalog || 'main' : model.catalog
const semanticModel = {
...omit(model, 'indicators'),
key: modelKey,
catalog,
dialect,
agentType,
settings: {
dataSourceInfo: model.dataSource?.options?.data_source_info as string
} as any,
schema: {
...(model.options?.schema ?? {}),
indicators: model.indicators
}
} as DataSourceOptions

if (model.dataSource?.type?.protocol?.toUpperCase() === 'SQL') {
semanticModel.settings = semanticModel.settings
? { ...semanticModel.settings }
: {
ignoreUnknownProperty: true
}
semanticModel.settings.dataSourceId = model.dataSource.id
}
if (model.dataSource?.type?.protocol?.toUpperCase() === 'SQL') {
semanticModel.settings = semanticModel.settings
? { ...semanticModel.settings }
: {
ignoreUnknownProperty: true
}
semanticModel.settings.dataSourceId = model.dataSource.id
}

if (model.type === 'XMLA') {
semanticModel.syntax = Syntax.MDX
if (model.dataSource?.type?.protocol?.toUpperCase() === 'SQL') {
dsCoreService.registerModel({
...semanticModel,
/**
* Corresponding name of schema in olap engine:
* ```xml
* <root name="Semantic Model Name">
* <Cube name="Sales">
* ...
* ```
*/
catalog: model.name,
settings: {
...(semanticModel.settings ?? {}),
/**
* Corresponding id of XmlaConnection in olap engine:
*/
dataSourceInfo: model.id
} as any
})
} else {
dsCoreService.registerModel({
...semanticModel,
settings: {
...semanticModel.settings,
dataSourceInfo: model.dataSource?.options?.data_source_info
} as any
})
}
} else {
dsCoreService.registerModel({
...semanticModel,
syntax: Syntax.SQL,
settings: {
...semanticModel.settings,
dataSourceInfo: model.dataSource?.options?.data_source_info
} as any
})
}
if (model.type === 'XMLA') {
semanticModel.syntax = Syntax.MDX
if (model.dataSource?.type?.protocol?.toUpperCase() === 'SQL') {
dsCoreService.registerModel({
...semanticModel,
/**
* Corresponding name of schema in olap engine:
* ```xml
* <root name="Semantic Model Name">
* <Cube name="Sales">
* ...
* ```
*/
catalog: model.name,
settings: {
...(semanticModel.settings ?? {}),
/**
* Corresponding id of XmlaConnection in olap engine:
*/
dataSourceInfo: model.id
} as any
})
} else {
dsCoreService.registerModel({
...semanticModel,
settings: {
...semanticModel.settings,
dataSourceInfo: model.dataSource?.options?.data_source_info
} as any
})
}
} else {
dsCoreService.registerModel({
...semanticModel,
syntax: Syntax.SQL,
settings: {
...semanticModel.settings,
dataSourceInfo: model.dataSource?.options?.data_source_info
} as any
})
}

return semanticModel
}
return semanticModel
}
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/ocap-angular",
"version": "2.4.2",
"version": "2.4.3",
"keywords": [
"metad",
"ocap",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/server-auth",
"version": "2.4.2",
"version": "2.4.3",
"type": "commonjs",
"dependencies": {
"@nestjs/common": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/server-common",
"version": "2.4.2",
"version": "2.4.3",
"type": "commonjs",
"dependencies": {
"@nestjs/typeorm": "^8.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/server-config",
"version": "2.4.2",
"version": "2.4.3",
"type": "commonjs",
"dependencies": {
"@nestjs/common": "^8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/copilot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/copilot",
"version": "2.4.2",
"version": "2.4.3",
"peerDependencies": {
"@langchain/core": "0.2.5",
"ai": "^2.2.30",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/ocap-core",
"version": "2.4.2",
"version": "2.4.3",
"dependencies": {
"tslib": "^2.3.0"
},
Expand Down
34 changes: 20 additions & 14 deletions packages/core/src/lib/ds-core.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export interface DSState {
timeGranularity?: TimeGranularity
}

/**
* DataSource core store
*
*
*/
export class DSCoreService extends ComponentStore<DSState> {
public readonly timeGranularity$ = this.select((state) => state.timeGranularity)
public readonly currentTime$ = combineLatest([this.select((state) => state.today), this.timeGranularity$]).pipe(
Expand All @@ -29,13 +34,14 @@ export class DSCoreService extends ComponentStore<DSState> {
super({ dataSources })
}

public readonly registerModel = this.updater((state, model: DataSourceOptions) => {
registerModel = this.updater((state, model: DataSourceOptions) => {
// Backward compatibility
if (model.useLocalAgent) {
model.agentType = model.agentType ?? AgentType.Local
}

state.dataSources = state.dataSources ?? []
// Use `key` as primary to determine duplication
const index = state.dataSources.findIndex((item) => item.key === model.key)
if (index > -1) {
state.dataSources.splice(index, 1, model)
Expand All @@ -47,41 +53,41 @@ export class DSCoreService extends ComponentStore<DSState> {
/**
* @todo 共用 DataSource 对象
*
* @param name
* @param key The key of data source
* @returns
*/
getDataSource(name: string): Observable<DataSource> {
if (!this._dataSources.get(name)) {
getDataSource(key: string): Observable<DataSource> {
if (!this._dataSources.get(key)) {
this._dataSources.set(
name,
this.select((state) => state.dataSources?.find((item) => item.key === name || item.name === name)).pipe(
key,
this.select((state) => state.dataSources?.find((item) => item.key === key)).pipe(
filter((value) => !!value),
switchMap((options) => this.createDataSource(options)),
shareReplay(1)
)
)
}

return this._dataSources.get(name)
return this._dataSources.get(key)
}

/**
* New async method to get DataSource object
*
* @param name
* @param key
* @returns
*/
async _getDataSource(name: string): Promise<DataSource> {
if (!this.#dataSources.has(name)) {
const options = this.get((state) => state.dataSources?.find((item) => item.key === name || item.name === name))
async _getDataSource(key: string): Promise<DataSource> {
if (!this.#dataSources.has(key)) {
const options = this.get((state) => state.dataSources?.find((item) => item.key === key))
if (!options) {
throw new Error(`Can't found dataSource options: '${name}'`)
throw new Error(`Can't found dataSource options: '${key}'`)
}

this.#dataSources.set(name, await this.createDataSource(options))
this.#dataSources.set(key, await this.createDataSource(options))
}

return this.#dataSources.get(name)
return this.#dataSources.get(key)
}

private async createDataSource(options: DataSourceOptions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/duckdb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/ocap-duckdb",
"version": "2.4.2",
"version": "2.4.3",
"keywords": [
"metad",
"ocap",
Expand Down
2 changes: 1 addition & 1 deletion packages/echarts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/ocap-echarts",
"version": "2.4.2",
"version": "2.4.3",
"keywords": [
"metad",
"ocap",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metad/server-core",
"version": "2.4.2",
"version": "2.4.3",
"type": "commonjs",
"dependencies": {
"@casl/ability": "^5.4.3",
Expand Down
Loading

0 comments on commit 30eba29

Please sign in to comment.