Project: ShardingSphere (App Definition and Development / Database)
File: expr.en.md

+++ title = "Row Value Expressions" weight = 10 +++ Type: GROOVY Just use `${ expression }` or `$->{ expression }` in the configuration to identify the row expressions. The content of row expressions uses Groovy syntax, and all operations supported by Groovy are supported by row expressions. `${begin..end}` denotes the range interval, `${[unit1, unit2, unit_x]}` denotes the enumeration value. If there are multiple `${ expression }` or `$->{ expression }` expressions in a row expression, the final result of the whole expression will be a Cartesian combination based on the result of each sub-expression. Example: `<GROOVY>torder${1..3}` will be converted to `torder1, torder2, torder3` `<GROOVY>${['online', 'offline']}table${1..3}` will be converted to `onlinetable1, onlinetable2, onlinetable3, offlinetable1, offlinetable2, offline_table3` The `LITERAL` implementation will not convert any symbols to the expression part, and will directly obtain the output of the standard list from the input of the standard list. This helps address the issue that Groovy expressions are inconvenient to use under GraalVM Native Image. Type: LITERAL Example: `<LITERAL>torder1, torder2, torder3` will be converted to `torder1, torder2, torder3` `<LITERAL>torder${1..3}` will be converted to `torder${1..3}` The `INTERVAL` implementation introduces a Key-Value style property syntax to define a set of time ranges of strings via a single line string. This is often used to simplify the definition of `actualDataNodes` for `Sharding` feature. `INTERVAL` implements the method of defining multiple attributes as `Key1=Value1;Key2=Value2`, using `;` to separate key-value pairs, and `=` to separate `Key` values and `Value` values. This implementation actively ignores the time zone information of `SP`, which means that when `DL` and `DU` contain time zone information, no time zone conversion will occur due to inconsistent time zones. This implementation is not sensitive to the order of key-value pairs, and the line expression does not carry the `;` sign at the end. The `INTERVAL` implementation introduces the following Key values: `P` stands for the abbreviation of prefix, which means the prefix of the result list unit, usually representing the prefix format of the real table. `SP` stands for the abbreviation of suffix pattern, which means the timestamp format of the suffix of the result list unit. It usually represents the suffix format of the real table and must follow the format of Java DateTimeFormatter. For example: yyyyMMdd, yyyyMM or yyyy etc. `DIA` stands for the abbreviation of datetime interval amount, which means the time interval of the result list unit. `DIU` stands for the abbreviation of datetime interval unit, which means the shard key time interval unit. It must follow the enumeration value of Java `java.time.temporal.ChronoUnit#toString()`. For example: `Months`. `DL` stands for the abbreviation of datetime lower, which means the lower bound of time. The format is consistent with the timestamp format defined by

`DU` stands for the abbreviation of datetime upper, which means the upper bound value of time. The format is consistent with the timestamp format defined by `SP`. `C` stands for the abbreviation of chronology, which means calendar system and must follow the format of Java `java.time.chrono.Chronology#getId()`. For example: `Japanese`, `Minguo`, `ThaiBuddhist`. There is a default value of `ISO`. Whether the Value corresponding to the Key of `C` is available depends on the system environment in which the JVM is located. This means that if the user needs to set `C=Japanese`, they may need to call `java.util.Locale.setDefault(java.util.Locale.JAPAN);` in the application's startup class to modify the system environment. Discuss two JVM environments. Hotspot JVM determines the return value of `java.util.Locale.getDefault()` at RunTime. GraalVM Native Image determines the return value of `java.util.Locale.Locale.getDefault()` at BuildTime, which is inconsistent with the performance of Hotspot JVM. Refer to https://github.com/oracle/graal/issues/8022 . Type: INTERVAL Example: `<INTERVAL>P=torder;SP=yyyyMMdd;DIA=1;DIU=Days;DL=20231202;DU=20231204` will be converted to `torder20231202, torder20231203, torder20231204` `<INTERVAL>P=torder;SP=yyyyMM;DIA=1;DIU=Months;DL=202310;DU=202312` will be converted to `torder202310, torder202311, torder202312` `<INTERVAL>P=torder;SP=yyyy;DIA=1;DIU=Years;DL=2021;DU=2023` will be converted to `torder2021, torder2022, torder2023` `<INTERVAL>P=torder;SP=HHmmssSSS;DIA=1;DIU=Millis;DL=224852131;DU=224852133` will be converted to `torder224852131, torder224852132, torder224852133` `<INTERVAL>P=torder;SP=yyyyMMddHHmmssSSS;DIA=1;DIU=Days;DL=20231204224852131;DU=20231206224852131` will be converted to `torder20231204224852131, torder20231205224852131, torder20231206224852131` `<INTERVAL>P=torder;SP=MM;DIA=1;DIU=Months;DL=10;DU=12` will be converted to `torder10, torder11, torder12` `<INTERVAL>P=torder;SP=GGGGyyyyMMdd;DIA=1;DIU=Days;DL=00011205;DU=00011206;C=Japanese` will be converted to `torder00011205, torder00011206` `<INTERVAL>P=torder;SP=GGGGyyyMMdd;DIA=1;DIU=Days;DL=0011205;DU=0011206;C=Japanese` will be converted to `torder0011205, torder0011206` `<INTERVAL>P=torder;SP=GGGGyMMdd;DIA=1;DIU=Days;DL=11205;DU=11206;C=Japanese` will be converted to `torder11205, torder11206` This is an optional implementation. You need to actively declare the following dependencies in the `pom.xml` of your own project. And please make sure your own projects are compiled with OpenJDK 21+ or its downstream distribution. Due to the limitations of https://www.graalvm.org/jdk21/reference-manual/java-on-truffle/faq/#does-java-running-on-truffle-run-on-hotspot-too , this module is only ready on Linux when used in environments other than GraalVM Native Image. Truffle's backward compatibility matrix with the JDK is located at https://medium.com/graalvm/40027a59c401 . ```xml <dependencies> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-infra-expr-espresso</artifactId> <version>${shardingsphere.version}</version> </dependency> <dependency> <groupId>org.graalvm.polyglot</groupId> <artifactId>polyglot</artifactId> <version>24.0.0</version> </dependency> <dependency> <groupId>org.graalvm.polyglot</groupId> <artifactId>java-community</artifactId> <version>24.0.0</version> <type>pom</type> </dependency> </dependencies> ``` `ESPRESSO` is still an experimental module that allows the use of Row Value Expressions with Groovy syntax under GraalVM Native Image through the Espresso implementation of GraalVM Truffle. The syntax part is the same as the `GROOVY` implementation rules. Type: ESPRESSO Example: `<ESPRESSO>torder${1..3}` will be converted to `torder1, torder2, torder3` `<ESPRESSO>${['online', 'offline']}table${1..3}` will be converted to `onlinetable1, onlinetable2, onlinetable3, offlinetable1, offlinetable2, offline_table3` When using attributes that require the use of `Row Value Expressions`, such as in the `data sharding` feature, it is sufficient to indicate the Type Name of the specific SPI implementation under the `actualDataNodes` attribute. If the `Row Value Expressions` does not indicate the Type Name of the SPI, the SPI implementation of `GROOVY` will be used by default. ```yaml rules: !SHARDING tables: t_order: actualDataNodes: <LITERAL>ds0.torder0, ds0.torder1, ds1.torder0, ds1.torder1 tableStrategy: standard: shardingColumn: order_id shardingAlgorithmName: torderinline keyGenerateStrategy: column: order_id keyGeneratorName: snowflake defaultDatabaseStrategy: standard: shardingColumn: user_id shardingAlgorithmName: database_inline shardingAlgorithms: database_inline: type: INLINE props: algorithm-expression: <GROOVY>ds${userid % 2} torderinline: type: INLINE props: algorithm-expression: torder${order_id % 2} keyGenerators: snowflake: type: SNOWFLAKE ```