Canner / wren-engine

🤖 The semantic engine for LLMs, bringing semantic context to AI agents. 🔥
https://getwren.ai/oss
Apache License 2.0
129 stars 34 forks source link

fix(core): fix the remote column inferring and disable simplify expression rule #874

Closed goldmedal closed 2 weeks ago

goldmedal commented 2 weeks ago

Description

This PR fixed multiple issues.

Disable SimplifyExpressionRule

This rule will simplify an expression to another expression if it can be evaluated. For example, current_date would be simplified to the real value like CAST('2024-10-31' DATE). However, we should execute this function on the DataSource side to make sure the time or timezone issue can be aligned.

Fix the Remote Column inferring

The remote column has some bugs. I missed to apply this way when generating the ModelSourceNode.

Fix the isHidden field

We always serialize the field name using camelCase style.

grieve54706 commented 2 weeks ago

@goldmedal Could you check the transformed SQL is changed for Postgres?

goldmedal commented 2 weeks ago

@goldmedal Could you check the transformed SQL is changed for Postgres?

The planned SQL is

SELECT 
  orders."timestamp", 
  orders."timestamptz", 
  orders.order_cust_key, 
  orders.o_custkey, 
  orders.o_orderdate, 
  orders.o_orderkey, 
  orders.o_orderstatus, 
  orders.o_totalprice 
FROM 
  (
    SELECT 
      CAST(
        '2024-01-01T23:59:59' AS TIMESTAMP
      ) AS "timestamp", 
      CAST(
        '2024-01-01T23:59:59' AS TIMESTAMP WITH TIME ZONE
      ) AS "timestamptz", 
      concat(
        CAST(
          public.orders.o_orderkey AS VARCHAR
        ), 
        '_', 
        CAST(
          public.orders.o_custkey AS VARCHAR
        )
      ) AS order_cust_key, 
      public.orders.o_custkey AS o_custkey, 
      public.orders.o_orderdate AS o_orderdate, 
      public.orders.o_orderkey AS o_orderkey, 
      public.orders.o_orderstatus AS o_orderstatus, 
      public.orders.o_totalprice AS o_totalprice 
    FROM 
      public.orders
  ) AS orders 
LIMIT 
  1

The dialect SQL is

SELECT 
  orders."timestamp", 
  orders."timestamptz", 
  orders.order_cust_key, 
  orders.o_custkey, 
  orders.o_orderdate, 
  orders.o_orderkey, 
  orders.o_orderstatus, 
  orders.o_totalprice 
FROM 
  (
    SELECT 
      CAST(
        '2024-01-01T23:59:59' AS TIMESTAMP
      ) AS "timestamp", 
      CAST(
        '2024-01-01T23:59:59' AS TIMESTAMPTZ
      ) AS "timestamptz", 
      CONCAT(
        CAST(
          public.orders.o_orderkey AS VARCHAR
        ), 
        '_', 
        CAST(
          public.orders.o_custkey AS VARCHAR
        )
      ) AS order_cust_key, 
      public.orders.o_custkey AS o_custkey, 
      public.orders.o_orderdate AS o_orderdate, 
      public.orders.o_orderkey AS o_orderkey, 
      public.orders.o_orderstatus AS o_orderstatus, 
      public.orders.o_totalprice AS o_totalprice 
    FROM 
      public.orders
  ) AS orders 
LIMIT 
  1

It seems to generate TIMESTAMPTZ, so the result has a UTC suffix.