Skip to content

Commit

Permalink
Merge pull request #36 from GreptimeTeam/fix/data-types
Browse files Browse the repository at this point in the history
fix(result):  support all number and date data-types
  • Loading branch information
ZonaHex authored Dec 9, 2022
2 parents 3322a43 + 2d3664b commit f094eec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/store/modules/code-run/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { getSqlResult } from '@/api/editor'
import { Message } from '@arco-design/web-vue'
import { defineStore } from 'pinia'
import { dateTypes } from '@/views/dashboard/data-explorer/components/data-view/config'

const TYPE_MAP: any = {
Timestamp: 'time',
String: 'ordinal',
Float64: 'float',
Int: 'int',
}
// TODO: Add all the types we decide instead of ECharts if needed in the future.
// const TYPE_MAP: any = {
// Timestamp: 'time',
// String: 'ordinal',
// Float64: 'float',
// Int: 'int',
// }

const getDimensionsAndXName = (elements: any) => {
const tempDimensions: any = []
let xAxisName = ''
let findTimeFlag = false
elements.forEach((element: any) => {
if (!findTimeFlag && element.data_type === 'Timestamp') {
if (!findTimeFlag && dateTypes.find((type: string) => type === element.data_type)) {
findTimeFlag = true
xAxisName = element.name
}
const oneDimension = {
name: element.name,
type: TYPE_MAP[element.data_type] || 'ordinal',
// Note: let ECharts decide type for now.
// type: TYPE_MAP[element.data_type] || 'ordinal',
}

tempDimensions.push(oneDimension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ a-spin(style="width: 100%")
</template>

<script lang="ts" setup>
import { chartTypeOptions, updateOptions } from '../config'
import { chartTypeOptions, updateOptions, numberTypes } from '../config'
const { currentResult } = storeToRefs(useCodeRunStore())
const option = ref({})
Expand All @@ -23,9 +23,10 @@ a-spin(style="width: 100%")
ySelectedTypes: [],
})
// TODO: Add support for more data types not just numbers.
const yOptions = computed(() => {
return currentResult.value.schema.column_schemas
.filter((item: any) => item.data_type === 'Int' || item.data_type === 'Float64')
.filter((item: any) => numberTypes.find((type: string) => type === item.data_type))
.map((item: any) => ({
value: item.name,
}))
Expand Down
15 changes: 15 additions & 0 deletions src/views/dashboard/data-explorer/components/data-view/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ export const chartTypeOptions: any = [
},
]
export const updateOptions = { notMerge: true }

export const numberTypes = [
'Int8',
'Int16',
'Int32',
'Int64',
'UInt8',
'UInt16',
'UInt32',
'UInt64',
'Float32',
'Float64',
]

export const dateTypes = ['Date', 'DateTime', 'Timestamp']

0 comments on commit f094eec

Please sign in to comment.