KSML Type Inference Rules
This document describes KSML attribute type inference rules.
It explains how KSML infers field types based on explicit declarations and literal values, and how these types map to Java, SQL, and GraphQL.
1. Overview
In KSML, attribute types can be:
- Explicitly declared using type functions such as
string(),id(),date() - Implicitly inferred from literal values using regex-based matchers
- Inherited via parent type relationships
Type inference is deterministic and rule-ordered.
2. Base Type Flags
Every type carries a set of semantic flags that guide downstream code generation.
| Flag | Meaning |
|---|---|
isString | String-like value |
isText | Large text (CLOB / TEXT) |
isNumber | Numeric value |
isInt | Integer number |
isBool | Boolean |
isDate | Date component |
isTime | Time component |
isDateTime | Date + time |
isId | Primary identifier |
isVersion | Version field |
isBaseEntityField | System-level base field |
isPassword | Password field |
3. Core Built-in Types
3.1 Identifier & Version
| Type | Java Type | SQL Type | Special Flags |
|---|---|---|---|
id | Long | BIGINT | isId, isBaseEntityField |
version | Long | BIGINT | isVersion, isBaseEntityField |
Example
id="id()"
version="version()"
3.2 String Types
| Type | Parent | Java Type | SQL Type | Notes |
|---|---|---|---|---|
string | — | String | VARCHAR(100) | Default type |
text | string | String | TEXT / CLOB | Large text |
jsonMe | text | String | TEXT | JSON, zipped |
password | string | String | VARCHAR | Encrypted |
uniStr | string | String | VARCHAR | Auto-generated |
Example
name="string()"
description="text()"
password="password()"
3.3 Numeric Types
| Type | Parent | Java Type | SQL Type | Notes |
|---|---|---|---|---|
number | — | BigDecimal | NUMERIC(19,7) | Decimal |
integer | number | Integer | INTEGER | Whole number |
long | number | Long | BIGINT | Large integer |
Example
age="integer()"
amount="number()"
count="long()"
3.4 Boolean
| Type | Java Type | SQL Type |
|---|---|---|
bool | Boolean | BOOLEAN |
Example
enabled="bool()"
3.5 Date & Time
| Type | Java Type | SQL Type | Notes |
|---|---|---|---|
date | LocalDate | DATE | Date only |
time | LocalTime | TIME | Time only |
dateTime | LocalDateTime | TIMESTAMP | Date + time |
createTime | LocalDateTime | TIMESTAMP | Auto now() |
updateTime | LocalDateTime | TIMESTAMP | Auto now() |
Example
birth_date="date()"
create_time="createTime()"
update_time="updateTime()"
4. Literal-Based Type Inference (Type Matchers)
When no explicit type is declared, KSML infers the type using regex matchers in priority order.
4.1 Type Matcher Table
| Order | Regex Pattern | Inferred Type | Example Value |
|---|---|---|---|
| 1 | ^\d+$ | integer | 123 |
| 2 | `^\d+(l | L)$` | long |
| 3 | ^\d+\.\d+$ | number | 12.34 |
| 4 | `^(true | false | on |
| 5 | ^\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{1,2}:\d{1,2}$ | dateTime | 2024-01-01T10:00:00 |
| 6 | ^\d{4}-\d{1,2}-\d{1,2}$ | date | 2024-01-01 |
4.2 Inference Examples
age="18"
➡ inferred as integer
total_amount="99.95"
➡ inferred as number
active="true"
➡ inferred as bool
created_at="2024-06-01T12:30:00"
➡ inferred as dateTime
5. Parent Type Inheritance
Types can inherit from parent types.
| Child Type | Parent | Inherited Behavior |
|---|---|---|
text | string | String semantics + large storage |
integer | number | Numeric semantics |
password | string | String + security |
createTime | dateTime | Auto creation |
updateTime | dateTime | Auto create & update |
6. Type Resolution Priority
- Explicit type declaration (e.g.
string()) - Built-in semantic type (
id(),createTime()) - Regex matcher inference
- Default type (
string)
7. Summary
- KSML type inference is rule-based, ordered, and deterministic
- Explicit types always override inferred types
- Parent-child type inheritance reduces duplication
- Type flags drive multi-target generation (Java / SQL / GraphQL)
Result: a single KSML model can reliably generate consistent schemas across systems.