ossie icon indicating copy to clipboard operation
ossie copied to clipboard

Add datatype field to Field and Metric; reframe is_time as role marker

Open jonmmease opened this issue 7 months ago • 13 comments

AI Disclosure: I developed this PR and its description iteratively with Claude Code and Codex, and have reviewed the resulting changes fully.

Motivation

Closes #84. Related to #17 and follows the earlier discussion in #25.

The issue originally framed this as “use datatype rather than is_time.” After reviewing existing semantic-layer implementations, the cleaner model is to represent logical data type and temporal role independently:

  • datatype says what values a field or metric produces.
  • dimension.is_time says whether a field plays a temporal-dimension role.

For example, d_year, d_quarter_name, and d_month_name may have integer data types while all serving temporal roles. Snowflake Semantic Views and LookML similarly separate scalar representation from temporal classification.

So, this PR adds datatype alongside is_time, then carries that metadata through the Python bindings and existing converter paths that have native type information.

What changes

Core specification

Adds an optional top-level datatype property to both Field and Metric, backed by the following logical data types:

  • String
  • Integer
  • Decimal
  • Float
  • Boolean
  • Date
  • Time
  • DateTime
  • DateTimeTz
  • Opaque

The shared names align with the ontology specification’s built-in value types where possible. Time, DateTimeTz, and Opaque are additional types. I think these would make sense as ontology value types as well, but this PR doesn't modify the ontology’s layer.

The JSON Schema defines the authoritative DataType enum. Until the YAML specification is generated from JSON, spec.yaml mirrors the same enum explicitly.

Temporal role semantics

dimension.is_time remains valid and is documented as independent of datatype.

For fields with a dimension block:

  1. An explicit is_time value wins.
  2. When is_time is unset, it defaults to true for Date, Time, DateTime, and DateTimeTz, and to false otherwise.

A field without dimension metadata remains a fact regardless of its datatype. This supports combinations like:

  • datatype: Integer with is_time: true for a year grain.
  • datatype: DateTimeTz with is_time: false for a timestamp that should not be exposed as a time dimension.
  • is_time: true without datatype for legacy models that know the role but do not declare a scalar type.

Python bindings

  • Adds and exports OSIDataType.
  • Adds optional datatype fields to OSIField and OSIMetric.
  • Adds OSIField.is_time_dimension() to implement the effective temporal-role rule.
  • Tests keep the Python enum synchronized with the core JSON Schema.

Existing converters

I updated the existing converters to propagate data types where it looked unambiguous. Here tagging some folks who have worked on the various converters for visibility.

  • @sfc-gh-tgao — Snowflake
  • @jaceksan — GoodData
  • @jbonofre — Polaris
  • @deutschn — Salesforce

jonmmease avatar Apr 24 '26 19:04 jonmmease

Hi @jonmmease !

Thanks for your work on this PR! Some comments on this PR based on comments and discussions we have opened in regards of including spatial semantics in the OSI spec:

  • https://github.com/open-semantic-interchange/OSI/discussions/114
  • https://github.com/open-semantic-interchange/OSI/issues/84

On geometry and geography as first-class datatype values

We'd like to make the case for adding geometry and geography to the datatype enum rather than leaving spatial columns to fall through to other.

Both are first-class native types in the leading cloud data warehouses:

  • Snowflake: GEOGRAPHY and GEOMETRY
  • BigQuery: GEOGRAPHY (WGS84 point/line/polygon)
  • Databricks: GEOMETRY
  • PostGIS: geometry and geography

The geometry / geography distinction is also meaningful and standardized (OGC/ISO SQL): geography operates on a spherical earth model with real-world units, while geometry operates on a flat Cartesian plane. Consumers need to know which they're dealing with to generate correct spatial SQL.

Leaving these as other + custom_extensions means every OSI implementation dealing with spatial data falls back to vendor-specific metadata, something that at CARTO we believe it should not happen.

On dimension.spatial as the spatial role marker

The type/role split you've introduced gives spatial data a natural place to live. We're working on a proposal (related to #69) that would add a spatial object to the dimension block as the spatial equivalent of is_time — a role marker that carries the metadata consuming tools need: geometry type, SRID, spatial index system and resolution, and geographic level. It would look like this:

- name: geom
  datatype: geometry              # proposed new enum value
  dimension:
    spatial:                      # proposed role marker + metadata
      type: polygon
      srid: 4326
      geographic_level: "census_block_group"
      geographic_hierarchy:
        parent: "census_tract"
        children: []
  description: "Block group boundary polygon (WGS84)"

- name: h3
  datatype: string                # H3 index is stored as a string
  dimension:
    spatial:
      type: spatial_index
      index:
        system: h3
        resolution: 8
        rollup_resolutions: [7, 6, 5]
      geographic_level: "h3_cell_res8"
  description: "H3 cell index at resolution 8"

This maps exactly onto the pattern you're establishing: datatype for the data type question, dimension.spatial for the role/semantics question. We can open a separate discussion on the spatial descriptor, but wanted to flag it here so the geometry/geography datatype values are on the radar before the enum is locked in.

On number precision — +1 to @KSDaemon's concern. We raised the same point on issue #84 and in a comment there. Worth resolving before this merges.

xavipereztr avatar Apr 27 '26 14:04 xavipereztr

Hi @xavipereztr, your descriptions of geometry and geography make good sense to me as additional data types, though I'd lean toward incorporating these as type additions in your proposal in https://github.com/open-semantic-interchange/OSI/discussions/69 rather than this PR.

I'm not opposed to adding a decimal type, but I'd be interested to articulate a case where a consumer of the semantic model would act differently for a float vs decimal column or expression type.

You mentioned in the other issue:

So a value like 1.5 in a column declared as unqualified NUMBER/NUMERIC survives on BigQuery but is silently truncated to 2 on Snowflake and Databricks. Precision ceilings also diverge (29 vs 38 total digits).

If this value is in a column with a decimal type in BigQuery or Snowflake, it's either already truncated or the precision accommodates it. If I'm writing SQL generation logic on top of this dimension, are there cases where this needs to differ when the underlying type is decimal vs a float type?

Another factor would be, for translation purposes, whether any mainstream semantic layers already distinguish these numeric types (cube and lookml do not as far as I've seen). If so, that would also be good argument to separate decimal as a dedicated type.

Grounding this in a use case would also help me think through whether decimal by itself is useful without the specific scale and precision parameters, or whether these parameters would be necessary.

jonmmease avatar Apr 27 '26 17:04 jonmmease

Hi @jonmmease - on the geometry and geography aspect, are you suggesting we create a PR based on #69 or shall we wait for further discussion with OSI members?

On the numeric simplification, I guess that you are right that between integer vs number is largely enough for most use-cases.

xavipereztr avatar Apr 28 '26 09:04 xavipereztr

I only meant that I think it makes sense to attach the additional geometry/geography data types to the dimension. spatial_data proposal in #69, and for these to be evaluated together through the OSI standards process (of which I'm not familiar with the details).

jonmmease avatar Apr 28 '26 13:04 jonmmease

Hey all, I'm not up to speed on the decision making process here, or who the decision makers are, but I'd like to do what I can to move this forward. I'm happy to make adjustments to the type system, but not sure we have consensus on this yet.

Would it be possible for someone with decision making authority here to summarize the desired changes?

jonmmease avatar Jun 17 '26 12:06 jonmmease

closing in favor of https://github.com/apache/ossie-temp/pull/12

jonmmease avatar Jul 13 '26 14:07 jonmmease

Hey @jonmmease Sorry for the confusion here, now the ASF setup is fully done and the original repo is transferred to apache. With that all the open PRs are correct preserved. I am reopening this PR and reviewing now. The PR on the ossie-temp can be closed.

khush-bhatia avatar Jul 14 '26 19:07 khush-bhatia

The datatypes for geometry/geography can be added in a follow up PR.

khush-bhatia avatar Jul 14 '26 20:07 khush-bhatia

Thanks @khush-bhatia! I brought the changes I made in the ossie-temp back here. Main changes are:

  1. I adopted the type system from the ontology layer (with a few extras that we could consider adding to the ontology value types as well)
  2. I updated several of the converters to propagate types where it was relatively unambiguous how to do so
  3. Added types to core-spec/spec.yaml as well

jonmmease avatar Jul 14 '26 22:07 jonmmease

@jbonofre and @QMalcolm could one of you also review this PR since this involves changes to the spec ?

khush-bhatia avatar Jul 15 '26 18:07 khush-bhatia

@khush-bhatia of course! I will! Thanks!

jbonofre avatar Jul 15 '26 19:07 jbonofre

Can we resolve the conflicts?

jbonofre avatar Jul 22 '26 05:07 jbonofre

Done. Conflict resolved and comment added. Thanks @jbonofre!

jonmmease avatar Jul 22 '26 15:07 jonmmease

Ping to merge before we get more conflicts @jbonofre. thanks!

jonmmease avatar Jul 23 '26 14:07 jonmmease