>>>pipeline_explain.txt
=== Category
ID:          default_catalog.default_database.Category
Type:        stream
Stage:       flink
Primary key: -
Timestamp:   updateTime
Row count:   ~1e8
---
Schema:
 - categoryid: INTEGER NOT NULL
 - name: VARCHAR(2147483647) CHARACTER SET "UTF-16LE" NOT NULL
 - description: VARCHAR(2147483647) CHARACTER SET "UTF-16LE"
 - updateTime: TIMESTAMP_LTZ(3) *ROWTIME* NOT NULL
Inputs:
 - default_catalog.default_database.Category__base
Plan:
LogicalWatermarkAssigner(rowtime=[updateTime], watermark=[-($3, 1:INTERVAL SECOND)])
  LogicalProject(categoryid=[$0], name=[$1], description=[$2], updateTime=[NOW()])
    LogicalTableScan(table=[[default_catalog, default_database, Category]])
SQL:
CREATE TABLE `Category` (
  `categoryid` INTEGER NOT NULL,
  `name` STRING NOT NULL,
  `description` STRING,
  `updateTime` AS NOW(),
  WATERMARK FOR `updateTime` AS `updateTime` - INTERVAL '0.001' SECOND
)
WITH (
  'format' = 'flexible-json',
  'path' = 'file:/mock',
  'source.monitor-interval' = '10 sec',
  'connector' = 'filesystem'
)
=== CategoryDistinct
ID:          default_catalog.default_database.CategoryDistinct
Type:        state
Stage:       flink
Primary key: categoryid
Timestamp:   updateTime
Row count:   ~2e7
---
Schema:
 - categoryid: INTEGER NOT NULL
 - name: VARCHAR(2147483647) CHARACTER SET "UTF-16LE" NOT NULL
 - description: VARCHAR(2147483647) CHARACTER SET "UTF-16LE"
 - updateTime: TIMESTAMP_LTZ(3) *ROWTIME* NOT NULL
Inputs:
 - default_catalog.default_database.Category
Annotations:
 - mostRecentDistinct: true
Plan:
LogicalProject(categoryid=[$0], name=[$1], description=[$2], updateTime=[$3])
  LogicalFilter(condition=[=($4, 1)])
    LogicalProject(categoryid=[$0], name=[$1], description=[$2], updateTime=[$3], __sqrlinternal_rownum=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $3 DESC NULLS LAST)])
      LogicalTableScan(table=[[default_catalog, default_database, Category]])
SQL:
CREATE VIEW `CategoryDistinct`
AS
SELECT `categoryid`, `name`, `description`, `updateTime`
FROM (SELECT `categoryid`, `name`, `description`, `updateTime`, ROW_NUMBER() OVER (PARTITION BY `categoryid` ORDER BY `updateTime` DESC NULLS LAST) AS `__sqrlinternal_rownum`
  FROM `default_catalog`.`default_database`.`Category`) AS `t`
WHERE `__sqrlinternal_rownum` = 1
>>>flink-sql-no-functions.sql
CREATE TABLE `Category` (
  `categoryid` INTEGER NOT NULL,
  `name` STRING NOT NULL,
  `description` STRING,
  `updateTime` AS `NOW`(),
  WATERMARK FOR `updateTime` AS `updateTime` - INTERVAL '0.001' SECOND
)
WITH (
  'format' = 'flexible-json',
  'path' = 'file:/mock',
  'source.monitor-interval' = '10 sec',
  'connector' = 'filesystem'
);
CREATE VIEW `CategoryDistinct`
AS
SELECT `categoryid`, `name`, `description`, `updateTime`
FROM (SELECT `categoryid`, `name`, `description`, `updateTime`, ROW_NUMBER() OVER (PARTITION BY `categoryid` ORDER BY `updateTime` DESC NULLS LAST) AS `__sqrlinternal_rownum`
  FROM `default_catalog`.`default_database`.`Category`) AS `t`
WHERE `__sqrlinternal_rownum` = 1;
CREATE TABLE `Category_1` (
  `categoryid` INTEGER NOT NULL,
  `name` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `description` VARCHAR(2147483647) CHARACTER SET `UTF-16LE`,
  `updateTime` TIMESTAMP(3) WITH LOCAL TIME ZONE NOT NULL,
  `__pk_hash` CHAR(32) CHARACTER SET `UTF-16LE`,
  PRIMARY KEY (`__pk_hash`) NOT ENFORCED
)
WITH (
  'connector' = 'jdbc-sqrl',
  'driver' = 'org.postgresql.Driver',
  'password' = '${POSTGRES_PASSWORD}',
  'sink.on-conflict.action' = 'IGNORE',
  'table-name' = 'Category_1',
  'url' = 'jdbc:postgresql://${POSTGRES_AUTHORITY}',
  'username' = '${POSTGRES_USERNAME}'
);
CREATE TABLE `CategoryDistinct_2` (
  `categoryid` INTEGER NOT NULL,
  `name` VARCHAR(2147483647) CHARACTER SET `UTF-16LE` NOT NULL,
  `description` VARCHAR(2147483647) CHARACTER SET `UTF-16LE`,
  `updateTime` TIMESTAMP(3) WITH LOCAL TIME ZONE NOT NULL,
  PRIMARY KEY (`categoryid`) NOT ENFORCED
)
WITH (
  'connector' = 'jdbc-sqrl',
  'driver' = 'org.postgresql.Driver',
  'password' = '${POSTGRES_PASSWORD}',
  'sink.on-conflict.action' = 'TIMESTAMP',
  'sink.on-conflict.timestamp-column' = 'updateTime',
  'table-name' = 'CategoryDistinct_2',
  'url' = 'jdbc:postgresql://${POSTGRES_AUTHORITY}',
  'username' = '${POSTGRES_USERNAME}'
);
EXECUTE STATEMENT SET BEGIN
INSERT INTO `default_catalog`.`default_database`.`Category_1`
SELECT `categoryid`, `name`, `description`, `updateTime`, `hash_columns`(`categoryid`, `name`, `description`, `updateTime`) AS `__pk_hash`
 FROM `default_catalog`.`default_database`.`Category`
;
INSERT INTO `default_catalog`.`default_database`.`CategoryDistinct_2`
 SELECT *
  FROM `default_catalog`.`default_database`.`Category`
 ;
 END
>>>kafka.json
{
  "topics" : [ ],
  "testRunnerTopics" : [ ]
}
>>>postgres.json
{
  "statements" : [
    {
      "name" : "Category_1",
      "type" : "TABLE",
      "sql" : "CREATE TABLE IF NOT EXISTS \"Category_1\" (\"categoryid\" INTEGER NOT NULL, \"name\" TEXT NOT NULL, \"description\" TEXT, \"updateTime\" TIMESTAMP WITH TIME ZONE NOT NULL, \"__pk_hash\" TEXT, PRIMARY KEY (\"__pk_hash\"))",
      "fields" : [
        {
          "name" : "categoryid",
          "type" : "INTEGER",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "description",
          "type" : "TEXT",
          "nullable" : true
        },
        {
          "name" : "updateTime",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        },
        {
          "name" : "__pk_hash",
          "type" : "TEXT",
          "nullable" : true
        }
      ],
      "primaryKey" : [
        "__pk_hash"
      ],
      "partitionKey" : [ ],
      "partitionType" : "NONE",
      "numPartitions" : 0,
      "ttl" : 0.0
    },
    {
      "name" : "CategoryDistinct_2",
      "type" : "TABLE",
      "sql" : "CREATE TABLE IF NOT EXISTS \"CategoryDistinct_2\" (\"categoryid\" INTEGER NOT NULL, \"name\" TEXT NOT NULL, \"description\" TEXT, \"updateTime\" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY (\"categoryid\"))",
      "fields" : [
        {
          "name" : "categoryid",
          "type" : "INTEGER",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "description",
          "type" : "TEXT",
          "nullable" : true
        },
        {
          "name" : "updateTime",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        }
      ],
      "primaryKey" : [
        "categoryid"
      ],
      "partitionKey" : [ ],
      "partitionType" : "NONE",
      "numPartitions" : 0,
      "ttl" : 0.0
    },
    {
      "name" : "Category",
      "type" : "VIEW",
      "sql" : "CREATE OR REPLACE VIEW \"Category\"(\"categoryid\", \"name\", \"description\", \"updateTime\") AS SELECT \"categoryid\", \"name\", \"description\", \"updateTime\"\nFROM \"Category_1\"",
      "fields" : [
        {
          "name" : "categoryid",
          "type" : "INTEGER",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "description",
          "type" : "TEXT",
          "nullable" : true
        },
        {
          "name" : "updateTime",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        }
      ]
    },
    {
      "name" : "CategoryDistinct",
      "type" : "VIEW",
      "sql" : "CREATE OR REPLACE VIEW \"CategoryDistinct\"(\"categoryid\", \"name\", \"description\", \"updateTime\") AS SELECT *\nFROM \"CategoryDistinct_2\"",
      "fields" : [
        {
          "name" : "categoryid",
          "type" : "INTEGER",
          "nullable" : false
        },
        {
          "name" : "name",
          "type" : "TEXT",
          "nullable" : false
        },
        {
          "name" : "description",
          "type" : "TEXT",
          "nullable" : true
        },
        {
          "name" : "updateTime",
          "type" : "TIMESTAMP WITH TIME ZONE",
          "nullable" : false
        }
      ]
    }
  ]
}
>>>vertx.json
{
  "models" : {
    "v1" : {
      "queries" : [
        {
          "type" : "args",
          "parentType" : "Query",
          "fieldName" : "Category",
          "exec" : {
            "arguments" : [
              {
                "type" : "variable",
                "path" : "limit"
              },
              {
                "type" : "variable",
                "path" : "offset"
              }
            ],
            "query" : {
              "type" : "SqlQuery",
              "sql" : "SELECT \"categoryid\", \"name\", \"description\", \"updateTime\"\nFROM \"Category_1\"",
              "parameters" : [ ],
              "pagination" : "LIMIT_AND_OFFSET",
              "cacheDurationMs" : 0,
              "database" : "POSTGRES"
            }
          }
        },
        {
          "type" : "args",
          "parentType" : "Query",
          "fieldName" : "CategoryDistinct",
          "exec" : {
            "arguments" : [
              {
                "type" : "variable",
                "path" : "limit"
              },
              {
                "type" : "variable",
                "path" : "offset"
              }
            ],
            "query" : {
              "type" : "SqlQuery",
              "sql" : "SELECT *\nFROM \"CategoryDistinct_2\"",
              "parameters" : [ ],
              "pagination" : "LIMIT_AND_OFFSET",
              "cacheDurationMs" : 0,
              "database" : "POSTGRES"
            }
          }
        }
      ],
      "mutations" : [ ],
      "subscriptions" : [ ],
      "operations" : [
        {
          "function" : {
            "name" : "GetCategory",
            "parameters" : {
              "type" : "object",
              "properties" : {
                "offset" : {
                  "type" : "integer"
                },
                "limit" : {
                  "type" : "integer"
                }
              },
              "required" : [ ]
            }
          },
          "format" : "JSON",
          "apiQuery" : {
            "query" : "query Category($limit: Int = 10, $offset: Int = 0) {\nCategory(limit: $limit, offset: $offset) {\ncategoryid\nname\ndescription\nupdateTime\n}\n\n}",
            "queryName" : "Category",
            "operationType" : "QUERY"
          },
          "mcpMethod" : "TOOL",
          "restMethod" : "GET",
          "uriTemplate" : "queries/Category{?offset,limit}"
        },
        {
          "function" : {
            "name" : "GetCategoryDistinct",
            "parameters" : {
              "type" : "object",
              "properties" : {
                "offset" : {
                  "type" : "integer"
                },
                "limit" : {
                  "type" : "integer"
                }
              },
              "required" : [ ]
            }
          },
          "format" : "JSON",
          "apiQuery" : {
            "query" : "query CategoryDistinct($limit: Int = 10, $offset: Int = 0) {\nCategoryDistinct(limit: $limit, offset: $offset) {\ncategoryid\nname\ndescription\nupdateTime\n}\n\n}",
            "queryName" : "CategoryDistinct",
            "operationType" : "QUERY"
          },
          "mcpMethod" : "TOOL",
          "restMethod" : "GET",
          "uriTemplate" : "queries/CategoryDistinct{?offset,limit}"
        }
      ],
      "schema" : {
        "type" : "string",
        "schema" : "type Category {\n  categoryid: Int!\n  name: String!\n  description: String\n  updateTime: DateTime!\n}\n\ntype CategoryDistinct {\n  categoryid: Int!\n  name: String!\n  description: String\n  updateTime: DateTime!\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  Category(limit: Int = 10, offset: Int = 0): [Category!]\n  CategoryDistinct(limit: Int = 10, offset: Int = 0): [CategoryDistinct!]\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"
      }
    }
  }
}
