Skip to content

Commit

Permalink
Add support for time and date columns in BigQuery,
Browse files Browse the repository at this point in the history
MSSQL, MySQL, and Postgres capabilities
  • Loading branch information
MXPOL committed Dec 5, 2023
1 parent 642a273 commit b936c8a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
2 changes: 2 additions & 0 deletions libs/external-db-bigquery/src/bigquery_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export const ColumnsCapabilities = {
image: { sortable: false, columnQueryOperators: [] },
object: { sortable: false, columnQueryOperators: [] },
datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
}
33 changes: 21 additions & 12 deletions libs/external-db-mssql/src/sql_schema_translator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ describe('Sql Schema Column Translator', () => {
})

describe('string fields', () => {
test('string', () => {
expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`)
})

test.each([
'string',
'richcontent',
'image',
'video',
'audio',
'document',
'language',
])('text %s', (subtype) => {
expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2048)`)
})

test('string with length', () => {
expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'string', precision: '2055' }) ).toEqual(`${escapeId(ctx.fieldName)} VARCHAR(2055)`)
Expand All @@ -86,12 +95,6 @@ describe('Sql Schema Column Translator', () => {
test('text large', () => {
expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'large' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`)
})

test('text language', () => {
expect( env.schemaTranslator.columnToDbColumnSql({ name: ctx.fieldName, type: 'text', subtype: 'language' }) ).toEqual(`${escapeId(ctx.fieldName)} TEXT`)
})


})

describe('other fields', () => {
Expand Down Expand Up @@ -127,10 +130,16 @@ describe('Sql Schema Column Translator', () => {
})

describe('date time fields', () => {
test('time', () => {
expect( env.schemaTranslator.translateType('TIME') ).toEqual('time')
})

test('date', () => {
['DATE', 'DATETIME', 'DATETIME2', 'TIME', 'DATETIMEOFFSET', 'SMALLDATETIME'].forEach(t => {
expect( env.schemaTranslator.translateType(t) ).toEqual('datetime')
})
expect( env.schemaTranslator.translateType('DATE') ).toEqual('date')
})

test.each([ 'DATETIME', 'DATETIME2', 'DATETIMEOFFSET', 'SMALLDATETIME'])('%s', (t) => {
expect( env.schemaTranslator.translateType(t) ).toEqual('datetime')
})
})

Expand Down
14 changes: 11 additions & 3 deletions libs/external-db-mssql/src/sql_schema_translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ export default class SchemaColumnTranslator {
case 'decimal':
case 'numeric':
return 'number'


case 'time':
return 'time'
case 'date':
return 'date'

case 'datetime':
case 'datetime2':
case 'time':
case 'datetimeoffset':
case 'smalldatetime':
return 'datetime'
Expand Down Expand Up @@ -83,12 +86,17 @@ export default class SchemaColumnTranslator {
return 'SMALLDATETIME'

case 'text_string':
case 'text_richcontent':
case 'text_image':
case 'text_video':
case 'text_audio':
case 'text_document':
case 'text_language':
return `VARCHAR${this.parseLength(precision)}`

case 'text_small':
case 'text_medium':
case 'text_large':
case 'text_language':
return 'TEXT'


Expand Down
2 changes: 2 additions & 0 deletions libs/external-db-mysql/src/mysql_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export const ColumnsCapabilities = {
image: { sortable: false, columnQueryOperators: [] },
object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] },
datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
}
2 changes: 2 additions & 0 deletions libs/external-db-postgres/src/postgres_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export const ColumnsCapabilities = {
image: { sortable: false, columnQueryOperators: [] },
object: { sortable: false, columnQueryOperators: [eq, ne, string_contains, string_begins, string_ends, include, gt, gte, lt, lte] },
datetime: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
time: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
date: { sortable: true, columnQueryOperators: [eq, ne, gt, gte, lt, lte] },
}

0 comments on commit b936c8a

Please sign in to comment.