(opts *MaterializedViewDDLOptions)
| 264 | } |
| 265 | |
| 266 | func genMaterializedViewDDL(opts *MaterializedViewDDLOptions) (string, error) { |
| 267 | var builder strings.Builder |
| 268 | viewNameWithDB := fmt.Sprintf("`%s`.`%s`", opts.databaseName, opts.mtViewName) |
| 269 | |
| 270 | // mtView name. |
| 271 | _, _ = fmt.Fprintf(&builder, "CREATE MATERIALIZED VIEW %s\n", viewNameWithDB) |
| 272 | |
| 273 | // disable rewrite. |
| 274 | if opts.disableRewrite { |
| 275 | _, _ = builder.WriteString("DISABLE REWRITE\n") |
| 276 | } |
| 277 | |
| 278 | // comment. |
| 279 | if opts.comment != "" { |
| 280 | _, _ = fmt.Fprintf(&builder, "COMMENT '%s'\n", opts.comment) |
| 281 | } |
| 282 | |
| 283 | // partitioned on. |
| 284 | if opts.partitionedOn != nil { |
| 285 | _, _ = builder.WriteString("PARTITIONED ON ") |
| 286 | formatColumn(&builder, opts.partitionedOn) |
| 287 | } |
| 288 | |
| 289 | if opts.clusteredOn != nil && opts.distributedOn != nil { |
| 290 | return "", errors.New("keywords 'CLUSTERED ON' and 'DISTRIBUTED ON' cannot appear at the same time") |
| 291 | } |
| 292 | // [CLUSTERED ON (col_name, ...) | DISTRIBUTED ON (col_name, ...) SORTED ON (col_name, ...)]. |
| 293 | if opts.distributedOn != nil && opts.sortedOn != nil { |
| 294 | // distributed on. |
| 295 | _, _ = builder.WriteString("DISTRIBUTED ON ") |
| 296 | formatColumn(&builder, opts.distributedOn) |
| 297 | |
| 298 | // sorted on. |
| 299 | _, _ = builder.WriteString("SORTED ON ") |
| 300 | formatColumn(&builder, opts.sortedOn) |
| 301 | } |
| 302 | if opts.clusteredOn != nil { |
| 303 | // clusteredOn |
| 304 | _, _ = builder.WriteString("CLUSTERED ON ") |
| 305 | formatColumn(&builder, opts.clusteredOn) |
| 306 | } |
| 307 | |
| 308 | // stored as or stored by. |
| 309 | if opts.storedAs != "" && opts.storedBy != "" { |
| 310 | return "", errors.New("keywords 'STORED AS' and 'STORED BY' cannot appear at the same time") |
| 311 | } |
| 312 | if opts.storedAs != "" { |
| 313 | _, _ = fmt.Fprintf(&builder, "STORED AS %s\n", opts.storedAs) |
| 314 | } |
| 315 | if opts.storedBy != "" { |
| 316 | _, _ = fmt.Fprintf(&builder, "STORED BY '%s'\n", opts.storedBy) |
| 317 | |
| 318 | // if with serde properties. |
| 319 | if opts.serdProperties != nil { |
| 320 | _, _ = builder.WriteString("WITH SERDEPROPERTIES ") |
| 321 | formatKVPair(&builder, opts.serdProperties) |
| 322 | } |
| 323 | } |
no test coverage detected