>>>pipeline_explain.txt
=== Customer
ID:          default_catalog.default_database.Customer
Type:        stream
Stage:       flink
Primary key: customerid, lastUpdated
Timestamp:   timestamp
Row count:   ~1e8
---
Schema:
 - customerid: BIGINT NOT NULL
 - email: VARCHAR(2147483647) CHARACTER SET "UTF-16LE" NOT NULL
 - name: VARCHAR(2147483647) CHARACTER SET "UTF-16LE" NOT NULL
 - lastUpdated: BIGINT NOT NULL
 - timestamp: TIMESTAMP_LTZ(3) *ROWTIME* NOT NULL
Inputs:
 - default_catalog.default_database.Customer__base
Annotations:
 - stream-root: Customer
Plan:
LogicalWatermarkAssigner(rowtime=[timestamp], watermark=[-($4, 1:INTERVAL SECOND)])
  LogicalProject(customerid=[$0], email=[$1], name=[$2], lastUpdated=[$3], timestamp=[COALESCE(TO_TIMESTAMP_LTZ($3, 0), 1970-01-01 08:00:00:TIMESTAMP_WITH_LOCAL_TIME_ZONE(3))])
    LogicalTableScan(table=[[default_catalog, default_database, Customer]])
SQL:
CREATE TEMPORARY TABLE `Customer__schema` (
  `customerid` BIGINT NOT NULL,
  `email` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `name` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `lastUpdated` BIGINT NOT NULL
)
WITH (
  'connector' = 'datagen'
);
CREATE TABLE `Customer` (
  `timestamp` AS COALESCE(`TO_TIMESTAMP_LTZ`(`lastUpdated`, 0), CAST(TIMESTAMP '1970-01-01 00:00:00.000' AS TIMESTAMP(3) WITH LOCAL TIME ZONE)),
  PRIMARY KEY (`customerid`, `lastUpdated`) NOT ENFORCED,
  WATERMARK FOR `timestamp` AS `timestamp` - INTERVAL '0.001' SECOND
)
WITH (
  'format' = 'flexible-json',
  'path' = 'file:/mock',
  'source.monitor-interval' = '10 sec',
  'connector' = 'filesystem'
)
LIKE `Customer__schema`
=== CustomerHighCount
ID:          default_catalog.default_database.CustomerHighCount
Type:        stream
Stage:       flink
Primary key: window_start, window_end
Timestamp:   -
Row count:   ~5e7
---
Schema:
 - window_start: TIMESTAMP(3) NOT NULL
 - window_end: TIMESTAMP(3) NOT NULL
 - unique_email_count: BIGINT NOT NULL
Inputs:
 - default_catalog.default_database.CustomerTimeWindow
Plan:
LogicalProject(window_start=[$0], window_end=[$1], unique_email_count=[$2])
  LogicalFilter(condition=[>($2, 1)])
    LogicalTableScan(table=[[default_catalog, default_database, CustomerTimeWindow]])
SQL:
CREATE VIEW `CustomerHighCount` AS  SELECT * FROM CustomerTimeWindow WHERE unique_email_count > 1;

=== CustomerTimeWindow
ID:          default_catalog.default_database.CustomerTimeWindow
Type:        stream
Stage:       flink
Primary key: window_start, window_end
Timestamp:   -
Row count:   ~3e7
---
Schema:
 - window_start: TIMESTAMP(3) NOT NULL
 - window_end: TIMESTAMP(3) NOT NULL
 - unique_email_count: BIGINT NOT NULL
Inputs:
 - default_catalog.default_database.Customer
Annotations:
 - features: STREAM_WINDOW_AGGREGATION (feature)
Plan:
LogicalAggregate(group=[{0, 1}], unique_email_count=[COUNT(DISTINCT $2)])
  LogicalProject(window_start=[$5], window_end=[$6], email=[$1])
    LogicalTableFunctionScan(invocation=[TUMBLE(TABLE(#0), DESCRIPTOR('timestamp'), 60000:INTERVAL MINUTE)], rowType=[RecordType(BIGINT customerid, VARCHAR(2147483647) email, VARCHAR(2147483647) name, BIGINT lastUpdated, TIMESTAMP_LTZ(3) *ROWTIME* timestamp, TIMESTAMP(3) window_start, TIMESTAMP(3) window_end, TIMESTAMP_LTZ(3) *ROWTIME* window_time)])
      LogicalProject(customerid=[$0], email=[$1], name=[$2], lastUpdated=[$3], timestamp=[$4])
        LogicalTableScan(table=[[default_catalog, default_database, Customer]])
SQL:
CREATE VIEW `CustomerTimeWindow` AS  SELECT
                          window_start, window_end,
                          COUNT(DISTINCT email) AS unique_email_count
                      FROM TABLE(
                              TUMBLE(TABLE Customer, DESCRIPTOR(`timestamp`), INTERVAL '1' MINUTE)
                           )
                      GROUP BY
                          window_start, window_end;

>>>flink-sql-no-functions.sql
CREATE TEMPORARY TABLE `Customer__schema` (
  `customerid` BIGINT NOT NULL,
  `email` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `name` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `lastUpdated` BIGINT NOT NULL
)
WITH (
  'connector' = 'datagen'
);
CREATE TABLE `Customer` (
  `timestamp` AS COALESCE(`TO_TIMESTAMP_LTZ`(`lastUpdated`, 0), TIMESTAMP '1970-01-01 00:00:00.000'),
  PRIMARY KEY (`customerid`, `lastUpdated`) NOT ENFORCED,
  WATERMARK FOR `timestamp` AS `timestamp` - INTERVAL '0.001' SECOND
)
WITH (
  'format' = 'flexible-json',
  'path' = 'file:/mock',
  'source.monitor-interval' = '10 sec',
  'connector' = 'filesystem'
)
LIKE `Customer__schema`;
CREATE VIEW `CustomerTimeWindow`
AS
SELECT `window_start`, `window_end`, COUNT(DISTINCT `email`) AS `unique_email_count`
FROM TABLE(TUMBLE(TABLE `Customer`, DESCRIPTOR(`timestamp`), INTERVAL '1' MINUTE))
GROUP BY `window_start`, `window_end`;
CREATE VIEW `CustomerHighCount`
AS
SELECT *
FROM `CustomerTimeWindow`
WHERE `unique_email_count` > 1;
CREATE TABLE `Customer_1` (
  `customerid` BIGINT NOT NULL,
  `email` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `name` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `lastUpdated` BIGINT NOT NULL,
  `timestamp` TIMESTAMP(3) WITH LOCAL TIME ZONE NOT NULL,
  PRIMARY KEY (`customerid`, `lastUpdated`) NOT ENFORCED
)
WITH (
  'connector' = 'jdbc-sqrl',
  'driver' = 'org.postgresql.Driver',
  'password' = '${POSTGRES_PASSWORD}',
  'sink.on-conflict.action' = 'IGNORE',
  'table-name' = 'Customer_1',
  'url' = 'jdbc:postgresql://${POSTGRES_AUTHORITY}',
  'username' = '${POSTGRES_USERNAME}'
);
CREATE TABLE `CustomerHighCount_2` (
  `window_start` TIMESTAMP(3) NOT NULL,
  `window_end` TIMESTAMP(3) NOT NULL,
  `unique_email_count` BIGINT NOT NULL,
  PRIMARY KEY (`window_start`, `window_end`) NOT ENFORCED
)
WITH (
  'connector' = 'jdbc-sqrl',
  'driver' = 'org.postgresql.Driver',
  'password' = '${POSTGRES_PASSWORD}',
  'sink.on-conflict.action' = 'IGNORE',
  'table-name' = 'CustomerHighCount_2',
  'url' = 'jdbc:postgresql://${POSTGRES_AUTHORITY}',
  'username' = '${POSTGRES_USERNAME}'
);
CREATE TABLE `CustomerTimeWindow_3` (
  `window_start` TIMESTAMP(3) NOT NULL,
  `window_end` TIMESTAMP(3) NOT NULL,
  `unique_email_count` BIGINT NOT NULL,
  PRIMARY KEY (`window_start`, `window_end`) NOT ENFORCED
)
WITH (
  'connector' = 'jdbc-sqrl',
  'driver' = 'org.postgresql.Driver',
  'password' = '${POSTGRES_PASSWORD}',
  'sink.on-conflict.action' = 'IGNORE',
  'table-name' = 'CustomerTimeWindow_3',
  'url' = 'jdbc:postgresql://${POSTGRES_AUTHORITY}',
  'username' = '${POSTGRES_USERNAME}'
);
EXECUTE STATEMENT SET BEGIN
INSERT INTO `default_catalog`.`default_database`.`Customer_1`
SELECT *
 FROM `default_catalog`.`default_database`.`Customer`
;
INSERT INTO `default_catalog`.`default_database`.`CustomerHighCount_2`
 SELECT *
  FROM `default_catalog`.`default_database`.`CustomerHighCount`
 ;
 INSERT INTO `default_catalog`.`default_database`.`CustomerTimeWindow_3`
  SELECT *
   FROM `default_catalog`.`default_database`.`CustomerTimeWindow`
  ;
  END
>>>kafka.json
{
  "topics" : [ ],
  "testRunnerTopics" : [ ]
}
>>>postgres.json
{
  "statements" : [
    {
      "name" : "Customer_1",
      "type" : "TABLE",
      "sql" : "CREATE TABLE IF NOT EXISTS \"Customer_1\" (\"customerid\" BIGINT NOT NULL, \"email\" TEXT NOT NULL, \"name\" TEXT NOT NULL, \"lastUpdated\" BIGINT NOT NULL, \"timestamp\" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY (\"customerid\",\"lastUpdated\"))",
      "fields" : [
        {
          "name" : "customerid",
          "type" : "BIGINT",
          "nullable" : false
        },
        {
          "name" : "email",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "lastUpdated",
          "type" : "BIGINT",
          "nullable" : false
        },
        {
          "name" : "timestamp",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        }
      ],
      "primaryKey" : [
        "customerid",
        "lastUpdated"
      ],
      "partitionKey" : [ ],
      "partitionType" : "NONE",
      "numPartitions" : 0,
      "ttl" : 0.0
    },
    {
      "name" : "CustomerHighCount_2",
      "type" : "TABLE",
      "sql" : "CREATE TABLE IF NOT EXISTS \"CustomerHighCount_2\" (\"window_start\" TIMESTAMP WITHOUT TIME ZONE NOT NULL, \"window_end\" TIMESTAMP WITHOUT TIME ZONE NOT NULL, \"unique_email_count\" BIGINT NOT NULL, PRIMARY KEY (\"window_start\",\"window_end\"))",
      "fields" : [
        {
          "name" : "window_start",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "window_end",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "unique_email_count",
          "type" : "BIGINT",
          "nullable" : false
        }
      ],
      "primaryKey" : [
        "window_start",
        "window_end"
      ],
      "partitionKey" : [ ],
      "partitionType" : "NONE",
      "numPartitions" : 0,
      "ttl" : 0.0
    },
    {
      "name" : "CustomerTimeWindow_3",
      "type" : "TABLE",
      "sql" : "CREATE TABLE IF NOT EXISTS \"CustomerTimeWindow_3\" (\"window_start\" TIMESTAMP WITHOUT TIME ZONE NOT NULL, \"window_end\" TIMESTAMP WITHOUT TIME ZONE NOT NULL, \"unique_email_count\" BIGINT NOT NULL, PRIMARY KEY (\"window_start\",\"window_end\"))",
      "fields" : [
        {
          "name" : "window_start",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "window_end",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "unique_email_count",
          "type" : "BIGINT",
          "nullable" : false
        }
      ],
      "primaryKey" : [
        "window_start",
        "window_end"
      ],
      "partitionKey" : [ ],
      "partitionType" : "NONE",
      "numPartitions" : 0,
      "ttl" : 0.0
    },
    {
      "name" : "Customer",
      "type" : "VIEW",
      "sql" : "CREATE OR REPLACE VIEW \"Customer\"(\"customerid\", \"email\", \"name\", \"lastUpdated\", \"timestamp\") AS SELECT *\nFROM \"Customer_1\"",
      "fields" : [
        {
          "name" : "customerid",
          "type" : "BIGINT",
          "nullable" : false
        },
        {
          "name" : "email",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "lastUpdated",
          "type" : "BIGINT",
          "nullable" : false
        },
        {
          "name" : "timestamp",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        }
      ]
    },
    {
      "name" : "CustomerHighCount",
      "type" : "VIEW",
      "sql" : "CREATE OR REPLACE VIEW \"CustomerHighCount\"(\"window_start\", \"window_end\", \"unique_email_count\") AS SELECT *\nFROM \"CustomerHighCount_2\"",
      "fields" : [
        {
          "name" : "window_start",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "window_end",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "unique_email_count",
          "type" : "BIGINT",
          "nullable" : false
        }
      ]
    },
    {
      "name" : "CustomerTimeWindow",
      "type" : "VIEW",
      "sql" : "CREATE OR REPLACE VIEW \"CustomerTimeWindow\"(\"window_start\", \"window_end\", \"unique_email_count\") AS SELECT *\nFROM \"CustomerTimeWindow_3\"",
      "fields" : [
        {
          "name" : "window_start",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "window_end",
          "type" : "TIMESTAMP WITHOUT TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "unique_email_count",
          "type" : "BIGINT",
          "nullable" : false
        }
      ]
    }
  ]
}
>>>vertx.json
{
  "models" : {
    "v1" : {
      "queries" : [
        {
          "type" : "args",
          "parentType" : "Query",
          "fieldName" : "Customer",
          "exec" : {
            "arguments" : [
              {
                "type" : "variable",
                "path" : "limit"
              },
              {
                "type" : "variable",
                "path" : "offset"
              }
            ],
            "query" : {
              "type" : "SqlQuery",
              "sql" : "SELECT *\nFROM \"Customer_1\"",
              "parameters" : [ ],
              "pagination" : "LIMIT_AND_OFFSET",
              "cacheDurationMs" : 0,
              "database" : "POSTGRES"
            }
          }
        },
        {
          "type" : "args",
          "parentType" : "Query",
          "fieldName" : "CustomerHighCount",
          "exec" : {
            "arguments" : [
              {
                "type" : "variable",
                "path" : "limit"
              },
              {
                "type" : "variable",
                "path" : "offset"
              }
            ],
            "query" : {
              "type" : "SqlQuery",
              "sql" : "SELECT *\nFROM \"CustomerHighCount_2\"",
              "parameters" : [ ],
              "pagination" : "LIMIT_AND_OFFSET",
              "cacheDurationMs" : 0,
              "database" : "POSTGRES"
            }
          }
        },
        {
          "type" : "args",
          "parentType" : "Query",
          "fieldName" : "CustomerTimeWindow",
          "exec" : {
            "arguments" : [
              {
                "type" : "variable",
                "path" : "limit"
              },
              {
                "type" : "variable",
                "path" : "offset"
              }
            ],
            "query" : {
              "type" : "SqlQuery",
              "sql" : "SELECT *\nFROM \"CustomerTimeWindow_3\"",
              "parameters" : [ ],
              "pagination" : "LIMIT_AND_OFFSET",
              "cacheDurationMs" : 0,
              "database" : "POSTGRES"
            }
          }
        }
      ],
      "mutations" : [ ],
      "subscriptions" : [ ],
      "operations" : [
        {
          "function" : {
            "name" : "GetCustomer",
            "parameters" : {
              "type" : "object",
              "properties" : {
                "offset" : {
                  "type" : "integer"
                },
                "limit" : {
                  "type" : "integer"
                }
              },
              "required" : [ ]
            }
          },
          "format" : "JSON",
          "apiQuery" : {
            "query" : "query Customer($limit: Int = 10, $offset: Int = 0) {\nCustomer(limit: $limit, offset: $offset) {\ncustomerid\nemail\nname\nlastUpdated\ntimestamp\n}\n\n}",
            "queryName" : "Customer",
            "operationType" : "QUERY"
          },
          "mcpMethod" : "TOOL",
          "restMethod" : "GET",
          "uriTemplate" : "queries/Customer{?offset,limit}"
        },
        {
          "function" : {
            "name" : "GetCustomerHighCount",
            "parameters" : {
              "type" : "object",
              "properties" : {
                "offset" : {
                  "type" : "integer"
                },
                "limit" : {
                  "type" : "integer"
                }
              },
              "required" : [ ]
            }
          },
          "format" : "JSON",
          "apiQuery" : {
            "query" : "query CustomerHighCount($limit: Int = 10, $offset: Int = 0) {\nCustomerHighCount(limit: $limit, offset: $offset) {\nwindow_start\nwindow_end\nunique_email_count\n}\n\n}",
            "queryName" : "CustomerHighCount",
            "operationType" : "QUERY"
          },
          "mcpMethod" : "TOOL",
          "restMethod" : "GET",
          "uriTemplate" : "queries/CustomerHighCount{?offset,limit}"
        },
        {
          "function" : {
            "name" : "GetCustomerTimeWindow",
            "parameters" : {
              "type" : "object",
              "properties" : {
                "offset" : {
                  "type" : "integer"
                },
                "limit" : {
                  "type" : "integer"
                }
              },
              "required" : [ ]
            }
          },
          "format" : "JSON",
          "apiQuery" : {
            "query" : "query CustomerTimeWindow($limit: Int = 10, $offset: Int = 0) {\nCustomerTimeWindow(limit: $limit, offset: $offset) {\nwindow_start\nwindow_end\nunique_email_count\n}\n\n}",
            "queryName" : "CustomerTimeWindow",
            "operationType" : "QUERY"
          },
          "mcpMethod" : "TOOL",
          "restMethod" : "GET",
          "uriTemplate" : "queries/CustomerTimeWindow{?offset,limit}"
        }
      ],
      "schema" : {
        "type" : "string",
        "schema" : "type Customer {\n  customerid: Long!\n  email: String!\n  name: String!\n  lastUpdated: Long!\n  timestamp: DateTime!\n}\n\ntype CustomerTimeWindow {\n  window_start: DateTime!\n  window_end: DateTime!\n  unique_email_count: Long!\n}\n\n\"An RFC-3339 compliant Full Date Scalar\"\nscalar Date\n\n\"A DateTime scalar that handles both full RFC3339 and shorter timestamp formats\"\nscalar DateTime\n\n\"A JSON scalar\"\nscalar JSON\n\n\"24-hour clock time value string in the format `hh:mm:ss` or `hh:mm:ss.sss`.\"\nscalar LocalTime\n\n\"A 64-bit signed integer\"\nscalar Long\n\ntype Query {\n  Customer(limit: Int = 10, offset: Int = 0): [Customer!]\n  CustomerHighCount(limit: Int = 10, offset: Int = 0): [CustomerTimeWindow!]\n  CustomerTimeWindow(limit: Int = 10, offset: Int = 0): [CustomerTimeWindow!]\n}\n\nenum _McpMethodType {\n  NONE\n  TOOL\n  RESOURCE\n}\n\nenum _RestMethodType {\n  NONE\n  GET\n  POST\n}\n\ndirective @api(mcp: _McpMethodType, rest: _RestMethodType, uri: String) on QUERY | MUTATION | FIELD_DEFINITION\n"
      }
    }
  }
}
