{"record":{"id":"2f85066c92876abd","repo":"influxdata/influxdb","slug":"cannot-use-a-column-of-type-attempted-in-a-distinct-value","errorCode":null,"errorMessage":"cannot use a column of type {attempted} in a distinct value cache, only tags and string fields can be used","messagePattern":"cannot use a column of type (.+?) in a distinct value cache, only tags and string fields can be used","errorType":"validation","errorClass":"CacheError","httpStatus":null,"severity":"error","filePath":"influxdb3_cache/src/distinct_cache/cache.rs","lineNumber":26,"sourceCode":"use arrow::{\n    array::{ArrayRef, RecordBatch, StringViewBuilder},\n    datatypes::{DataType, Field, SchemaBuilder, SchemaRef},\n    error::ArrowError,\n};\nuse indexmap::IndexMap;\nuse influxdb3_catalog::catalog::legacy;\nuse influxdb3_catalog::catalog::{MaxAge, MaxCardinality, TableDefinition};\nuse influxdb3_id::{ColumnId, ColumnIdentifier};\nuse influxdb3_wal::{FieldData, Row};\nuse iox_time::TimeProvider;\nuse observability_deps::tracing::debug;\nuse schema::{InfluxColumnType, InfluxFieldType};\n\n#[derive(Debug, thiserror::Error)]\npub enum CacheError {\n    #[error(\"must pass a non-empty set of column ids\")]\n    EmptyColumnSet,\n    #[error(\n        \"cannot use a column of type {attempted} in a distinct value cache, only \\\n                    tags and string fields can be used\"\n    )]\n    NonTagOrStringColumn { attempted: InfluxColumnType },\n    #[error(\"cannot overwrite an an existing cache: {message}\")]\n    ConfigurationMismatch { message: String },\n    #[error(\"unexpected error: {0}\")]\n    Unexpected(#[from] anyhow::Error),\n}\n\n/// A cache for storing distinct values for a set of columns in a table\n#[derive(Debug)]\npub(crate) struct DistinctCache {\n    time_provider: Arc<dyn TimeProvider>,\n    /// The maximum number of unique value combinations in the cache\n    max_cardinality: usize,\n    /// The maximum age for entries in the cache\n    max_age: Duration,","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_cache/src/distinct_cache/cache.rs#L8-L44","documentation":"CacheError::NonTagOrStringColumn is returned when a distinct value cache is attempted on a column whose InfluxColumnType is neither a tag nor a string field. Distinct caches only work over string-valued data; numeric, timestamp, or boolean columns are rejected.","triggerScenarios":"CREATE DISTINCT CACHE or new_cache with a column id that resolves to a field of type integer/uint/float/boolean/timestamp instead of tag or string field.","commonSituations":"Misremembering which columns are tags; schema changes turned a former tag into a numeric field; hand-written cache configs referencing the wrong column.","solutions":["Choose only tag columns or string field columns for the distinct cache","Inspect the table schema (schema::Schema) and filter candidate columns to InfluxColumnType::Tag and String field variants before creating the cache","Fix the SQL statement to name a string-valued column"],"exampleFix":"// before\nlet cols = vec![numeric_field_col_id];\nprovider.new_cache(table_id, cols)?;\n// after\nlet ok = schema.fields().iter().any(|f| matches!(f.data_type(), InfluxColumnType::Tag | InfluxColumnType::Field(InfluxFieldType::String)));\nassert!(ok, \"column must be a tag or string field\");","handlingStrategy":"validation","validationCode":"fn column_is_tag_or_string(col: &schema::Column) -> bool {\n    matches!(col.data_type, InfluxColumnType::Tag | InfluxColumnType::Field(InfluxFieldType::String))\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch provider.new_cache(table_id, cols) {\n    Err(ProviderError::Cache(CacheError::NonTagOrStringColumn { attempted })) => {\n        bail!(\"column type {attempted:?} not allowed in distinct cache; use tags or string fields\")\n    }\n    other => other,\n}","preventionTips":["Verify the table schema before choosing cache columns","Re-validate cache definitions after schema migrations","Only expose tag and string-field columns in cache-creation UIs"],"tags":["validation","distinct-cache","type-mismatch","influxdb3"],"backgroundTag":"type-mismatch","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}