Hybrid queries

FeatureQL integrates smoothly into the SQL world by supporting hybrid queries.

Language specification

When working with FeatureMesh, queries can be interpreted as either SQL or FeatureQL. You can explicitly control the interpretation using comment directives:

Pure FeatureQL:

/* FEATUREQL */
SELECT
    CUSTOMER_ID := INPUT(BIGINT),
    TOTAL_SPEND := CUSTOMER_ID * 100
sql

Pure SQL:

/* SQL */
SELECT customer_id, total_spend
FROM customer_features
sql

Embedding patterns

FeatureQL offers bidirectional integration with SQL through multiple embedding patterns:

1. SQL within FeatureQL

Use EXTERNAL_SQL() and BIND_SQL() functions to embed SQL queries within FeatureQL features (covered in earlier sections).

2. FeatureQL within SQL

Embed FeatureQL segments within SQL queries as table-valued expressions:

How this works:

  • The FEATUREQL/* ... */ block is executed as a FeatureQL query
  • Results are returned as a table that can be used in SQL operations
  • The outer SQL can perform additional filtering, joining, or aggregation

3. FeatureQL as CTEs

Use FeatureQL as Common Table Expressions within larger SQL workflows:

Benefits of CTE embedding:

  • Modular design: Separate feature computation from business logic
  • Reusability: CTEs can be referenced multiple times in the main query
  • Performance: Query optimizers can cache CTE results
  • Readability: Clear separation between feature engineering and analytics

Third-party client integration

FeatureQL seamlessly integrates with existing SQL clients and BI tools through hybrid query support.

Common client pattern: Many SQL clients automatically wrap user queries with query parts generated by the themselves:

SELECT * FROM (/* User's query goes here */) LIMIT 1000
sql

FeatureQL integration: Simply wrap your FeatureQL with the hybrid syntax:

SELECT * FROM (/* SQL */ FEATUREQL/* Your FeatureQL query */) LIMIT 1000
sql

Example with client wrapper:

Client compatibility:

  • BI Tools: Tableau, PowerBI, Looker or Superset can query FeatureQL through hybrid syntax
  • SQL IDEs: DataGrip, DBeaver, and other SQL tools work seamlessly
  • Applications: Any application using JDBC/ODBC can execute hybrid queries

Performance considerations

When using hybrid queries:

  • The query optimization relies on the underlying engine's ability to perform filter pushdown
  • FeatureQL doesn't optimize across language boundaries

While hybrid queries provide flexibility, using the SQL-form of FeatureQL when it's possible is recommended for better maintainability and performance.

Last update at: 2025/10/13 10:23:46