{"record":{"id":"acf78b15fc7d16f7","repo":"t8y2/dbx","slug":"execute-hive-initfile-statement-w","errorCode":null,"errorMessage":"execute Hive initFile statement: %w","messagePattern":"execute Hive initFile statement: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/main.go","lineNumber":372,"sourceCode":"\t}\n\tserver.database = database\n\tserver.connection = connection\n\treturn nil\n}\n\nfunc (server *server) connectionOpenTimeout() time.Duration {\n\ttimeout := server.config.ConnectTimeout\n\tif strings.EqualFold(server.config.Auth, \"BROWSER\") && strings.TrimSpace(server.config.BrowserToken) == \"\" {\n\t\ttimeout += server.config.BrowserResponseTimeout\n\t}\n\treturn timeout\n}\n\nfunc runHiveInitStatements(ctx context.Context, connection *sql.Conn, statements []string, fetchSize int) error {\n\tfor _, statement := range statements {\n\t\trows, _, hasResultSet, err := executeHiveStatement(ctx, connection, statement, fetchSize)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"execute Hive initFile statement: %w\", err)\n\t\t}\n\t\tif !hasResultSet {\n\t\t\tcontinue\n\t\t}\n\t\tfor rows.Next() {\n\t\t}\n\t\tif rowsErr := rows.Err(); rowsErr != nil {\n\t\t\t_ = rows.Close()\n\t\t\treturn fmt.Errorf(\"read Hive initFile statement result: %w\", rowsErr)\n\t\t}\n\t\tif closeErr := rows.Close(); closeErr != nil {\n\t\t\treturn fmt.Errorf(\"close Hive initFile statement result: %w\", closeErr)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (server *server) dispatch(method string, params map[string]json.RawMessage) (any, bool, error) {","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/main.go#L354-L390","documentation":"Wrapper error produced by `runHiveInitStatements` when `executeHiveStatement` returns an error while running one of the configured initFile statements on a freshly opened `*sql.Conn` during `openConnection`. The original driver error is preserved with %w; the wrapper only identifies which init statement phase failed. Since init statements run at connect time, any failure aborts the whole connection open (openConnection closes the conn and database and returns this error).","triggerScenarios":"openConnection → runHiveInitStatements executes a statement from config.InitStatements and `executeHiveStatement` returns an error: invalid SQL syntax, missing target table/database, permission denied, Hive server query error, context timeout exceeded, or fetchSize misuse.","commonSituations":"initFile containing SQL valid in another engine (e.g. MySQL/Postgres syntax Hive rejects); USE/SET statements referencing a database the user cannot access; initFile grown stale after schema migrations; connect timeout too short for slow init queries; Kerberos/LDAP-authenticated user lacking privileges for init statements.","solutions":["Unwrap the error (%w) and fix the underlying Hive driver error reported for the failing statement; run the statement manually in beeline/Hive CLI to see the full message.","Validate the initFile: remove or correct statements incompatible with your Hive version and confirm referenced databases/tables exist and the connecting user has privileges.","Increase the connection open timeout (connectTimeout / browser response timeout) if init statements are slow rather than wrong.","As a workaround, temporarily empty InitStatements to confirm connectivity itself is fine, then re-add statements one at a time to isolate the offender."],"exampleFix":"// before (init.sql)\nSET hive.support.concurrency=false;\nUSE analytics;\nSELECT * FROM events;  -- fails: table renamed\n// after\nSET hive.support.concurrency=false;\nUSE analytics;\nSELECT 1;  -- cheap, valid init statement","handlingStrategy":"validation","validationCode":"// validate initFile statements before configuring the driver\nfor i, stmt := range initStatements {\n    if strings.TrimSpace(stmt) == \"\" {\n        return fmt.Errorf(\"init statement %d is empty\", i)\n    }\n    if err := dryRunInBeeline(stmt); err != nil {\n        return fmt.Errorf(\"init statement %d invalid: %w\", i, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"err := runHiveInitStatements(ctx, conn, stmts, fetchSize)\nif err != nil {\n    var execErr error\n    if errors.As(err, &execErr) && strings.Contains(err.Error(), \"execute Hive initFile statement\") {\n        return fmt.Errorf(\"initFile rejected by Hive server: %w\", err) // fix the SQL, not the transport\n    }\n    return err\n}","preventionTips":["Keep initFile statements Hive-compatible and non-result (SET/USE/DDL) so failures are rare and nothing needs draining.","Dry-run every init statement in beeline after schema or version changes.","Grant the connecting principal privileges on every database/table the initFile touches.","Version-pin and review the initFile alongside schema migrations."],"tags":["go","hive","sql","init-script","connection-setup"],"backgroundTag":"sql-execution-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}