本页面指的是属于模型的
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 参数,区分大小写的情况会因数据库设置而异,通常不区分大小写。方言支持情况列在某些 SQL 方言不支持 case_sensitive 中。
示例
使模型的所有过滤条件都区分大小写:
connection: "connection_name"
include: "filename_or_pattern"
case_sensitive: yes
explore: explore_name {...}
将模型的所有过滤条件设为不区分大小写:
connection: "connection_name"
include: "filename_or_pattern"
case_sensitive: no
常见挑战
某些 SQL 方言不支持 case_sensitive
为了让 Looker 在您的 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+ | |
| Apache Druid 0.18+ | |
| Apache Hive 2.3+ | |
| Apache Hive 3.1.2+ | |
| Apache Spark 3+ | |
| ClickHouse | |
| 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+ | |
| Exasol | |
| Google BigQuery Legacy SQL | |
| Google BigQuery Standard SQL | |
| 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 | |
| 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) ;;
}