{"record":{"id":"25e5342359905558","repo":"prestodb/presto","slug":"request-has-different-number-of-fields-than-column","errorCode":null,"errorMessage":"Request has different number of fields than column handles: %d != %d","messagePattern":"Request has different number of fields than column handles: (.+?) != (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-flight-shim/src/main/java/com/facebook/presto/flightshim/FlightShimProducer.java","lineNumber":171,"sourceCode":"                    .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY)\n                    .setLocale(ENGLISH).build();\n            ConnectorId connectorId = new ConnectorId(request.getConnectorId());\n            Split split = new Split(connectorId, transactionHandle, connectorSplit);\n\n            List<ColumnHandle> columnHandles = request.getColumnHandlesBytes().stream().map(\n                    columnHandleBytes -> connectorCodecs.getCodecColumnHandle().fromJson(columnHandleBytes)\n            ).collect(toImmutableList());\n\n            AtomicInteger fieldCount = new AtomicInteger();\n            List<ColumnMetadata> columnsMetadata = request.getFields().stream()\n                    .map(field -> ColumnMetadata.builder()\n                                    .setName(field.getName().orElse(format(\"$col%s$\", fieldCount.incrementAndGet())))\n                                    .setType(field.getType().orElseThrow(() -> new IllegalArgumentException(\"Field type not present\")))\n                            .build())\n                    .collect(toImmutableList());\n\n            if (columnHandles.size() != columnsMetadata.size()) {\n                throw new IllegalArgumentException(format(\"Request has different number of fields than column handles: %d != %d\", columnsMetadata.size(), columnHandles.size()));\n            }\n\n            ConnectorPageSource connectorPageSource = pageSourceManager.createPageSource(session, split, tableHandle, columnHandles, new RuntimeStats());\n\n            try (ArrowBatchSource batchSource = new ArrowBatchSource(allocator, columnsMetadata, connectorPageSource, config.getMaxRowsPerBatch())) {\n                listener.setUseZeroCopy(true);\n                listener.start(batchSource.getVectorSchemaRoot());\n                columnCount = batchSource.getVectorSchemaRoot().getFieldVectors().size();\n                while (batchSource.nextBatch()) {\n                    BackpressureStrategy.WaitResult waitResult;\n                    while ((waitResult = backpressureStrategy.waitForListener(CLIENT_POLL_TIME)) == BackpressureStrategy.WaitResult.TIMEOUT) {\n                        log.debug(format(\"Waiting for client to read from connector %s\", request.getConnectorId()));\n                    }\n                    if (waitResult != BackpressureStrategy.WaitResult.READY) {\n                        log.info(format(\"Read stopped from connector %s due to client wait result: %s\", request.getConnectorId(), waitResult));\n                        break;\n                    }\n                    rowCount += batchSource.getVectorSchemaRoot().getRowCount();","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-flight-shim/src/main/java/com/facebook/presto/flightshim/FlightShimProducer.java#L153-L189","documentation":"FlightShimProducer.runGetStreamAsync builds Arrow field metadata from the request and compares its size against the connector's column handles before creating the page source. If the request's field count differs from the number of column handles, it throws IllegalArgumentException, because results could not be aligned to the requested schema.","triggerScenarios":"A Flight client issues a GetStream/Ticket request whose schema (fields) has a different number of columns than the table/column handles resolved server-side for that ticket.","commonSituations":"Client cached an old schema after the server-side table definition changed; client built the ticket from a different SELECT list than the request schema; concurrent ALTER TABLE between ticket creation and stream request.","solutions":["Regenerate the ticket and request schema from the current table metadata so field count matches","Update the client to build its schema from the same metadata used to create the ticket","Re-fetch the table schema after any DDL change before issuing the stream request"],"exampleFix":"// before (client)\n// schema built from stale 3-column metadata, ticket has 4 column handles\n// after\nSchema schema = fetchCurrentSchema(ticket); // derive fields from same metadata as ticket","handlingStrategy":"validation","validationCode":"// Client-side: assert schema size matches ticket metadata before GetStream\nSchema schema = /* fields from current metadata */;\nif (schema.getFields().size() != ticketColumnHandleCount) {\n  throw new IllegalStateException(\"Stale ticket/schema; refetch metadata\");\n}","typeGuard":null,"tryCatchPattern":"try (FlightStream stream = reader) { ... }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Request has different number of fields\")) {\n    ticket = regenerateTicket(currentMetadata); // refresh and retry once\n  } else throw e;\n}","preventionTips":["Always build the request schema and ticket from the same metadata snapshot","Refetch table metadata after DDL changes before streaming","Fail fast client-side on schema/hash mismatch with the ticket"],"tags":["flight","arrow","schema-mismatch","getstream"],"backgroundTag":"schema-column-count-mismatch","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}