case_sensitive(适用于模型)

本页介绍的是属于 模型 的 case_sensitive 参数。

case_sensitive 也可以用作探索的一部分,如 case_sensitive(适用于探索) 文档页面中所述。

case_sensitive 也可以用作维度或过滤条件字段的一部分,如 case_sensitive(适用于字段) 文档页面中所述。

用法

case_sensitive: yes
层次结构
case_sensitive
默认值
如果数据库方言支持该参数,则为 yes

接受
布尔值(yes 或 no)

定义

case_sensitive 用于确定是否将过滤条件视为给定模型区分大小写。与该模型相关的所有过滤条件都会受到影响,包括在“探索”界面、“信息中心”界面、过滤条件字段或指标的 filters 参数中添加的过滤条件。

case_sensitive 通过调整 Looker 生成的 SQL 的 WHERE 子句来发挥作用。当 case_sensitive: yes 时,过滤条件使用 = 或 LIKE 表示,例如:

WHERE name = 'bob'
WHERE name LIKE '%bob%'

当 case_sensitive: no 时,过滤条件使用 ILIKE(或等效项)表示,例如:

WHERE name ILIKE 'bob'

大多数 SQL 方言都支持 case_sensitive。但是,如果您的 SQL 方言不支持 case_sensitive 参数,则区分大小写的情况会因数据库设置而异,通常不区分大小写。 如需了解方言支持情况,请参阅 case_sensitive 不受某些 SQL 方言支持。

示例

使模型的所有过滤条件都区分大小写:

connection: "connection_name"
include: "filename_or_pattern"
case_sensitive: yes
explore: explore_name {...}

使模型的所有过滤条件都不区分大小写:

connection: "connection_name"
include: "filename_or_pattern"
case_sensitive: no

常见挑战

case_sensitive 不受某些 SQL 方言支持

如需让 Looker 项目支持 case_sensitive,您的数据库方言也必须支持它。下表显示了在最新版 Looker 中哪些方言支持 case_sensitive:

方言 是否支持?
Actian Avalanche
Amazon Athena
Amazon Aurora MySQL
Amazon Redshift
Amazon Redshift 2.1+
Amazon Redshift Serverless 2.1+
Apache Druid
Apache Druid 0.13.x - 0.17.x
Apache Druid 0.18+
Apache Hive 2.3+
Apache Hive 3.1.2+
Apache Spark 3+
ClickHouse
ClickHouse 26+
Cloudera Impala 3.1+
Cloudera Impala 3.1+ with Native Driver
Cloudera Impala with Native Driver
DataVirtuality
Databricks
Denodo 7
Denodo 8 & 9
Dremio
Dremio 11+
Dremio 26+ with Arrow Flight SQL
Exasol
Google BigQuery Legacy SQL
Google BigQuery Standard SQL
Google Cloud AlloyDB for PostgreSQL
Google Cloud PostgreSQL
Google Cloud SQL
Google Spanner
Greenplum
HyperSQL
IBM Netezza
MariaDB
Microsoft Azure PostgreSQL
Microsoft Azure SQL Database
Microsoft Azure Synapse Analytics
Microsoft SQL Server 2008+
Microsoft SQL Server 2012+
Microsoft SQL Server 2016
Microsoft SQL Server 2017+
MongoBI
MongoSQL
MySQL
MySQL 8.0.12+
Oracle
Oracle ADWC
PostgreSQL 9.5+
PostgreSQL pre-9.5
PrestoDB
PrestoSQL
SAP HANA
SAP HANA 2+
SingleStore
SingleStore 7+
Snowflake
Teradata
Trino
Vector
Vertica

DataVirtuality 提供了一个语义数据层,用于连接到各种数据库方言。如果 Looker 支持底层方言的 case_sensitive,则 Looker 支持连接到这些方言的 DataVirtuality 的 case_sensitive。

注意事项

您可以在 MySQL 中创建区分大小写的搜索

您可以在 MySQL 中创建区分大小写的搜索,而无需使用 case_sensitive 参数。在 MySQL 中,某些数据类型(称为二进制字符串)会将文本存储为一系列数字。文本的大小写会影响所使用的数字。因此,如果您将文本转换为二进制字符串,则可以进行区分大小写的搜索。例如:

dimension: will_NOT_be_case_sensitive {
  sql: ${TABLE}.something ;;
}
dimension: will_be_case_sensitive {
  sql: CAST(${TABLE}.something AS BINARY) ;;
}