(opts *IndexDDLOptions)
| 199 | } |
| 200 | |
| 201 | func genIndexDDL(opts *IndexDDLOptions) (string, error) { |
| 202 | var builder strings.Builder |
| 203 | |
| 204 | // index name, table name. |
| 205 | _, _ = fmt.Fprintf(&builder, "CREATE INDEX `%s`\nON TABLE %s ", opts.indexName, fmt.Sprintf("`%s`.`%s`", opts.databaseName, opts.tableName)) |
| 206 | |
| 207 | // column names. |
| 208 | formatColumn(&builder, opts.colNames) |
| 209 | |
| 210 | // index type. |
| 211 | _, _ = fmt.Fprintf(&builder, ")\nAS '%s'\n", opts.indexType) |
| 212 | |
| 213 | // with deferred rebuild. |
| 214 | if opts.isWithDeferredRebuild { |
| 215 | _, _ = builder.WriteString("WITH DEFERRED REBUILD\n") |
| 216 | } |
| 217 | |
| 218 | // index properties. |
| 219 | if opts.idxProperties != nil { |
| 220 | _, _ = builder.WriteString("IDXPROPERTIES ") |
| 221 | formatKVPair(&builder, opts.tableProperties) |
| 222 | } |
| 223 | |
| 224 | // index table. |
| 225 | if opts.indexTableName != "" { |
| 226 | _, _ = fmt.Fprintf(&builder, "IN TABLE %s\n", opts.indexTableName) |
| 227 | } |
| 228 | |
| 229 | // row format. |
| 230 | if opts.rowFmt != "" { |
| 231 | _, _ = builder.WriteString(opts.rowFmt) |
| 232 | _, _ = builder.WriteRune('\n') |
| 233 | } |
| 234 | |
| 235 | // stored as or stored by. |
| 236 | if opts.storedAs != "" && opts.storedBy != "" { |
| 237 | return "", errors.New("keywords 'STORED AS' and 'STORED BY' cannot appear at the same time") |
| 238 | } |
| 239 | if opts.storedAs != "" { |
| 240 | _, _ = fmt.Fprintf(&builder, "STORED AS %s\n", opts.storedAs) |
| 241 | } |
| 242 | if opts.storedBy != "" { |
| 243 | _, _ = fmt.Fprintf(&builder, "STORED BY '%s'\n", opts.storedBy) |
| 244 | } |
| 245 | |
| 246 | // location. |
| 247 | if opts.location != "" { |
| 248 | _, _ = builder.WriteString(opts.location) |
| 249 | _, _ = builder.WriteRune('\n') |
| 250 | } |
| 251 | |
| 252 | // table properties. |
| 253 | if opts.tableProperties != nil { |
| 254 | _, _ = builder.WriteString("TBLPROPERTIES (") |
| 255 | formatKVPair(&builder, opts.tableProperties) |
| 256 | } |
| 257 | |
| 258 | // comment. |
no test coverage detected