Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/how-to-guides/dbt-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ Ensure your dbt model includes the entity column specified with `--entity-column

By default, Feast looks for `event_timestamp`. Use `--timestamp-field` to specify a different column name.

### "Timestamp field ... does not map to a timestamp type"

The timestamp column exists but its `data_type` in schema.yml is not a timestamp type (for example `STRING` or `INT64`). The model is still imported, but point-in-time retrieval needs a real timestamp column. Declare the column as `TIMESTAMP`, `DATETIME` or `DATE` in schema.yml. Columns with no `data_type` are treated as `STRING` and also trigger this warning.

### "Entity column ... may not be suitable as an entity key"

The entity column's `data_type` in schema.yml maps to a Feast type other than a string or integer type. Floating point values are unreliable join keys, and boolean, binary and timestamp columns rarely identify an entity. The model is still imported. Use a `STRING` or `INT64` column as the entity, or declare the column's type in schema.yml if it is wrong. `NUMBER` types with a precision above 18, such as Snowflake's `NUMBER(38,0)`, map to `Float64`; declare integer IDs as `INTEGER` or `NUMBER(18,0)` instead.
Expand Down
23 changes: 22 additions & 1 deletion sdk/python/feast/cli/dbt_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ def import_command(
map_dbt_type_to_feast_type,
)
from feast.dbt.parser import DbtManifestParser, DbtModel
from feast.types import Array, Int32, Int64, String
from feast.types import (
Array,
Int32,
Int64,
String,
UnixTimestamp,
ZonedTimestamp,
)

try:
_validate_file_path_template(file_path_template, data_source_type)
Expand Down Expand Up @@ -228,6 +235,20 @@ def import_command(
)
continue

# The parser reports STRING for columns with no declared data_type.
timestamp_column = next(c for c in model.columns if c.name == timestamp_field)
if map_dbt_type_to_feast_type(timestamp_column.data_type) not in (
UnixTimestamp,
ZonedTimestamp,
):
click.echo(
f"{Fore.YELLOW}Warning: Model '{model.name}' timestamp field "
f"'{timestamp_field}' has type '{timestamp_column.data_type}', "
f"which does not map to a timestamp type. Importing anyway. "
f"Declare it as a timestamp type in schema.yml if this is wrong."
f"{Style.RESET_ALL}"
)

# Validate ALL entity columns exist
missing_entities = [e for e in entity_cols if e not in column_names]
if missing_entities:
Expand Down
127 changes: 127 additions & 0 deletions sdk/python/tests/unit/dbt/test_timestamp_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""`feast dbt import` warns when the timestamp field is not a timestamp type."""

import json

import pytest
from click.testing import CliRunner

pytest.importorskip("dbt_artifacts_parser", reason="dbt-artifacts-parser not installed")

from feast.cli.cli import cli # noqa: E402

MISSING = object()


def _column(name, data_type):
column = {
"name": name,
"description": "",
"meta": {},
"constraints": [],
"quote": None,
"tags": [],
}
if data_type is not MISSING:
column["data_type"] = data_type
return column


def _manifest(tmp_path, timestamp_type):
manifest = {
"metadata": {
"dbt_schema_version": "https://schemas.getdbt.com/dbt/manifest/v9.json",
"dbt_version": "1.5.0",
"generated_at": "2024-01-10T00:00:00Z",
"invocation_id": "test-invocation-id",
"env": {},
"adapter_type": "bigquery",
},
"nodes": {
"model.test_project.driver_stats": {
"database": "test_db",
"schema": "analytics",
"name": "driver_stats",
"resource_type": "model",
"package_name": "test_project",
"path": "models/driver_stats.sql",
"original_file_path": "models/driver_stats.sql",
"unique_id": "model.test_project.driver_stats",
"fqn": ["test_project", "driver_stats"],
"alias": "driver_stats",
"checksum": {"name": "sha256", "checksum": "abc"},
"config": {"enabled": True, "materialized": "table", "tags": []},
"tags": ["feast"],
"description": "",
"columns": {
"driver_id": _column("driver_id", "INT64"),
"event_timestamp": _column("event_timestamp", timestamp_type),
"trip_count": _column("trip_count", "INT64"),
},
"meta": {},
"depends_on": {"macros": [], "nodes": []},
}
},
"sources": {},
"macros": {},
"docs": {},
"exposures": {},
"metrics": {},
"groups": {},
"selectors": {},
"disabled": {},
"parent_map": {},
"child_map": {},
}
path = tmp_path / "manifest.json"
path.write_text(json.dumps(manifest))
return str(path)


def _import_dry_run(manifest_path):
return CliRunner().invoke(
cli,
[
"dbt",
"import",
"-m",
manifest_path,
"-e",
"driver_id",
"-d",
"file",
"--dry-run",
],
catch_exceptions=False,
)


@pytest.mark.parametrize(
"timestamp_type, reported_type",
[
("STRING", "STRING"),
("INT64", "INT64"),
pytest.param(MISSING, "STRING", id="undeclared"),
pytest.param(None, "STRING", id="null"),
],
)
def test_import_warns_when_timestamp_field_is_not_a_timestamp(
tmp_path, timestamp_type, reported_type
):
result = _import_dry_run(_manifest(tmp_path, timestamp_type))

assert result.exit_code == 0, result.output
assert (
f"Warning: Model 'driver_stats' timestamp field 'event_timestamp' "
f"has type '{reported_type}', which does not map to a timestamp type. "
f"Importing anyway." in result.output
)
assert "driver_stats: DataSource + FeatureView" in result.output


@pytest.mark.parametrize("timestamp_type", ["TIMESTAMP", "TIMESTAMP_NTZ(9)"])
def test_import_accepts_timestamp_types_silently(tmp_path, timestamp_type):
result = _import_dry_run(_manifest(tmp_path, timestamp_type))

assert result.exit_code == 0, result.output
assert "Warning" not in result.output
assert "driver_stats: DataSource + FeatureView" in result.output
Loading