2025-03-26 07:11:14 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert from rich to primitive types.
|
|
|
|
|
*
|
|
|
|
|
* @import {DecodedArray, SchemaElement} from 'hyparquet'
|
|
|
|
|
* @param {SchemaElement} schemaElement
|
|
|
|
|
* @param {DecodedArray} values
|
|
|
|
|
* @returns {DecodedArray}
|
|
|
|
|
*/
|
|
|
|
|
export function unconvert(schemaElement, values) {
|
|
|
|
|
const ctype = schemaElement.converted_type
|
|
|
|
|
if (ctype === 'DATE') {
|
|
|
|
|
return values.map(v => v.getTime())
|
|
|
|
|
}
|
|
|
|
|
if (ctype === 'JSON') {
|
|
|
|
|
if (!Array.isArray(values)) throw new Error('JSON must be an array')
|
2025-03-26 07:45:22 +00:00
|
|
|
const encoder = new TextEncoder()
|
2025-03-26 07:11:14 +00:00
|
|
|
return values.map(v => encoder.encode(JSON.stringify(v)))
|
|
|
|
|
}
|
2025-03-26 07:45:22 +00:00
|
|
|
if (ctype === 'UTF8') {
|
|
|
|
|
if (!Array.isArray(values)) throw new Error('strings must be an array')
|
|
|
|
|
const encoder = new TextEncoder()
|
|
|
|
|
return values.map(v => encoder.encode(v))
|
|
|
|
|
}
|
2025-03-26 07:11:14 +00:00
|
|
|
return values
|
|
|
|
|
}
|