{"record":{"id":"7b5419cb6d0895b5","repo":"bytebase/bytebase","slug":"keywords-stored-as-and-stored-by-cannot-appear","errorCode":null,"errorMessage":"keywords 'STORED AS' and 'STORED BY' cannot appear at the same time","messagePattern":"keywords 'STORED AS' and 'STORED BY' cannot appear at the same time","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/db/hive/dump.go","lineNumber":237,"sourceCode":"\tif opts.idxProperties != nil {\n\t\t_, _ = builder.WriteString(\"IDXPROPERTIES \")\n\t\tformatKVPair(&builder, opts.tableProperties)\n\t}\n\n\t// index table.\n\tif opts.indexTableName != \"\" {\n\t\t_, _ = fmt.Fprintf(&builder, \"IN TABLE %s\\n\", opts.indexTableName)\n\t}\n\n\t// row format.\n\tif opts.rowFmt != \"\" {\n\t\t_, _ = builder.WriteString(opts.rowFmt)\n\t\t_, _ = builder.WriteRune('\\n')\n\t}\n\n\t// stored as or stored by.\n\tif opts.storedAs != \"\" && opts.storedBy != \"\" {\n\t\treturn \"\", errors.New(\"keywords 'STORED AS' and 'STORED BY' cannot appear at the same time\")\n\t}\n\tif opts.storedAs != \"\" {\n\t\t_, _ = fmt.Fprintf(&builder, \"STORED AS %s\\n\", opts.storedAs)\n\t}\n\tif opts.storedBy != \"\" {\n\t\t_, _ = fmt.Fprintf(&builder, \"STORED BY '%s'\\n\", opts.storedBy)\n\t}\n\n\t// location.\n\tif opts.location != \"\" {\n\t\t_, _ = builder.WriteString(opts.location)\n\t\t_, _ = builder.WriteRune('\\n')\n\t}\n\n\t// table properties.\n\tif opts.tableProperties != nil {\n\t\t_, _ = builder.WriteString(\"TBLPROPERTIES (\")\n\t\tformatKVPair(&builder, opts.tableProperties)","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/db/hive/dump.go#L219-L255","documentation":"genIndexDDL (used for Hive index/table DDL generation) accepts storage options storedAs (STORED AS <format>) and storedBy (STORED BY '<class>'). Hive only permits one of these clauses, so when both are non-empty the generator refuses to emit invalid DDL and returns this error.","triggerScenarios":"Dump reaching genIndexDDL with IndexDDLOptions where both storedAs and storedBy were populated — e.g. metadata that merged storage info from two sources or a bug feeding the same index both a file format and a storage handler.","commonSituations":"Index tables created with a custom storage handler (STORED BY) whose metadata also carries a STORED AS format; manually patched schema metadata; dialect mappings translating both fields from a foreign dialect.","solutions":["Fix the source metadata so the object declares only one storage clause — a storage-handler table (STORED BY) should not also set a file format (STORED AS).","If both values come from upstream sync code, correct the field mapping so storedBy takes precedence and storedAs is left empty (or vice versa).","As a workaround, drop and recreate the Hive object with only one storage specification, then re-run the dump."],"exampleFix":"// before\nopts := &IndexDDLOptions{storedAs: \"PARQUET\", storedBy: \"org.apache.hadoop.hive.hbase.HBaseStorageHandler\"}\n// after\nopts := &IndexDDLOptions{storedBy: \"org.apache.hadoop.hive.hbase.HBaseStorageHandler\"} // drop storedAs when storedBy is set","handlingStrategy":"validation","validationCode":"func validateStorage(opts *IndexDDLOptions) error {\n  if opts.storedAs != \"\" && opts.storedBy != \"\" {\n    return errors.New(\"STORED AS and STORED BY are mutually exclusive\")\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":"if err := genIndexDDL(opts); err != nil {\n  if strings.Contains(err.Error(), \"STORED AS' and 'STORED BY\") {\n    // fall back to the storage-handler form\n    opts.storedAs = \"\"\n    return genIndexDDL(opts)\n  }\n  return err\n}","preventionTips":["Normalize metadata so an object with a storage handler (STORED BY) never also carries a file format (STORED AS).","Validate mutually exclusive DDL options at metadata sync time, not at dump time.","Document which storage clause the source object uses and map only that field during dialect translation."],"tags":["hive","ddl","validation"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}