Geometric Types

Handle PostgreSQL geometric and spatial data types.

Overview

PostgreSQL geometric types include:

  • Point: (x,y) coordinates

  • Line: Linear equations

  • Box: Rectangular boxes

  • Path: Connected points

  • Polygon: Closed paths

  • Circle: Center and radius

Geometric Type Support

TDK supports PostgreSQL geometric types through:

  1. Direct copying: Preserves geometric values

  2. Custom transformations: Modify geometric data

  3. Type conversion: Convert to/from text

Common Issues

Issue: Geometric Type Not Preserved

Symptom: Geometric values become NULL or corrupted.

Solution: Ensure JDBC driver supports geometric types:

data_sources:
  input:
    url: jdbc:postgresql://host:5432/db?geometryEnabled=true
    driver_class_name: org.postgresql.Driver

Issue: Cannot Transform Geometric Data

Symptom: "Cannot transform geometric type" errors.

Solution: Use scripting transformer for custom geometric transformations:

transformations:
  - columns: ["location"]  # POINT type
    type: Scripting
    config:
      script: |
        // Offset point by random amount
        if (location != null) {
          var parts = location.replace('(', '').replace(')', '').split(',');
          var x = parseFloat(parts[0]) + Math.random() * 0.01;
          var y = parseFloat(parts[1]) + Math.random() * 0.01;
          return '(' + x + ',' + y + ')';
        }
        return location;

PostGIS Spatial Types

For PostGIS extension (geography, geometry):

Enable PostGIS Support

-- Check PostGIS is installed
SELECT PostGIS_Version();

Preserve Spatial Data

table_schema:
  - table_name_pattern: "public.locations"
    transformations:
      - columns: ["geom"]  # geometry/geography column
        # Don't transform - preserve spatial data
        type: Preserve

Transform Spatial References

For masking while preserving spatial relationships:

transformations:
  - columns: ["geom"]
    type: Scripting
    config:
      script: |
        // Apply small random offset to coordinates
        // while preserving geometry type
        if (geom != null) {
          return ST_Translate(geom,
            Math.random() * 0.001,
            Math.random() * 0.001);
        }
        return geom;

Type Conversion

Convert to Text

For databases that don’t support geometric types:

-- In source database (PostgreSQL)
SELECT location::text as location_text
FROM places;
# Transform as text
transformations:
  - columns: ["location_text"]
    type: Preserve  # Keep as text

Convert from Text

In target database:

-- Convert text back to POINT
UPDATE places
SET location = location_text::POINT;