Skip to main content

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:

  1. Explicitly declared using type functions such as string(), id(), date()
  2. Implicitly inferred from literal values using regex-based matchers
  3. 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.

FlagMeaning
isStringString-like value
isTextLarge text (CLOB / TEXT)
isNumberNumeric value
isIntInteger number
isBoolBoolean
isDateDate component
isTimeTime component
isDateTimeDate + time
isIdPrimary identifier
isVersionVersion field
isBaseEntityFieldSystem-level base field
isPasswordPassword field

3. Core Built-in Types​

3.1 Identifier & Version​

TypeJava TypeSQL TypeSpecial Flags
idLongBIGINTisId, isBaseEntityField
versionLongBIGINTisVersion, isBaseEntityField

Example

id="id()"
version="version()"

3.2 String Types​

TypeParentJava TypeSQL TypeNotes
string—StringVARCHAR(100)Default type
textstringStringTEXT / CLOBLarge text
jsonMetextStringTEXTJSON, zipped
passwordstringStringVARCHAREncrypted
uniStrstringStringVARCHARAuto-generated

Example

name="string()"
description="text()"
password="password()"

3.3 Numeric Types​

TypeParentJava TypeSQL TypeNotes
number—BigDecimalNUMERIC(19,7)Decimal
integernumberIntegerINTEGERWhole number
longnumberLongBIGINTLarge integer

Example

age="integer()"
amount="number()"
count="long()"

3.4 Boolean​

TypeJava TypeSQL Type
boolBooleanBOOLEAN

Example

enabled="bool()"

3.5 Date & Time​

TypeJava TypeSQL TypeNotes
dateLocalDateDATEDate only
timeLocalTimeTIMETime only
dateTimeLocalDateTimeTIMESTAMPDate + time
createTimeLocalDateTimeTIMESTAMPAuto now()
updateTimeLocalDateTimeTIMESTAMPAuto 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​

OrderRegex PatternInferred TypeExample Value
1^\d+$integer123
2`^\d+(lL)$`long
3^\d+\.\d+$number12.34
4`^(truefalseon
5^\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{1,2}:\d{1,2}$dateTime2024-01-01T10:00:00
6^\d{4}-\d{1,2}-\d{1,2}$date2024-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 TypeParentInherited Behavior
textstringString semantics + large storage
integernumberNumeric semantics
passwordstringString + security
createTimedateTimeAuto creation
updateTimedateTimeAuto create & update

6. Type Resolution Priority​

  1. Explicit type declaration (e.g. string())
  2. Built-in semantic type (id(), createTime())
  3. Regex matcher inference
  4. 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.