-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: respect iox::column_type::field metadata when mapping query (#491)
- Loading branch information
1 parent
ecfcf06
commit 5e663bb
Showing
10 changed files
with
347 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const CLIENT_LIB_VERSION = '0.12.0' | ||
export const CLIENT_LIB_VERSION = '1.0.0' | ||
export const CLIENT_LIB_USER_AGENT = `influxdb3-js/${CLIENT_LIB_VERSION}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {Field} from 'apache-arrow' | ||
import {isNumber, isUnsignedNumber} from './common' | ||
import {Type as ArrowType} from 'apache-arrow/enum' | ||
|
||
/** | ||
* Function to cast value return base on metadata from InfluxDB. | ||
* | ||
* @param field the Field object from Arrow | ||
* @param value the value to cast | ||
* @return the value with the correct type | ||
*/ | ||
export function getMappedValue(field: Field, value: any): any { | ||
if (value === null || value === undefined) { | ||
return null | ||
} | ||
|
||
const metaType = field.metadata.get('iox::column::type') | ||
|
||
if (!metaType || field.typeId === ArrowType.Timestamp) { | ||
return value | ||
} | ||
|
||
const [, , valueType, _fieldType] = metaType.split('::') | ||
|
||
if (valueType === 'field') { | ||
switch (_fieldType) { | ||
case 'integer': | ||
if (isNumber(value)) { | ||
return parseInt(value) | ||
} | ||
console.warn(`Value ${value} is not an integer`) | ||
return value | ||
case 'uinteger': | ||
if (isUnsignedNumber(value)) { | ||
return parseInt(value) | ||
} | ||
console.warn(`Value ${value} is not an unsigned integer`) | ||
return value | ||
case 'float': | ||
if (isNumber(value)) { | ||
return parseFloat(value) | ||
} | ||
console.warn(`Value ${value} is not a float`) | ||
return value | ||
case 'boolean': | ||
if (typeof value === 'boolean') { | ||
return value | ||
} | ||
console.warn(`Value ${value} is not a boolean`) | ||
return value | ||
case 'string': | ||
if (typeof value === 'string') { | ||
return String(value) | ||
} | ||
console.warn(`Value ${value} is not a string`) | ||
return value | ||
default: | ||
return value | ||
} | ||
} | ||
|
||
return value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.