@@ -453,12 +453,15 @@ export function arrowSchemaToFields(
453453 let analyzerType = arrowDataTypeToAnalyzerDataType ( field . type ) ;
454454 let format = '' ;
455455
456+ const fieldTypeSuggestion = fieldTypeSuggestions [ field . name ] ;
457+ const keplerField = keplerFields [ fieldIndex ] ;
458+
456459 // geometry fields produced by DuckDB's st_asgeojson()
457- if ( fieldTypeSuggestions [ field . name ] === 'JSON' ) {
460+ if ( fieldTypeSuggestion === 'JSON' ) {
458461 type = ALL_FIELD_TYPES . geojson ;
459462 analyzerType = AnalyzerDATA_TYPES . GEOMETRY_FROM_STRING ;
460463 } else if (
461- fieldTypeSuggestions [ field . name ] === 'GEOMETRY' ||
464+ fieldTypeSuggestion === 'GEOMETRY' ||
462465 field . metadata . get ( GEOARROW_METADATA_KEY ) ?. startsWith ( 'geoarrow' )
463466 ) {
464467 type = ALL_FIELD_TYPES . geoarrow ;
@@ -467,7 +470,7 @@ export function arrowSchemaToFields(
467470 type = ALL_FIELD_TYPES . geoarrow ;
468471 analyzerType = AnalyzerDATA_TYPES . GEOMETRY ;
469472 field . metadata ?. set ( GEOARROW_METADATA_KEY , geoArrowMetadata [ field . name ] ) ;
470- } else if ( fieldTypeSuggestions [ field . name ] === 'BLOB' ) {
473+ } else if ( fieldTypeSuggestion === 'BLOB' ) {
471474 // When arrow wkb column saved to DuckDB as BLOB without any metadata, then queried back
472475 try {
473476 const data = table . getChildAt ( fieldIndex ) ?. get ( 0 ) ;
@@ -482,10 +485,18 @@ export function arrowSchemaToFields(
482485 } catch ( error ) {
483486 // ignore, not WKB
484487 }
488+ } else if (
489+ fieldTypeSuggestion === 'VARCHAR' &&
490+ ( keplerField . analyzerType === AnalyzerDATA_TYPES . GEOMETRY ||
491+ keplerField . analyzerType === AnalyzerDATA_TYPES . GEOMETRY_FROM_STRING )
492+ ) {
493+ // When wkb/wkt was saved as varchar in DuckDB
494+ type = keplerField . type ;
495+ analyzerType = keplerField . analyzerType ;
496+ format = keplerField . format ;
485497 } else {
486498 // TODO should we use Kepler getFieldsFromData instead
487499 // of arrowDataTypeToFieldType for all fields?
488- const keplerField = keplerFields [ fieldIndex ] ;
489500 if ( keplerField . type === ALL_FIELD_TYPES . timestamp ) {
490501 type = keplerField . type ;
491502 analyzerType = keplerField . analyzerType ;
0 commit comments