本页面介绍的是
case_sensitive参数,该参数是 Explore 的一部分。
case_sensitive也可以作为模型的一部分使用,如case_sensitive(适用于模型)参数文档页面中所述。
case_sensitive也可以作为维度的一部分使用,如case_sensitive(适用于字段) 参数文档页面中所述。
用法
explore: explore_name {
case_sensitive: yes
}
|
层次结构
case_sensitive |
默认值
yes,如果数据库方言支持该参数
接受
布尔值(yes 或 no)
|
定义
case_sensitive 用于确定在给定的 Explore 中,过滤条件是否区分大小写。与 Explore 相关的所有过滤条件都会受到影响,包括在 Explore 界面、信息中心界面和 filters 参数中添加的过滤条件。
默认情况下,case_sensitivity 处于开启状态,过滤条件区分大小写。不过,某些方言不支持此参数,如本页面的 case_sensitive 不受某些 SQL 方言支持 部分中所述。
case_sensitive 的工作原理是调整 Looker 生成的 SQL 的 WHERE 子句。 当 case_sensitive 处于开启状态时,过滤条件使用 = 或 LIKE 表示,例如:
WHERE name = 'bob'
WHERE name LIKE '%bob%'
当 case_sensitive 处于关闭状态时,过滤条件使用 ILIKE(或等效项)表示,例如:
WHERE name ILIKE 'bob'
示例
使 Product Explore 的所有过滤条件都区分大小写:
explore: product {
case_sensitive: yes
}
使 Customer Explore 的所有过滤条件都不区分大小写:
explore: customer {
case_sensitive: no
}
常见挑战
case_sensitive 不受某些 SQL 方言支持
默认情况下,case_sensitivity 处于开启状态,过滤条件区分大小写。如果您的 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.x - 0.17.x | |
| 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 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 |
注意事项
您可以在 MySQL 中创建区分大小写的搜索
即使 MySQL 不支持 case_sensitive 参数,您也可以在 MySQL 中创建区分大小写的搜索。在 MySQL 中,某些数据类型(称为二进制字符串)会将文本存储为一系列数字。 文本的大小写会影响所使用的数字。因此,如果您将文本转换为二进制字符串,则可以进行区分大小写的搜索。例如:
dimension: will_NOT_be_case_sensitive {
sql: ${TABLE}.something ;;
}
dimension: will_be_case_sensitive {
sql: CAST(${TABLE}.something AS BINARY) ;;
}