treasure-data avatar

validate-segment

Validates CDP segment YAML configurations against the TD CDP API specification. Use when reviewing s

作者 treasure-data|オープンソース

Segment YAML Validation

Validate one segment at a time. Always specify the file path explicitly:

tdx sg validate path/to/segment.yml       # Local validation (fast, catches syntax errors)
tdx sg push --dry-run "path/to/segment.yml"  # Server validation (catches schema/reference errors)

Required Structure

name: string                       # Required (MISSING_NAME)
kind: batch                        # batch | realtime | funnel_stage
rule:
  type: And                        # And | Or (INVALID_RULE_TYPE)
  conditions:                      # Required array (MISSING_CONDITIONS)
    - type: Value
      attribute: field_name        # Required non-empty for Value (EMPTY_ATTRIBUTE)
      operator:
        type: OperatorType
        not: false                 # Optional negation
        value: ...

Condition Types

TypeRequired FieldsError Codes
Valueattribute, operatorEMPTY_ATTRIBUTE, INVALID_OPERATOR_TYPE
Value (with behavior)attribute: "", operator, source, aggregation, filterServer-side validation
include / excludesegmentMISSING_SEGMENT_REFERENCE
And / OrconditionsMISSING_CONDITIONS, NESTED_CONDITION_GROUP

Note: For behavior queries, use type: Value with source, aggregation, and filter fields. The type: Behavior may pass local validation but fail server-side.

Operators

18 valid types — any other value triggers INVALID_OPERATOR_TYPE:

CategoryTypesRequiredError
ComparisonEqual, NotEqual, Greater, GreaterEqual, Less, LessEqualvalueMISSING_OPERATOR_VALUE
RangeBetweenmin and/or maxMISSING_BETWEEN_BOUNDS
SetIn, NotInvalue (array)MISSING_OPERATOR_VALUE
TextContain, StartWith, EndWithvalue (string array)MISSING_OPERATOR_VALUE
PatternRegexpvalue (string)MISSING_OPERATOR_VALUE
NullIsNull(none)
TimeTimeWithinPast, TimeWithinNextvalue + unitMISSING_OPERATOR_VALUE, MISSING_TIME_UNIT
TimeTimeRange, TimeToday(special)

Time Units (Singular Form Only)

year | quarter | month | week | day | hour | minute | second

Common mistake: daysday, monthsmonth

Operator Negation

Any operator supports not: true for negation. This is separate from NotEqual/NotIn which are standalone types.

Behavior Conditions

Use type: Value with source, aggregation, and filter. Inside filter, use type: Column with column field (not type: Value with attribute). See segment skill for full examples.

Nested Condition Groups

Supported, but flagged. Nesting triggers a NESTED_CONDITION_GROUP warning, not a rejection — the segment still validates and pushes successfully. The warning exists because the Console UI's SQL preview doesn't render nested groups correctly; segment execution itself is unaffected. For same-attribute Or conditions, In is simpler and avoids the warning. See segment skill for details and workarounds.

Array Matching

Optional field on Value conditions:

arrayMatching: any                 # any | all | { atLeast: N } | { atMost: N } | { exactly: N }

Invalid keys trigger INVALID_ARRAY_MATCHING.

Error Code Reference

CodeCauseSolution
MISSING_NAMESegment name is empty or missingAdd name: field
INVALID_RULE_TYPERule type is not And or OrCheck type: spelling
MISSING_CONDITIONSRule or group has no conditions arrayAdd conditions array
EMPTY_ATTRIBUTEAttribute is emptyProvide attribute name (or "" for behavior)
INVALID_OPERATOR_TYPEOperator type not in the 18 valid typesCheck operator spelling
MISSING_OPERATOR_VALUEOperator requires value but it is missingAdd value: field
MISSING_BETWEEN_BOUNDSBetween has neither min nor maxAdd min: and/or max:
MISSING_TIME_UNITTime operator missing unitAdd unit: day (singular)
INVALID_ARRAY_MATCHINGarrayMatching has invalid formatUse any, all, or object form
MISSING_SEGMENT_REFERENCEinclude/exclude missing segment fieldAdd segment: with exact name
NESTED_CONDITION_GROUPAny nested Or/And condition group (warning, not a rejection)Use In operator or flatten if you want to avoid the warning
SEGMENT_SCHEMA_ERRORServer rejected the schemaCheck field names (column vs attribute in filter)

Local vs Server Validation

Checktdx sg validatetdx sg push --dry-run
YAML syntaxYesYes
Operator typesYesYes
Required fieldsYesYes
Nested groups flagged (warning only)YesYes
Segment referencesNoYes
Behavior schemaPartialYes
Field availabilityNoYes

Always run both validations before pushing.

Related Skills

  • segment - Full segment rule syntax and workflow