diff --git a/docs/en/10-cluster/02-cluster-mgmt.md b/docs/en/10-cluster/02-cluster-mgmt.md index 674c92e276..bd3386c411 100644 --- a/docs/en/10-cluster/02-cluster-mgmt.md +++ b/docs/en/10-cluster/02-cluster-mgmt.md @@ -54,14 +54,14 @@ Database changed. taos> show vgroups; vgId | tables | status | onlines | v1_dnode | v1_status | compacting | ========================================================================================== - 14 | 38000 | ready | 1 | 1 | master | 0 | - 15 | 38000 | ready | 1 | 1 | master | 0 | - 16 | 38000 | ready | 1 | 1 | master | 0 | - 17 | 38000 | ready | 1 | 1 | master | 0 | - 18 | 37001 | ready | 1 | 1 | master | 0 | - 19 | 37000 | ready | 1 | 1 | master | 0 | - 20 | 37000 | ready | 1 | 1 | master | 0 | - 21 | 37000 | ready | 1 | 1 | master | 0 | + 14 | 38000 | ready | 1 | 1 | leader | 0 | + 15 | 38000 | ready | 1 | 1 | leader | 0 | + 16 | 38000 | ready | 1 | 1 | leader | 0 | + 17 | 38000 | ready | 1 | 1 | leader | 0 | + 18 | 37001 | ready | 1 | 1 | leader | 0 | + 19 | 37000 | ready | 1 | 1 | leader | 0 | + 20 | 37000 | ready | 1 | 1 | leader | 0 | + 21 | 37000 | ready | 1 | 1 | leader | 0 | Query OK, 8 row(s) in set (0.001154s) ``` @@ -161,14 +161,14 @@ First `show vgroups` is executed to show the vgroup distribution. taos> show vgroups; vgId | tables | status | onlines | v1_dnode | v1_status | compacting | ========================================================================================== - 14 | 38000 | ready | 1 | 3 | master | 0 | - 15 | 38000 | ready | 1 | 3 | master | 0 | - 16 | 38000 | ready | 1 | 3 | master | 0 | - 17 | 38000 | ready | 1 | 3 | master | 0 | - 18 | 37001 | ready | 1 | 3 | master | 0 | - 19 | 37000 | ready | 1 | 1 | master | 0 | - 20 | 37000 | ready | 1 | 1 | master | 0 | - 21 | 37000 | ready | 1 | 1 | master | 0 | + 14 | 38000 | ready | 1 | 3 | leader | 0 | + 15 | 38000 | ready | 1 | 3 | leader | 0 | + 16 | 38000 | ready | 1 | 3 | leader | 0 | + 17 | 38000 | ready | 1 | 3 | leader | 0 | + 18 | 37001 | ready | 1 | 3 | leader | 0 | + 19 | 37000 | ready | 1 | 1 | leader | 0 | + 20 | 37000 | ready | 1 | 1 | leader | 0 | + 21 | 37000 | ready | 1 | 1 | leader | 0 | Query OK, 8 row(s) in set (0.001314s) ``` @@ -191,14 +191,14 @@ Query OK, 0 row(s) in set (0.000575s) taos> show vgroups; vgId | tables | status | onlines | v1_dnode | v1_status | v2_dnode | v2_status | compacting | ================================================================================================================= - 14 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 | - 15 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 | - 16 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 | - 17 | 38000 | ready | 1 | 3 | master | 0 | NULL | 0 | - 18 | 37001 | ready | 2 | 1 | slave | 3 | master | 0 | - 19 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 | - 20 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 | - 21 | 37000 | ready | 1 | 1 | master | 0 | NULL | 0 | + 14 | 38000 | ready | 1 | 3 | leader | 0 | NULL | 0 | + 15 | 38000 | ready | 1 | 3 | leader | 0 | NULL | 0 | + 16 | 38000 | ready | 1 | 3 | leader | 0 | NULL | 0 | + 17 | 38000 | ready | 1 | 3 | leader | 0 | NULL | 0 | + 18 | 37001 | ready | 2 | 1 | follower | 3 | leader | 0 | + 19 | 37000 | ready | 1 | 1 | leader | 0 | NULL | 0 | + 20 | 37000 | ready | 1 | 1 | leader | 0 | NULL | 0 | + 21 | 37000 | ready | 1 | 1 | leader | 0 | NULL | 0 | Query OK, 8 row(s) in set (0.001242s) ``` @@ -207,7 +207,7 @@ It can be seen from above output that vgId 18 has been moved from dnode 3 to dno :::note - Manual load balancing can only be performed when the automatic load balancing is disabled, i.e. `balance` is set to 0. -- Only a vnode in normal state, i.e. master or slave, can be moved. vnode can't be moved when its in status offline, unsynced or syncing. +- Only a vnode in normal state, i.e. leader or follower, can be moved. vnode can't be moved when its in status offline, unsynced or syncing. - Before moving a vnode, it's necessary to make sure the target dnode has enough resources: CPU, memory and disk. ::: diff --git a/docs/en/10-cluster/03-ha-and-lb.md b/docs/en/10-cluster/03-ha-and-lb.md index bd718eef9f..9780e8f6c6 100644 --- a/docs/en/10-cluster/03-ha-and-lb.md +++ b/docs/en/10-cluster/03-ha-and-lb.md @@ -27,7 +27,7 @@ There may be multiple dnodes in a cluster, but only one mnode can be started in SHOW MNODES; ``` -The end point and role/status (master, slave, unsynced, or offline) of all mnodes can be shown by the above command. When the first dnode is started in a cluster, there must be one mnode in this dnode. Without at least one mnode, the cluster cannot work. If `numOfMNodes` is configured to 2, another mnode will be started when the second dnode is launched. +The end point and role/status (leader, follower, unsynced, or offline) of all mnodes can be shown by the above command. When the first dnode is started in a cluster, there must be one mnode in this dnode. Without at least one mnode, the cluster cannot work. If `numOfMNodes` is configured to 2, another mnode will be started when the second dnode is launched. For the high availability of mnode, `numOfMnodes` needs to be configured to 2 or a higher value. Because the data consistency between mnodes must be guaranteed, the replica confirmation parameter `quorum` is set to 2 automatically if `numOfMNodes` is set to 2 or higher. @@ -58,13 +58,13 @@ When a dnode is offline, it can be detected by the TDengine cluster. There are t - If the dnode has been offline over the threshold configured in `offlineThreshold` in `taos.cfg`, the dnode will be removed from the cluster automatically. A system alert will be generated and automatic load balancing will be triggered if `balance` is set to 1. When the removed dnode is restarted and becomes online, it will not join the cluster automatically. The system administrator has to manually join the dnode to the cluster. :::note -If all the vnodes in a vgroup (or mnodes in mnode group) are in offline or unsynced status, the master node can only be voted on, after all the vnodes or mnodes in the group become online and can exchange status. Following this, the vgroup (or mnode group) is able to provide service. +If all the vnodes in a vgroup (or mnodes in mnode group) are in offline or unsynced status, the leader node can only be voted on, after all the vnodes or mnodes in the group become online and can exchange status. Following this, the vgroup (or mnode group) is able to provide service. ::: ## Arbitrator -The "arbitrator" component is used to address the special case when the number of replicas is set to an even number like 2,4 etc. If half of the vnodes in a vgroup don't work, it is impossible to vote and select a master node. This situation also applies to mnodes if the number of mnodes is set to an even number like 2,4 etc. +The "arbitrator" component is used to address the special case when the number of replicas is set to an even number like 2,4 etc. If half of the vnodes in a vgroup don't work, it is impossible to vote and select a leader node. This situation also applies to mnodes if the number of mnodes is set to an even number like 2,4 etc. To resolve this problem, a new arbitrator component named `tarbitrator`, an abbreviation of TDengine Arbitrator, was introduced. The `tarbitrator` simulates a vnode or mnode but it's only responsible for network communication and doesn't handle any actual data access. As long as more than half of the vnode or mnode, including Arbitrator, are available the vnode group or mnode group can provide data insertion or query services normally. diff --git a/docs/en/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json b/docs/en/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json index f651983528..54dc1062d6 100644 --- a/docs/en/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json +++ b/docs/en/14-reference/07-tdinsight/assets/15146-tdengine-monitor-dashboard.json @@ -211,7 +211,7 @@ ], "timeFrom": null, "timeShift": null, - "title": "Master MNode", + "title": "Leader MNode", "transformations": [ { "id": "filterByValue", @@ -221,7 +221,7 @@ "config": { "id": "regex", "options": { - "value": "master" + "value": "leader" } }, "fieldName": "role" @@ -300,7 +300,7 @@ ], "timeFrom": null, "timeShift": null, - "title": "Master MNode Create Time", + "title": "Leader MNode Create Time", "transformations": [ { "id": "filterByValue", @@ -310,7 +310,7 @@ "config": { "id": "regex", "options": { - "value": "master" + "value": "leader" } }, "fieldName": "role" diff --git a/docs/en/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json b/docs/en/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json index b4254c428b..1add8522a7 100644 --- a/docs/en/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json +++ b/docs/en/14-reference/07-tdinsight/assets/tdengine-grafana-7.x.json @@ -153,7 +153,7 @@ ], "timeFrom": null, "timeShift": null, - "title": "Master MNode", + "title": "Leader MNode", "transformations": [ { "id": "filterByValue", @@ -163,7 +163,7 @@ "config": { "id": "regex", "options": { - "value": "master" + "value": "leader" } }, "fieldName": "role" @@ -246,7 +246,7 @@ ], "timeFrom": null, "timeShift": null, - "title": "Master MNode Create Time", + "title": "Leader MNode Create Time", "transformations": [ { "id": "filterByValue", @@ -256,7 +256,7 @@ "config": { "id": "regex", "options": { - "value": "master" + "value": "leader" } }, "fieldName": "role" diff --git a/docs/en/14-reference/07-tdinsight/index.md b/docs/en/14-reference/07-tdinsight/index.md index cebfafa225..e74c9de7b2 100644 --- a/docs/en/14-reference/07-tdinsight/index.md +++ b/docs/en/14-reference/07-tdinsight/index.md @@ -274,8 +274,8 @@ Details of the metrics are as follows. This section contains the current information and status of the cluster, the alert information is also here (from left to right, top to bottom). - **First EP**: the `firstEp` setting in the current TDengine cluster. -- **Version**: TDengine server version (master mnode). -- **Master Uptime**: The time elapsed since the current Master MNode was elected as Master. +- **Version**: TDengine server version (leader mnode). +- **Leader Uptime**: The time elapsed since the current Leader MNode was elected as Leader. - **Expire Time** - Enterprise version expiration time. - **Used Measuring Points** - The number of measuring points used by the Enterprise Edition. - **Databases** - The number of databases. @@ -333,7 +333,7 @@ Data node resource usage display with repeated multiple rows for the variable `$ 2. **Has MNodes?**: whether the current dnode is a mnode. 3. **CPU Cores**: the number of CPU cores. 4. **VNodes Number**: the number of VNodes in the current dnode. -5. **VNodes Masters**: the number of vnodes in the master role. +5. **VNodes Masters**: the number of vnodes in the leader role. 6. **Current CPU Usage of taosd**: CPU usage rate of taosd processes. 7. **Current Memory Usage of taosd**: memory usage of taosd processes. 8. **Disk Used**: The total disk usage percentage of the taosd data directory. diff --git a/docs/en/21-tdinternal/01-arch.md b/docs/en/21-tdinternal/01-arch.md index 4d8bed4d2d..d7d472eb98 100644 --- a/docs/en/21-tdinternal/01-arch.md +++ b/docs/en/21-tdinternal/01-arch.md @@ -22,9 +22,9 @@ A complete TDengine system runs on one or more physical nodes. Logically, it inc **Virtual node (vnode)**: To better support data sharding, load balancing and prevent data from overheating or skewing, data nodes are virtualized into multiple virtual nodes (vnode, V2, V3, V4, etc. in the figure). Each vnode is a relatively independent work unit, which is the basic unit of time-series data storage and has independent running threads, memory space and persistent storage path. A vnode contains a certain number of tables (data collection points). When a new table is created, the system checks whether a new vnode needs to be created. The number of vnodes that can be created on a data node depends on the capacity of the hardware of the physical node where the data node is located. A vnode belongs to only one DB, but a DB can have multiple vnodes. In addition to the stored time-series data, a vnode also stores the schema and tag values of the included tables. A virtual node is uniquely identified in the system by the EP of the data node and the VGroup ID to which it belongs and is created and managed by the management node. -**Management node (mnode)**: A virtual logical unit responsible for monitoring and maintaining the running status of all data nodes and load balancing among nodes (M in the figure). At the same time, the management node is also responsible for the storage and management of metadata (including users, databases, tables, static tags, etc.), so it is also called Meta Node. Multiple (up to 5) mnodes can be configured in a TDengine cluster, and they are automatically constructed into a virtual management node group (M0, M1, M2 in the figure). The master/slave mechanism is adopted for the mnode group and the data synchronization is carried out in a strongly consistent way. Any data update operation can only be executed on the master. The creation of mnode cluster is completed automatically by the system without manual intervention. There is at most one mnode on each dnode, which is uniquely identified by the EP of the data node to which it belongs. Each dnode automatically obtains the EP of the dnode where all mnodes in the whole cluster are located, through internal messaging interaction. +**Management node (mnode)**: A virtual logical unit responsible for monitoring and maintaining the running status of all data nodes and load balancing among nodes (M in the figure). At the same time, the management node is also responsible for the storage and management of metadata (including users, databases, tables, static tags, etc.), so it is also called Meta Node. Multiple (up to 5) mnodes can be configured in a TDengine cluster, and they are automatically constructed into a virtual management node group (M0, M1, M2 in the figure). The leader/follower mechanism is adopted for the mnode group and the data synchronization is carried out in a strongly consistent way. Any data update operation can only be executed on the leader. The creation of mnode cluster is completed automatically by the system without manual intervention. There is at most one mnode on each dnode, which is uniquely identified by the EP of the data node to which it belongs. Each dnode automatically obtains the EP of the dnode where all mnodes in the whole cluster are located, through internal messaging interaction. -**Virtual node group (VGroup)**: Vnodes on different data nodes can form a virtual node group to ensure the high availability of the system. The virtual node group is managed in a master/slave mechanism. Write operations can only be performed on the master vnode, and then replicated to slave vnodes, thus ensuring that one single replica of data is copied on multiple physical nodes. The number of virtual nodes in a vgroup equals the number of data replicas. If the number of replicas of a DB is N, the system must have at least N data nodes. The number of replicas can be specified by the parameter `“replica”` when creating a DB, and the default is 1. Using the multi-replication feature of TDengine, the same high data reliability can be achieved without the need for expensive storage devices such as disk arrays. Virtual node groups are created and managed by the management node, and the management node assigns a system unique ID, aka VGroup ID. If two virtual nodes have the same vnode group ID, it means that they belong to the same group and the data is backed up to each other. The number of virtual nodes in a virtual node group can be dynamically changed, allowing only one, that is, no data replication. VGroup ID is never changed. Even if a virtual node group is deleted, its ID will not be reused. +**Virtual node group (VGroup)**: Vnodes on different data nodes can form a virtual node group to ensure the high availability of the system. The virtual node group is managed in a leader/follower mechanism. Write operations can only be performed on the leader vnode, and then replicated to follower vnodes, thus ensuring that one single replica of data is copied on multiple physical nodes. The number of virtual nodes in a vgroup equals the number of data replicas. If the number of replicas of a DB is N, the system must have at least N data nodes. The number of replicas can be specified by the parameter `“replica”` when creating a DB, and the default is 1. Using the multi-replication feature of TDengine, the same high data reliability can be achieved without the need for expensive storage devices such as disk arrays. Virtual node groups are created and managed by the management node, and the management node assigns a system unique ID, aka VGroup ID. If two virtual nodes have the same vnode group ID, it means that they belong to the same group and the data is backed up to each other. The number of virtual nodes in a virtual node group can be dynamically changed, allowing only one, that is, no data replication. VGroup ID is never changed. Even if a virtual node group is deleted, its ID will not be reused. **TAOSC**: TAOSC is the driver provided by TDengine to applications. It is responsible for dealing with the interaction between application and cluster, and provides the native interface for the C/C++ language. It is also embedded in the JDBC, C #, Python, Go, Node.js language connection libraries. Applications interact with the whole cluster through TAOSC instead of directly connecting to data nodes in the cluster. This module is responsible for obtaining and caching metadata; forwarding requests for insertion, query, etc. to the correct data node; when returning the results to the application, TAOSC also needs to be responsible for the final level of aggregation, sorting, filtering and other operations. For JDBC, C/C++/C#/Python/Go/Node.js interfaces, this module runs on the physical node where the application is located. At the same time, in order to support the fully distributed RESTful interface, TAOSC has a running instance on each dnode of TDengine cluster. @@ -62,13 +62,13 @@ To explain the relationship between vnode, mnode, TAOSC and application and thei 1. Application initiates a request to insert data through JDBC, ODBC, or other APIs. 2. TAOSC checks the cache to see if meta data exists for the table. If it does, it goes straight to Step 4. If not, TAOSC sends a get meta-data request to mnode. 3. Mnode returns the meta-data of the table to TAOSC. Meta-data contains the schema of the table, and also the vgroup information to which the table belongs (the vnode ID and the End Point of the dnode where the table belongs. If the number of replicas is N, there will be N groups of End Points). If TAOSC does not receive a response from the mnode for a long time, and there are multiple mnodes, TAOSC will send a request to the next mnode. -4. TAOSC initiates an insert request to master vnode. +4. TAOSC initiates an insert request to leader vnode. 5. After vnode inserts the data, it gives a reply to TAOSC, indicating that the insertion is successful. If TAOSC doesn't get a response from vnode for a long time, TAOSC will treat this node as offline. In this case, if there are multiple replicas of the inserted database, TAOSC will issue an insert request to the next vnode in vgroup. 6. TAOSC notifies APP that writing is successful. For Step 2 and 3, when TAOSC starts, it does not know the End Point of mnode, so it will directly initiate a request to the configured serving End Point of the cluster. If the dnode that receives the request does not have a mnode configured, it will reply with the mnode EP list, so that TAOSC will re-issue a request to obtain meta-data to the EP of another mnode. -For Step 4 and 5, without caching, TAOSC can't recognize the master in the virtual node group, so assumes that the first vnode is the master and sends a request to it. If this vnode is not the master, it will reply to the actual master as a new target to which TAOSC shall send a request. Once a response of successful insertion is obtained, TAOSC will cache the information of master node. +For Step 4 and 5, without caching, TAOSC can't recognize the leader in the virtual node group, so assumes that the first vnode is the leader and sends a request to it. If this vnode is not the leader, it will reply to the actual leader as a new target to which TAOSC shall send a request. Once a response of successful insertion is obtained, TAOSC will cache the information of leader node. The above describes the process of inserting data. The processes of querying and computing are the same. TAOSC encapsulates and hides all these complicated processes, and it is transparent to applications. @@ -119,65 +119,65 @@ The load balancing process does not require any manual intervention, and it is t ## Data Writing and Replication Process -If a database has N replicas, a virtual node group has N virtual nodes. But only one is the Master and all others are slaves. When the application writes a new record to system, only the Master vnode can accept the writing request. If a slave vnode receives a writing request, the system will notifies TAOSC to redirect. +If a database has N replicas, a virtual node group has N virtual nodes. But only one is the Leader and all others are slaves. When the application writes a new record to system, only the Leader vnode can accept the writing request. If a follower vnode receives a writing request, the system will notifies TAOSC to redirect. -### Master vnode Writing Process +### Leader vnode Writing Process -Master Vnode uses a writing process as follows: +Leader Vnode uses a writing process as follows: -![TDengine Database Master Writing Process](write_master.webp) -
Figure 3: TDengine Master writing process
+![TDengine Database Leader Writing Process](write_master.webp) +
Figure 3: TDengine Leader writing process
-1. Master vnode receives the application data insertion request, verifies, and moves to next step; +1. Leader vnode receives the application data insertion request, verifies, and moves to next step; 2. If the system configuration parameter `“walLevel”` is greater than 0, vnode will write the original request packet into database log file WAL. If walLevel is set to 2 and fsync is set to 0, TDengine will make WAL data written immediately to ensure that even system goes down, all data can be recovered from database log file; -3. If there are multiple replicas, vnode will forward data packet to slave vnodes in the same virtual node group, and the forwarded packet has a version number with data; +3. If there are multiple replicas, vnode will forward data packet to follower vnodes in the same virtual node group, and the forwarded packet has a version number with data; 4. Write into memory and add the record to “skip list”; -5. Master vnode returns a confirmation message to the application, indicating a successful write. +5. Leader vnode returns a confirmation message to the application, indicating a successful write. 6. If any of Step 2, 3 or 4 fails, the error will directly return to the application. -### Slave vnode Writing Process +### Follower vnode Writing Process -For a slave vnode, the write process as follows: +For a follower vnode, the write process as follows: -![TDengine Database Slave Writing Process](write_slave.webp) -
Figure 4: TDengine Slave Writing Process
+![TDengine Database Follower Writing Process](write_slave.webp) +
Figure 4: TDengine Follower Writing Process
-1. Slave vnode receives a data insertion request forwarded by Master vnode; +1. Follower vnode receives a data insertion request forwarded by Leader vnode; 2. If the system configuration parameter `“walLevel”` is greater than 0, vnode will write the original request packet into database log file WAL. If walLevel is set to 2 and fsync is set to 0, TDengine will make WAL data written immediately to ensure that even system goes down, all data can be recovered from database log file; 3. Write into memory and add the record to “skip list”. -Compared with Master vnode, slave vnode has no forwarding or reply confirmation step, means two steps less. But writing into memory and WAL is exactly the same. +Compared with Leader vnode, follower vnode has no forwarding or reply confirmation step, means two steps less. But writing into memory and WAL is exactly the same. ### Remote Disaster Recovery and IDC (Internet Data Center) Migration -As discussed above, TDengine writes using Master and Slave processes. TDengine adopts asynchronous replication for data synchronization. This method can greatly improve write performance, with no obvious impact from network delay. By configuring IDC and rack number for each physical node, it can be ensured that for a virtual node group, virtual nodes are composed of physical nodes from different IDC and different racks, thus implementing remote disaster recovery without other tools. +As discussed above, TDengine writes using Leader and Follower processes. TDengine adopts asynchronous replication for data synchronization. This method can greatly improve write performance, with no obvious impact from network delay. By configuring IDC and rack number for each physical node, it can be ensured that for a virtual node group, virtual nodes are composed of physical nodes from different IDC and different racks, thus implementing remote disaster recovery without other tools. -On the other hand, TDengine supports dynamic modification of the replica number. Once the number of replicas increases, the newly added virtual nodes will immediately enter the data synchronization process. After synchronization is complete, added virtual nodes can provide services. In the synchronization process, master and other synchronized virtual nodes keep serving. With this feature, TDengine can provide IDC migration without service interruption. It is only necessary to add new physical nodes to the existing IDC cluster, and then remove old physical nodes after the data synchronization is completed. +On the other hand, TDengine supports dynamic modification of the replica number. Once the number of replicas increases, the newly added virtual nodes will immediately enter the data synchronization process. After synchronization is complete, added virtual nodes can provide services. In the synchronization process, leader and other synchronized virtual nodes keep serving. With this feature, TDengine can provide IDC migration without service interruption. It is only necessary to add new physical nodes to the existing IDC cluster, and then remove old physical nodes after the data synchronization is completed. However, the asynchronous replication has a very low probability scenario where data may be lost. The specific scenario is as follows: -1. Master vnode has finished its 5-step operations, confirmed the success of writing to APP, and then goes down; -2. Slave vnode receives the write request, then processing fails before writing to the log in Step 2; -3. Slave vnode will become the new master, thus losing one record. +1. Leader vnode has finished its 5-step operations, confirmed the success of writing to APP, and then goes down; +2. Follower vnode receives the write request, then processing fails before writing to the log in Step 2; +3. Follower vnode will become the new leader, thus losing one record. In theory, for asynchronous replication, there is no guarantee to prevent data loss. However, this is an extremely low probability scenario as described above. Note: Remote disaster recovery and no-downtime IDC migration are only supported by Enterprise Edition. **Hint: This function is not available yet** -### Master/slave Selection +### Leader/follower Selection Vnode maintains a version number. When memory data is persisted, the version number will also be persisted. For each data update operation, whether it is time-series data or metadata, this version number will be increased by one. -When a vnode starts, the roles (master, slave) are uncertain, and the data is in an unsynchronized state. It’s necessary to establish TCP connections with other nodes in the virtual node group and exchange status, including version and its own roles. Through the exchange, the system implements a master-selection process. The rules are as follows: +When a vnode starts, the roles (leader, follower) are uncertain, and the data is in an unsynchronized state. It’s necessary to establish TCP connections with other nodes in the virtual node group and exchange status, including version and its own roles. Through the exchange, the system implements a leader-selection process. The rules are as follows: -1. If there’s only one replica, it’s always master -2. When all replicas are online, the one with latest version is master -3. Over half of online nodes are virtual nodes, and some virtual node is slave, it will automatically become master -4. For 2 and 3, if multiple virtual nodes meet the requirement, the first vnode in virtual node group list will be selected as master. +1. If there’s only one replica, it’s always leader +2. When all replicas are online, the one with latest version is leader +3. Over half of online nodes are virtual nodes, and some virtual node is follower, it will automatically become leader +4. For 2 and 3, if multiple virtual nodes meet the requirement, the first vnode in virtual node group list will be selected as leader. ### Synchronous Replication -For scenarios with strong data consistency requirements, asynchronous data replication is not applicable, because there is a small probability of data loss. So, TDengine provides a synchronous replication mechanism for users. When creating a database, in addition to specifying the number of replicas, user also needs to specify a new parameter “quorum”. If quorum is greater than one, it means that every time the Master forwards a message to the replica, it needs to wait for “quorum-1” reply confirms before informing the application that data has been successfully written in slave. If “quorum-1” reply confirms are not received within a certain period of time, the master vnode will return an error to the application. +For scenarios with strong data consistency requirements, asynchronous data replication is not applicable, because there is a small probability of data loss. So, TDengine provides a synchronous replication mechanism for users. When creating a database, in addition to specifying the number of replicas, user also needs to specify a new parameter “quorum”. If quorum is greater than one, it means that every time the Leader forwards a message to the replica, it needs to wait for “quorum-1” reply confirms before informing the application that data has been successfully written in follower. If “quorum-1” reply confirms are not received within a certain period of time, the leader vnode will return an error to the application. With synchronous replication, performance of system will decrease and latency will increase. Because metadata needs strong consistency, the default for data synchronization between mnodes is synchronous replication. diff --git a/examples/c/tmq.c b/examples/c/tmq.c index 7870d7d9a1..6fb7e7a1fc 100644 --- a/examples/c/tmq.c +++ b/examples/c/tmq.c @@ -26,6 +26,14 @@ static void msg_process(TAOS_RES* msg) { printf("topic: %s\n", tmq_get_topic_name(msg)); printf("db: %s\n", tmq_get_db_name(msg)); printf("vg: %d\n", tmq_get_vgroup_id(msg)); + if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META) { + void* meta; + int32_t metaLen; + tmq_get_raw_meta(msg, &meta, &metaLen); + + printf("meta, len is %d\n", metaLen); + return; + } while (1) { TAOS_ROW row = taos_fetch_row(msg); if (row == NULL) break; @@ -76,19 +84,41 @@ int32_t init_env() { } taos_free_result(pRes); - pRes = taos_query(pConn, "create table if not exists ct1 using st1 tags(2000)"); + pRes = taos_query(pConn, "insert into ct0 values(now, 1, 2, 'a')"); if (taos_errno(pRes) != 0) { - printf("failed to create child table tu2, reason:%s\n", taos_errstr(pRes)); + printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes)); return -1; } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct1 using st1 tags(2000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct1 values(now, 3, 4, 'b')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); pRes = taos_query(pConn, "create table if not exists ct3 using st1 tags(3000)"); if (taos_errno(pRes) != 0) { - printf("failed to create child table tu3, reason:%s\n", taos_errstr(pRes)); + printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes)); return -1; } - taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct3 values(now, 5, 6, 'c')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + return 0; } @@ -107,8 +137,8 @@ int32_t create_topic() { } taos_free_result(pRes); - /*pRes = taos_query(pConn, "create topic topic_ctb_column as database abc1");*/ - pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from st1"); + pRes = taos_query(pConn, "create topic topic_ctb_column with meta as database abc1"); + /*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from st1");*/ if (taos_errno(pRes) != 0) { printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); return -1; @@ -168,6 +198,9 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "td.connect.pass", "taosdata"); tmq_conf_set(conf, "msg.with.table.name", "true"); tmq_conf_set(conf, "enable.auto.commit", "true"); + + tmq_conf_set(conf, "experiment.use.snapshot", "false"); + tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); assert(tmq); diff --git a/include/client/taos.h b/include/client/taos.h index 9d4da221f4..5e7f12de0a 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -128,7 +128,6 @@ typedef struct setConfRet { DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); -DLL_EXPORT setConfRet taos_set_config(const char *config); DLL_EXPORT int taos_init(void); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); @@ -261,7 +260,7 @@ enum tmq_res_t { typedef enum tmq_res_t tmq_res_t; DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res); -DLL_EXPORT int32_t tmq_get_raw_meta(TAOS_RES *res, const void **raw_meta, int32_t *raw_meta_len); +DLL_EXPORT int32_t tmq_get_raw_meta(TAOS_RES *res, void **raw_meta, int32_t *raw_meta_len); DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res); DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 73ba0f47b8..09f24cc555 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -46,11 +46,15 @@ typedef enum EStreamType { STREAM_INVALID, STREAM_GET_ALL, STREAM_DELETE, + STREAM_RETRIEVE, } EStreamType; typedef struct { SArray* pTableList; SHashObj* map; // speedup acquire the tableQueryInfo by table uid + void* pTagCond; + void* pTagIndexCond; + uint64_t suid; } STableListInfo; typedef struct SColumnDataAgg { @@ -65,14 +69,13 @@ typedef struct SColumnDataAgg { typedef struct SDataBlockInfo { STimeWindow window; - int32_t rows; + int32_t rows; // todo hide this attribute int32_t rowSize; - int64_t uid; // the uid of table, from which current data block comes - int64_t blockId; // block id, generated by physical planner + uint64_t uid; // the uid of table, from which current data block comes + uint16_t blockId; // block id, generated by physical planner uint64_t groupId; // no need to serialize - int16_t numOfCols; int16_t hasVarCol; - int32_t capacity; + uint32_t capacity; // TODO: optimize and remove following int32_t childId; // used for stream, do not serialize EStreamType type; // used for stream, do not serialize @@ -93,7 +96,7 @@ typedef struct SVarColAttr { // pBlockAgg->numOfNull == info.rows, all data are null // pBlockAgg->numOfNull == 0, no data are null. typedef struct SColumnInfoData { - SColumnInfo info; // TODO filter info needs to be removed + SColumnInfo info; // column info bool hasNull; // if current column data has null value. char* pData; // the corresponding block data in memory union { @@ -112,8 +115,8 @@ typedef struct SQueryTableDataCond { int32_t type; // data block load type: int32_t numOfTWindows; STimeWindow* twindows; - int32_t startVersion; - int32_t endVersion; + int64_t startVersion; + int64_t endVersion; } SQueryTableDataCond; void* blockDataDestroy(SSDataBlock* pBlock); diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 709462a744..2a0d4e7ff6 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -71,7 +71,8 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet); #define colDataGetData(p1_, r_) \ ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) : colDataGetNumData(p1_, r_)) -#define IS_JSON_NULL(type, data) ((type) == TSDB_DATA_TYPE_JSON && *(data) == TSDB_DATA_TYPE_NULL) +#define IS_JSON_NULL(type, data) \ + ((type) == TSDB_DATA_TYPE_JSON && (*(data) == TSDB_DATA_TYPE_NULL || tTagIsJsonNull(data))) static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) { if (!pColumnInfoData->hasNull) { @@ -183,9 +184,10 @@ static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, u int32_t getJsonValueLen(const char* data); int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); -int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity, +int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, uint32_t* capacity, const SColumnInfoData* pSource, uint32_t numOfRow2); -int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows); +int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows, + const SDataBlockInfo* pBlockInfo); int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex); int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows); @@ -211,7 +213,7 @@ size_t blockDataGetSerialMetaSize(uint32_t numOfCols); int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); -int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, uint32_t numOfRows); +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows); @@ -221,7 +223,13 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n); +int32_t assignOneDataBlock(SSDataBlock* dst, const SSDataBlock* src); SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData); +SSDataBlock* createDataBlock(); +int32_t blockDataAppendColInfo(SSDataBlock* pBlock, SColumnInfoData* pColInfoData); + +SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId); +SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index); void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress); @@ -235,7 +243,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId); static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) { - return blockDataGetSerialMetaSize(pBlock->info.numOfCols) + blockDataGetSize(pBlock); + return blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)) + blockDataGetSize(pBlock); } static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 2e69640a06..f9ede63f7f 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -70,6 +70,8 @@ int32_t tGetTSRow(uint8_t *p, STSRow2 *pRow); // STag int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag); void tTagFree(STag *pTag); +bool tTagIsJson(const void *pTag); +bool tTagIsJsonNull(void *tagVal); bool tTagGet(const STag *pTag, STagVal *pTagVal); char *tTagValToData(const STagVal *pTagVal, bool isJson); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 8c03d3ff42..41674b7a70 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -137,6 +137,8 @@ extern bool tsSmlDataFormat; // internal extern int32_t tsTransPullupInterval; extern int32_t tsMqRebalanceInterval; +extern int32_t tsTtlUnit; +extern int32_t tsTtlPushInterval; #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) @@ -149,6 +151,7 @@ void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); struct SConfig *taosGetCfg(); +int32_t taosSetCfg(SConfig *pCfg, char* name); #ifdef __cplusplus } diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 50ccae512d..e9ee8b5955 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -629,11 +629,6 @@ typedef struct { uint8_t scale; } SColumnInfo; -typedef struct { - int64_t uid; - TSKEY key; // last accessed ts, for subscription -} STableIdInfo; - typedef struct STimeWindow { TSKEY skey; TSKEY ekey; @@ -696,12 +691,12 @@ typedef struct { typedef STableCfg STableCfgRsp; -int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq); -int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq); +int32_t tSerializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq); +int32_t tDeserializeSTableCfgReq(void* buf, int32_t bufLen, STableCfgReq* pReq); -int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp); -int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp); -void tFreeSTableCfgRsp(STableCfgRsp *pRsp); +int32_t tSerializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp); +int32_t tDeserializeSTableCfgRsp(void* buf, int32_t bufLen, STableCfgRsp* pRsp); +void tFreeSTableCfgRsp(STableCfgRsp* pRsp); typedef struct { char db[TSDB_DB_FNAME_LEN]; @@ -834,6 +829,14 @@ typedef struct { int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq); int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq); +typedef struct { + int32_t rowNum; +} SDnodeListReq; + +int32_t tSerializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq); +int32_t tDeserializeSDnodeListReq(void* buf, int32_t bufLen, SDnodeListReq* pReq); + + typedef struct SQueryNodeAddr { int32_t nodeId; // vgId or qnodeId SEpSet epSet; @@ -852,6 +855,15 @@ int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp); int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp); void tFreeSQnodeListRsp(SQnodeListRsp* pRsp); +typedef struct { + SArray* dnodeList; // SArray +} SDnodeListRsp; + +int32_t tSerializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp); +int32_t tDeserializeSDnodeListRsp(void* buf, int32_t bufLen, SDnodeListRsp* pRsp); +void tFreeSDnodeListRsp(SDnodeListRsp* pRsp); + + typedef struct { SArray* pArray; // Array of SUseDbRsp } SUseDbBatchRsp; @@ -1210,6 +1222,13 @@ typedef struct { char* data; } STagData; +typedef struct { + int32_t useless; // useless +} SShowVariablesReq; + +int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); +int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); + /* * sql: show tables like '%a_%' * payload is the query condition, e.g., '%a_%' @@ -1322,11 +1341,19 @@ typedef struct { int32_t dnodeId; char config[TSDB_DNODE_CONFIG_LEN]; char value[TSDB_DNODE_VALUE_LEN]; -} SMCfgDnodeReq, SDCfgDnodeReq; +} SMCfgDnodeReq; int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq); int32_t tDeserializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq); +typedef struct { + char config[TSDB_DNODE_CONFIG_LEN]; + char value[TSDB_DNODE_VALUE_LEN]; +} SDCfgDnodeReq; + +int32_t tSerializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq); +int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq); + typedef struct { int32_t dnodeId; } SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq, @@ -2436,6 +2463,8 @@ typedef struct { int64_t interval; int64_t offset; int64_t sliding; + int64_t maxDelay; + int64_t watermark; int32_t exprLen; // strlen + 1 int32_t tagsFilterLen; // strlen + 1 int32_t sqlLen; // strlen + 1 @@ -2645,6 +2674,7 @@ typedef struct { SMsgHead head; char subKey[TSDB_SUBSCRIBE_KEY_LEN]; int8_t withTbName; + int8_t useSnapshot; int32_t epoch; uint64_t reqId; int64_t consumerId; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index bb5e903d1e..1babb45003 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -81,6 +81,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_DND_SERVER_STATUS, "server-status", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_DND_NET_TEST, "net-test", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_DND_CONFIG_DNODE, "config-dnode", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_DND_SYSTABLE_RETRIEVE, "dnode-retrieve", NULL, NULL) TD_NEW_MSG_SEG(TDMT_MND_MSG) TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "connect", NULL, NULL) @@ -101,6 +102,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "alter-qnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "drop-qnode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_QNODE_LIST, "qnode-list", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_DNODE_LIST, "dnode-list", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "create-snode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "alter-snode", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "drop-snode", NULL, NULL) @@ -145,13 +147,14 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_TRANS, "kill-trans", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_QUERY, "kill-query", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "kill-conn", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "heartbeat", SClientHbBatchReq, SClientHbBatchRsp) TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "status", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "show", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "retrieve", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "mnd-retrieve", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GRANT, "grant", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_AUTH, "auth", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_APPLY_MSG, "mnode-apply", NULL, NULL) @@ -159,6 +162,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_MERGE_VGROUP, "merge-vgroup", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_REDISTRIBUTE_VGROUP, "redistribute-vgroup", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SPLIT_VGROUP, "split-vgroup", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_SHOW_VARIABLES, "show-variables", NULL, NULL) TD_NEW_MSG_SEG(TDMT_VND_MSG) TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp) @@ -200,15 +204,14 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL) - TD_NEW_MSG_SEG(TDMT_QND_MSG) - //shared by snode and vnode TD_NEW_MSG_SEG(TDMT_STREAM_MSG) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DROP, "stream-task-drop", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_RETRIEVE, "stream-retrieve", NULL, NULL) TD_NEW_MSG_SEG(TDMT_SCH_MSG) TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL) diff --git a/include/common/tname.h b/include/common/tname.h index c691c2f7b2..3bf1cee870 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -57,6 +57,8 @@ void tNameAssign(SName* dst, const SName* src); int32_t tNameSetDbName(SName* dst, int32_t acctId, const char* dbName, size_t nameLen); +int32_t tNameAddTbName(SName* dst, const char* tbName, size_t nameLen); + int32_t tNameFromString(SName* dst, const char* str, uint32_t type); int32_t tNameSetAcctId(SName* dst, int32_t acctId); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 35b4a5ce7d..6ace51f58e 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -49,214 +49,218 @@ #define TK_CONNS 31 #define TK_STATE 32 #define TK_USER 33 -#define TK_PRIVILEGE 34 -#define TK_DROP 35 -#define TK_GRANT 36 -#define TK_ON 37 -#define TK_TO 38 -#define TK_REVOKE 39 -#define TK_FROM 40 -#define TK_NK_COMMA 41 -#define TK_READ 42 -#define TK_WRITE 43 -#define TK_NK_DOT 44 -#define TK_DNODE 45 -#define TK_PORT 46 -#define TK_NK_INTEGER 47 -#define TK_DNODES 48 -#define TK_NK_IPTOKEN 49 -#define TK_LOCAL 50 -#define TK_QNODE 51 -#define TK_BNODE 52 -#define TK_SNODE 53 -#define TK_MNODE 54 -#define TK_DATABASE 55 -#define TK_USE 56 -#define TK_IF 57 -#define TK_NOT 58 -#define TK_EXISTS 59 -#define TK_BUFFER 60 -#define TK_CACHELAST 61 -#define TK_COMP 62 -#define TK_DURATION 63 -#define TK_NK_VARIABLE 64 -#define TK_FSYNC 65 -#define TK_MAXROWS 66 -#define TK_MINROWS 67 -#define TK_KEEP 68 -#define TK_PAGES 69 -#define TK_PAGESIZE 70 -#define TK_PRECISION 71 -#define TK_REPLICA 72 -#define TK_STRICT 73 -#define TK_WAL 74 -#define TK_VGROUPS 75 -#define TK_SINGLE_STABLE 76 -#define TK_RETENTIONS 77 -#define TK_SCHEMALESS 78 -#define TK_NK_COLON 79 -#define TK_TABLE 80 -#define TK_NK_LP 81 -#define TK_NK_RP 82 -#define TK_STABLE 83 -#define TK_ADD 84 -#define TK_COLUMN 85 -#define TK_MODIFY 86 -#define TK_RENAME 87 -#define TK_TAG 88 -#define TK_SET 89 -#define TK_NK_EQ 90 -#define TK_USING 91 -#define TK_TAGS 92 -#define TK_COMMENT 93 -#define TK_BOOL 94 -#define TK_TINYINT 95 -#define TK_SMALLINT 96 -#define TK_INT 97 -#define TK_INTEGER 98 -#define TK_BIGINT 99 -#define TK_FLOAT 100 -#define TK_DOUBLE 101 -#define TK_BINARY 102 -#define TK_TIMESTAMP 103 -#define TK_NCHAR 104 -#define TK_UNSIGNED 105 -#define TK_JSON 106 -#define TK_VARCHAR 107 -#define TK_MEDIUMBLOB 108 -#define TK_BLOB 109 -#define TK_VARBINARY 110 -#define TK_DECIMAL 111 -#define TK_MAX_DELAY 112 -#define TK_WATERMARK 113 -#define TK_ROLLUP 114 -#define TK_TTL 115 -#define TK_SMA 116 -#define TK_FIRST 117 -#define TK_LAST 118 -#define TK_SHOW 119 -#define TK_DATABASES 120 -#define TK_TABLES 121 -#define TK_STABLES 122 -#define TK_MNODES 123 -#define TK_MODULES 124 -#define TK_QNODES 125 -#define TK_FUNCTIONS 126 -#define TK_INDEXES 127 -#define TK_ACCOUNTS 128 -#define TK_APPS 129 -#define TK_CONNECTIONS 130 -#define TK_LICENCE 131 -#define TK_GRANTS 132 -#define TK_QUERIES 133 -#define TK_SCORES 134 -#define TK_TOPICS 135 -#define TK_VARIABLES 136 -#define TK_BNODES 137 -#define TK_SNODES 138 -#define TK_CLUSTER 139 -#define TK_TRANSACTIONS 140 -#define TK_DISTRIBUTED 141 -#define TK_LIKE 142 -#define TK_INDEX 143 -#define TK_FULLTEXT 144 -#define TK_FUNCTION 145 -#define TK_INTERVAL 146 -#define TK_TOPIC 147 -#define TK_AS 148 -#define TK_CONSUMER 149 -#define TK_GROUP 150 -#define TK_DESC 151 -#define TK_DESCRIBE 152 -#define TK_RESET 153 -#define TK_QUERY 154 -#define TK_CACHE 155 -#define TK_EXPLAIN 156 -#define TK_ANALYZE 157 -#define TK_VERBOSE 158 -#define TK_NK_BOOL 159 -#define TK_RATIO 160 -#define TK_NK_FLOAT 161 -#define TK_COMPACT 162 -#define TK_VNODES 163 -#define TK_IN 164 -#define TK_OUTPUTTYPE 165 -#define TK_AGGREGATE 166 -#define TK_BUFSIZE 167 -#define TK_STREAM 168 -#define TK_INTO 169 -#define TK_TRIGGER 170 -#define TK_AT_ONCE 171 -#define TK_WINDOW_CLOSE 172 -#define TK_KILL 173 -#define TK_CONNECTION 174 -#define TK_TRANSACTION 175 -#define TK_BALANCE 176 -#define TK_VGROUP 177 -#define TK_MERGE 178 -#define TK_REDISTRIBUTE 179 -#define TK_SPLIT 180 -#define TK_SYNCDB 181 -#define TK_DELETE 182 -#define TK_NULL 183 -#define TK_NK_QUESTION 184 -#define TK_NK_ARROW 185 -#define TK_ROWTS 186 -#define TK_TBNAME 187 -#define TK_QSTARTTS 188 -#define TK_QENDTS 189 -#define TK_WSTARTTS 190 -#define TK_WENDTS 191 -#define TK_WDURATION 192 -#define TK_CAST 193 -#define TK_NOW 194 -#define TK_TODAY 195 -#define TK_TIMEZONE 196 -#define TK_COUNT 197 -#define TK_LAST_ROW 198 -#define TK_BETWEEN 199 -#define TK_IS 200 -#define TK_NK_LT 201 -#define TK_NK_GT 202 -#define TK_NK_LE 203 -#define TK_NK_GE 204 -#define TK_NK_NE 205 -#define TK_MATCH 206 -#define TK_NMATCH 207 -#define TK_CONTAINS 208 -#define TK_JOIN 209 -#define TK_INNER 210 -#define TK_SELECT 211 -#define TK_DISTINCT 212 -#define TK_WHERE 213 -#define TK_PARTITION 214 -#define TK_BY 215 -#define TK_SESSION 216 -#define TK_STATE_WINDOW 217 -#define TK_SLIDING 218 -#define TK_FILL 219 -#define TK_VALUE 220 -#define TK_NONE 221 -#define TK_PREV 222 -#define TK_LINEAR 223 -#define TK_NEXT 224 -#define TK_HAVING 225 -#define TK_RANGE 226 -#define TK_EVERY 227 -#define TK_ORDER 228 -#define TK_SLIMIT 229 -#define TK_SOFFSET 230 -#define TK_LIMIT 231 -#define TK_OFFSET 232 -#define TK_ASC 233 -#define TK_NULLS 234 -#define TK_ID 235 -#define TK_NK_BITNOT 236 -#define TK_INSERT 237 -#define TK_VALUES 238 -#define TK_IMPORT 239 -#define TK_NK_SEMI 240 -#define TK_FILE 241 +#define TK_ENABLE 34 +#define TK_NK_INTEGER 35 +#define TK_SYSINFO 36 +#define TK_DROP 37 +#define TK_GRANT 38 +#define TK_ON 39 +#define TK_TO 40 +#define TK_REVOKE 41 +#define TK_FROM 42 +#define TK_NK_COMMA 43 +#define TK_READ 44 +#define TK_WRITE 45 +#define TK_NK_DOT 46 +#define TK_DNODE 47 +#define TK_PORT 48 +#define TK_DNODES 49 +#define TK_NK_IPTOKEN 50 +#define TK_LOCAL 51 +#define TK_QNODE 52 +#define TK_BNODE 53 +#define TK_SNODE 54 +#define TK_MNODE 55 +#define TK_DATABASE 56 +#define TK_USE 57 +#define TK_IF 58 +#define TK_NOT 59 +#define TK_EXISTS 60 +#define TK_BUFFER 61 +#define TK_CACHELAST 62 +#define TK_COMP 63 +#define TK_DURATION 64 +#define TK_NK_VARIABLE 65 +#define TK_FSYNC 66 +#define TK_MAXROWS 67 +#define TK_MINROWS 68 +#define TK_KEEP 69 +#define TK_PAGES 70 +#define TK_PAGESIZE 71 +#define TK_PRECISION 72 +#define TK_REPLICA 73 +#define TK_STRICT 74 +#define TK_WAL 75 +#define TK_VGROUPS 76 +#define TK_SINGLE_STABLE 77 +#define TK_RETENTIONS 78 +#define TK_SCHEMALESS 79 +#define TK_NK_COLON 80 +#define TK_TABLE 81 +#define TK_NK_LP 82 +#define TK_NK_RP 83 +#define TK_STABLE 84 +#define TK_ADD 85 +#define TK_COLUMN 86 +#define TK_MODIFY 87 +#define TK_RENAME 88 +#define TK_TAG 89 +#define TK_SET 90 +#define TK_NK_EQ 91 +#define TK_USING 92 +#define TK_TAGS 93 +#define TK_COMMENT 94 +#define TK_BOOL 95 +#define TK_TINYINT 96 +#define TK_SMALLINT 97 +#define TK_INT 98 +#define TK_INTEGER 99 +#define TK_BIGINT 100 +#define TK_FLOAT 101 +#define TK_DOUBLE 102 +#define TK_BINARY 103 +#define TK_TIMESTAMP 104 +#define TK_NCHAR 105 +#define TK_UNSIGNED 106 +#define TK_JSON 107 +#define TK_VARCHAR 108 +#define TK_MEDIUMBLOB 109 +#define TK_BLOB 110 +#define TK_VARBINARY 111 +#define TK_DECIMAL 112 +#define TK_MAX_DELAY 113 +#define TK_WATERMARK 114 +#define TK_ROLLUP 115 +#define TK_TTL 116 +#define TK_SMA 117 +#define TK_FIRST 118 +#define TK_LAST 119 +#define TK_SHOW 120 +#define TK_DATABASES 121 +#define TK_TABLES 122 +#define TK_STABLES 123 +#define TK_MNODES 124 +#define TK_MODULES 125 +#define TK_QNODES 126 +#define TK_FUNCTIONS 127 +#define TK_INDEXES 128 +#define TK_ACCOUNTS 129 +#define TK_APPS 130 +#define TK_CONNECTIONS 131 +#define TK_LICENCE 132 +#define TK_GRANTS 133 +#define TK_QUERIES 134 +#define TK_SCORES 135 +#define TK_TOPICS 136 +#define TK_VARIABLES 137 +#define TK_BNODES 138 +#define TK_SNODES 139 +#define TK_CLUSTER 140 +#define TK_TRANSACTIONS 141 +#define TK_DISTRIBUTED 142 +#define TK_CONSUMERS 143 +#define TK_SUBSCRIPTIONS 144 +#define TK_LIKE 145 +#define TK_INDEX 146 +#define TK_FUNCTION 147 +#define TK_INTERVAL 148 +#define TK_TOPIC 149 +#define TK_AS 150 +#define TK_WITH 151 +#define TK_META 152 +#define TK_CONSUMER 153 +#define TK_GROUP 154 +#define TK_DESC 155 +#define TK_DESCRIBE 156 +#define TK_RESET 157 +#define TK_QUERY 158 +#define TK_CACHE 159 +#define TK_EXPLAIN 160 +#define TK_ANALYZE 161 +#define TK_VERBOSE 162 +#define TK_NK_BOOL 163 +#define TK_RATIO 164 +#define TK_NK_FLOAT 165 +#define TK_COMPACT 166 +#define TK_VNODES 167 +#define TK_IN 168 +#define TK_OUTPUTTYPE 169 +#define TK_AGGREGATE 170 +#define TK_BUFSIZE 171 +#define TK_STREAM 172 +#define TK_INTO 173 +#define TK_TRIGGER 174 +#define TK_AT_ONCE 175 +#define TK_WINDOW_CLOSE 176 +#define TK_KILL 177 +#define TK_CONNECTION 178 +#define TK_TRANSACTION 179 +#define TK_BALANCE 180 +#define TK_VGROUP 181 +#define TK_MERGE 182 +#define TK_REDISTRIBUTE 183 +#define TK_SPLIT 184 +#define TK_SYNCDB 185 +#define TK_DELETE 186 +#define TK_NULL 187 +#define TK_NK_QUESTION 188 +#define TK_NK_ARROW 189 +#define TK_ROWTS 190 +#define TK_TBNAME 191 +#define TK_QSTARTTS 192 +#define TK_QENDTS 193 +#define TK_WSTARTTS 194 +#define TK_WENDTS 195 +#define TK_WDURATION 196 +#define TK_CAST 197 +#define TK_NOW 198 +#define TK_TODAY 199 +#define TK_TIMEZONE 200 +#define TK_COUNT 201 +#define TK_LAST_ROW 202 +#define TK_BETWEEN 203 +#define TK_IS 204 +#define TK_NK_LT 205 +#define TK_NK_GT 206 +#define TK_NK_LE 207 +#define TK_NK_GE 208 +#define TK_NK_NE 209 +#define TK_MATCH 210 +#define TK_NMATCH 211 +#define TK_CONTAINS 212 +#define TK_JOIN 213 +#define TK_INNER 214 +#define TK_SELECT 215 +#define TK_DISTINCT 216 +#define TK_WHERE 217 +#define TK_PARTITION 218 +#define TK_BY 219 +#define TK_SESSION 220 +#define TK_STATE_WINDOW 221 +#define TK_SLIDING 222 +#define TK_FILL 223 +#define TK_VALUE 224 +#define TK_NONE 225 +#define TK_PREV 226 +#define TK_LINEAR 227 +#define TK_NEXT 228 +#define TK_HAVING 229 +#define TK_RANGE 230 +#define TK_EVERY 231 +#define TK_ORDER 232 +#define TK_SLIMIT 233 +#define TK_SOFFSET 234 +#define TK_LIMIT 235 +#define TK_OFFSET 236 +#define TK_ASC 237 +#define TK_NULLS 238 +#define TK_ID 239 +#define TK_NK_BITNOT 240 +#define TK_INSERT 241 +#define TK_VALUES 242 +#define TK_IMPORT 243 +#define TK_NK_SEMI 244 +#define TK_FILE 245 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 2509c10601..70056783ea 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -73,10 +73,12 @@ void mndStop(SMnode *pMnode); * @param pMnode The mnode object. * @param pCluster * @param pVgroup + * @param pStbInfo * @param pGrant * @return int32_t 0 for success, -1 for failure. */ -int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant); +int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, + SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo); /** * @brief Get mnode loads for status msg. diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index c23cf162aa..957c40f21e 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -33,7 +33,7 @@ struct SDataSink; struct SSDataBlock; typedef struct SDeleterRes { - uint64_t uid; + uint64_t suid; SArray* uidList; int64_t skey; int64_t ekey; @@ -41,7 +41,8 @@ typedef struct SDeleterRes { } SDeleterRes; typedef struct SDeleterParam { - SArray* pUidList; + uint64_t suid; + SArray* pUidList; } SDeleterParam; typedef struct SDataSinkStat { diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 083f6ae1b0..6738fc23bc 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -36,11 +36,13 @@ typedef struct SReadHandle { void* vnode; void* mnd; SMsgCb* pMsgCb; + int8_t initTsdbReader; } SReadHandle; enum { STREAM_DATA_TYPE_SUBMIT_BLOCK = 1, STREAM_DATA_TYPE_SSDATA_BLOCK = 2, + STREAM_DATA_TYPE_FROM_SNAPSHOT = 3, }; typedef enum { @@ -56,6 +58,13 @@ typedef enum { */ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle); +/** + * Switch the stream scan to snapshot mode + * @param tinfo + * @return + */ +int32_t qStreamScanSnapshot(qTaskInfo_t tinfo); + /** * Set the input data block for the stream scan. * @param tinfo diff --git a/include/libs/function/function.h b/include/libs/function/function.h index e543f0f653..a569c8de54 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -172,23 +172,6 @@ typedef struct tExprNode { void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); -typedef struct SAggFunctionInfo { - char name[FUNCTIONS_NAME_MAX_LENGTH]; - int8_t type; // Scalar function or aggregation function - uint32_t functionId; // Function Id - int8_t sFunctionId; // Transfer function for super table query - uint16_t status; - - bool (*init)(SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment - void (*addInput)(SqlFunctionCtx *pCtx); - - // finalizer must be called after all exec has been executed to generated final result. - void (*finalize)(SqlFunctionCtx *pCtx); - void (*combine)(SqlFunctionCtx *pCtx); - - int32_t (*dataReqFunc)(SqlFunctionCtx *pCtx, STimeWindow* w, int32_t colId); -} SAggFunctionInfo; - struct SScalarParam { SColumnInfoData *columnData; SHashObj *pHashFilter; diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index cbaff29cb2..1ca51b3043 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -123,6 +123,7 @@ typedef enum EFunctionType { FUNCTION_TYPE_SELECT_VALUE, FUNCTION_TYPE_BLOCK_DIST, // block distribution aggregate function FUNCTION_TYPE_BLOCK_DIST_INFO, // block distribution pseudo column function + FUNCTION_TYPE_TO_COLUMN, // distributed splitting functions FUNCTION_TYPE_APERCENTILE_PARTIAL = 4000, @@ -190,6 +191,7 @@ bool fmIsForbidWindowFunc(int32_t funcId); bool fmIsForbidGroupByFunc(int32_t funcId); bool fmIsIntervalInterpoFunc(int32_t funcId); bool fmIsInterpFunc(int32_t funcId); +bool fmIsLastRowFunc(int32_t funcId); int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc); diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 39e8042b93..41d80c1a83 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -109,6 +109,9 @@ typedef struct { char version[MON_VER_LEN]; float master_uptime; // day int32_t monitor_interval; // sec + int32_t dbs_total; + int32_t stbs_total; + int64_t tbs_total; int32_t vgroups_total; int32_t vgroups_alive; int32_t vnodes_total; @@ -135,6 +138,15 @@ typedef struct { SArray *vgroups; // array of SMonVgroupDesc } SMonVgroupInfo; +typedef struct { + char stb_name[TSDB_TABLE_NAME_LEN]; + char database_name[TSDB_DB_NAME_LEN]; +} SMonStbDesc; + +typedef struct { + SArray *stbs; // array of SMonStbDesc +} SMonStbInfo; + typedef struct { int32_t expire_time; int64_t timeseries_used; @@ -144,6 +156,7 @@ typedef struct { typedef struct { SMonClusterInfo cluster; SMonVgroupInfo vgroup; + SMonStbInfo stb; SMonGrantInfo grant; SMonSysInfo sys; SMonLogs log; diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 10c3f313a2..e473daad8d 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -28,14 +28,17 @@ extern "C" { #define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE) #define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE) -#define SHOW_CREATE_DB_RESULT_COLS 2 +#define SHOW_CREATE_DB_RESULT_COLS 2 #define SHOW_CREATE_DB_RESULT_FIELD1_LEN (TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE) #define SHOW_CREATE_DB_RESULT_FIELD2_LEN (TSDB_MAX_BINARY_LEN + VARSTR_HEADER_SIZE) -#define SHOW_CREATE_TB_RESULT_COLS 2 +#define SHOW_CREATE_TB_RESULT_COLS 2 #define SHOW_CREATE_TB_RESULT_FIELD1_LEN (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) #define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_BINARY_LEN + VARSTR_HEADER_SIZE) +#define SHOW_LOCAL_VARIABLES_RESULT_COLS 2 +#define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE) +#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE) #define PRIVILEGE_TYPE_MASK(n) (1 << n) @@ -179,13 +182,16 @@ typedef struct SCreateUserStmt { ENodeType type; char useName[TSDB_USER_LEN]; char password[TSDB_USET_PASSWORD_LEN]; + int8_t sysinfo; } SCreateUserStmt; typedef struct SAlterUserStmt { ENodeType type; char useName[TSDB_USER_LEN]; - char password[TSDB_USET_PASSWORD_LEN]; int8_t alterType; + char password[TSDB_USET_PASSWORD_LEN]; + int8_t enable; + int8_t sysinfo; } SAlterUserStmt; typedef struct SDropUserStmt { @@ -227,10 +233,10 @@ typedef struct SShowCreateDatabaseStmt { } SShowCreateDatabaseStmt; typedef struct SShowCreateTableStmt { - ENodeType type; - char dbName[TSDB_DB_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; - void* pCfg; // STableCfg + ENodeType type; + char dbName[TSDB_DB_NAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + void* pCfg; // STableCfg } SShowCreateTableStmt; typedef struct SShowTableDistributedStmt { @@ -252,6 +258,7 @@ typedef struct SIndexOptions { SNode* pInterval; SNode* pOffset; SNode* pSliding; + SNode* pStreamOptions; } SIndexOptions; typedef struct SCreateIndexStmt { @@ -268,7 +275,6 @@ typedef struct SDropIndexStmt { ENodeType type; bool ignoreNotExists; char indexName[TSDB_INDEX_NAME_LEN]; - char tableName[TSDB_TABLE_NAME_LEN]; } SDropIndexStmt; typedef struct SCreateComponentNodeStmt { @@ -287,6 +293,7 @@ typedef struct SCreateTopicStmt { char subDbName[TSDB_DB_NAME_LEN]; char subSTbName[TSDB_TABLE_NAME_LEN]; bool ignoreExists; + bool withMeta; SNode* pQuery; } SCreateTopicStmt; diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 7c840cef9c..2153f59bf8 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -59,10 +59,10 @@ extern "C" { for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); \ (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) -#define DESTORY_LIST(list) \ - do { \ - nodesDestroyList((list)); \ - (list) = NULL; \ +#define NODES_DESTORY_LIST(list) \ + do { \ + nodesDestroyList((list)); \ + (list) = NULL; \ } while (0) #define NODES_CLEAR_LIST(list) \ @@ -188,6 +188,7 @@ typedef enum ENodeType { QUERY_NODE_SHOW_CREATE_STABLE_STMT, QUERY_NODE_SHOW_TRANSACTIONS_STMT, QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT, + QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT, QUERY_NODE_KILL_CONNECTION_STMT, QUERY_NODE_KILL_QUERY_STMT, QUERY_NODE_KILL_TRANSACTION_STMT, @@ -219,12 +220,14 @@ typedef enum ENodeType { QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN, + QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN, QUERY_NODE_PHYSICAL_PLAN_PROJECT, QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN, QUERY_NODE_PHYSICAL_PLAN_HASH_AGG, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, QUERY_NODE_PHYSICAL_PLAN_MERGE, QUERY_NODE_PHYSICAL_PLAN_SORT, + QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT, QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL, @@ -282,6 +285,7 @@ int32_t nodesListPushFront(SNodeList* pList, SNode* pNode); SListCell* nodesListErase(SNodeList* pList, SListCell* pCell); void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc); SNode* nodesListGetNode(SNodeList* pList, int32_t index); +SListCell* nodesListGetCell(SNodeList* pList, int32_t index); void nodesDestroyList(SNodeList* pList); // Only clear the linked list structure, without releasing the elements inside void nodesClearList(SNodeList* pList); diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 473635bf36..f8cf58d8cb 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -32,6 +32,8 @@ typedef struct SLogicNode { struct SLogicNode* pParent; int32_t optimizedFlag; uint8_t precision; + SNode* pLimit; + SNode* pSlimit; } SLogicNode; typedef enum EScanType { @@ -40,7 +42,8 @@ typedef enum EScanType { SCAN_TYPE_SYSTEM_TABLE, SCAN_TYPE_STREAM, SCAN_TYPE_TABLE_MERGE, - SCAN_TYPE_BLOCK_INFO + SCAN_TYPE_BLOCK_INFO, + SCAN_TYPE_LAST_ROW } EScanType; typedef struct SScanLogicNode { @@ -65,6 +68,7 @@ typedef struct SScanLogicNode { int8_t intervalUnit; int8_t slidingUnit; SNode* pTagCond; + SNode* pTagIndexCond; int8_t triggerType; int64_t watermark; int16_t tsColId; @@ -90,10 +94,6 @@ typedef struct SProjectLogicNode { SLogicNode node; SNodeList* pProjections; char stmtName[TSDB_TABLE_NAME_LEN]; - int64_t limit; - int64_t offset; - int64_t slimit; - int64_t soffset; } SProjectLogicNode; typedef struct SIndefRowsFuncLogicNode { @@ -246,6 +246,8 @@ typedef struct SPhysiNode { SNode* pConditions; SNodeList* pChildren; struct SPhysiNode* pParent; + SNode* pLimit; + SNode* pSlimit; } SPhysiNode; typedef struct SScanPhysiNode { @@ -260,6 +262,7 @@ typedef struct SScanPhysiNode { typedef SScanPhysiNode STagScanPhysiNode; typedef SScanPhysiNode SBlockDistScanPhysiNode; +typedef SScanPhysiNode SLastRowScanPhysiNode; typedef struct SSystemTableScanPhysiNode { SScanPhysiNode scan; @@ -294,10 +297,6 @@ typedef STableScanPhysiNode SStreamScanPhysiNode; typedef struct SProjectPhysiNode { SPhysiNode node; SNodeList* pProjections; - int64_t limit; - int64_t offset; - int64_t slimit; - int64_t soffset; } SProjectPhysiNode; typedef struct SIndefRowsFuncPhysiNode { @@ -375,7 +374,7 @@ typedef struct SIntervalPhysiNode { int8_t slidingUnit; } SIntervalPhysiNode; -typedef SIntervalPhysiNode SMergeIntervalPhysiNode; +typedef SIntervalPhysiNode SMergeIntervalPhysiNode; typedef SIntervalPhysiNode SMergeAlignedIntervalPhysiNode; typedef SIntervalPhysiNode SStreamIntervalPhysiNode; typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode; @@ -418,6 +417,8 @@ typedef struct SSortPhysiNode { SNodeList* pTargets; } SSortPhysiNode; +typedef SSortPhysiNode SGroupSortPhysiNode; + typedef struct SPartitionPhysiNode { SPhysiNode node; SNodeList* pExprs; // these are expression list of partition_by_clause @@ -464,6 +465,7 @@ typedef struct SSubplan { SPhysiNode* pNode; // physical plan of current subplan SDataSinkNode* pDataSink; // data of the subplan flow into the datasink SNode* pTagCond; + SNode* pTagIndexCond; } SSubplan; typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 7a63f87412..a6e466e73e 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -258,6 +258,7 @@ typedef struct SSelectStmt { bool hasUniqueFunc; bool hasTailFunc; bool hasInterpFunc; + bool hasLastRowFunc; } SSelectStmt; typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType; @@ -287,11 +288,11 @@ typedef enum ESqlClause { } ESqlClause; typedef struct SDeleteStmt { - ENodeType type; // QUERY_NODE_DELETE_STMT - SNode* pFromTable; // FROM clause - SNode* pWhere; // WHERE clause - SNode* pCountFunc; // count the number of rows affected - SNode* pTagIndexCond; // pWhere divided into pTagIndexCond and timeRange + ENodeType type; // QUERY_NODE_DELETE_STMT + SNode* pFromTable; // FROM clause + SNode* pWhere; // WHERE clause + SNode* pCountFunc; // count the number of rows affected + SNode* pTagCond; // pWhere divided into pTagCond and timeRange STimeWindow timeRange; uint8_t precision; bool deleteZeroRows; @@ -384,6 +385,7 @@ bool nodesIsArithmeticOp(const SOperatorNode* pOp); bool nodesIsComparisonOp(const SOperatorNode* pOp); bool nodesIsJsonOp(const SOperatorNode* pOp); bool nodesIsRegularOp(const SOperatorNode* pOp); +bool nodesIsBitwiseOp(const SOperatorNode* pOp); bool nodesExprHasColumn(SNode* pNode); bool nodesExprsHasColumn(SNodeList* pList); @@ -395,7 +397,8 @@ void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal); char* nodesGetFillModeString(EFillMode mode); int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc); -int32_t nodesPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagCond, SNode** pOtherCond); +int32_t nodesPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, + SNode** pOtherCond); #ifdef __cplusplus } diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 26f2758033..d86a8dae6e 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -266,19 +266,19 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define qDebug(...) \ do { \ if (qDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("QRY ", DEBUG_DEBUG, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \ } \ } while (0) #define qTrace(...) \ do { \ if (qDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("QRY ", DEBUG_TRACE, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \ } \ } while (0) #define qDebugL(...) \ do { \ if (qDebugFlag & DEBUG_DEBUG) { \ - taosPrintLongString("QRY ", DEBUG_DEBUG, tsLogEmbedded ? 255 : qDebugFlag, __VA_ARGS__); \ + taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \ } \ } while (0) diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 3b8a37f420..36e9b3309c 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -32,7 +32,7 @@ enum { }; typedef struct SDeleteRes { - uint64_t uid; + uint64_t suid; SArray* uidList; int64_t skey; int64_t ekey; diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index ee599e8498..a47810e7c1 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -77,7 +77,7 @@ typedef struct { typedef struct { int8_t type; - int32_t sourceVg; + int32_t srcVgId; int64_t sourceVer; SArray* blocks; // SArray @@ -145,11 +145,6 @@ void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit); SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit); -#if 0 -int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput); -void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput); -#endif - typedef struct { char* qmsg; // followings are not applicable to encoder and decoder @@ -234,26 +229,33 @@ enum { TASK_TRIGGER_STATUS__ACTIVE, }; +typedef struct { + int32_t nodeId; + int32_t childId; + int32_t taskId; + SEpSet epSet; +} SStreamChildEpInfo; + struct SStreamTask { int64_t streamId; int32_t taskId; - int8_t inputType; - int8_t taskStatus; - - int8_t execStatus; - + int8_t isDataScan; int8_t execType; int8_t sinkType; int8_t dispatchType; int16_t dispatchMsgType; - int8_t dataScan; + int8_t taskStatus; + int8_t execStatus; // node info - int32_t childId; + int32_t selfChildId; int32_t nodeId; SEpSet epSet; + // children info + SArray* childEpInfo; // SArray + // exec STaskExec exec; @@ -291,6 +293,9 @@ struct SStreamTask { SMsgCb* pMsgCb; }; +int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo); +int32_t tDecodeStreamEpInfo(SDecoder* pDecoder, SStreamChildEpInfo* pInfo); + SStreamTask* tNewSStreamTask(int64_t streamId); int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask); int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask); @@ -339,10 +344,12 @@ static FORCE_INLINE int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBloc if (pTask->sinkType == TASK_SINK__TABLE) { ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pBlock->blocks); + taosArrayDestroyEx(pBlock->blocks, (FDelete)tDeleteSSDataBlock); taosFreeQitem(pBlock); } else if (pTask->sinkType == TASK_SINK__SMA) { ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE); pTask->smaSink.smaSink(pTask->smaSink.vnode, pTask->smaSink.smaId, pBlock->blocks); + taosArrayDestroyEx(pBlock->blocks, (FDelete)tDeleteSSDataBlock); taosFreeQitem(pBlock); } else { ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE); @@ -369,9 +376,9 @@ typedef struct { typedef struct { int64_t streamId; int32_t taskId; - int32_t sourceTaskId; - int32_t sourceVg; - int32_t sourceChildId; + int32_t dataSrcVgId; + int32_t upstreamTaskId; + int32_t upstreamChildId; int32_t upstreamNodeId; #if 0 int64_t sourceVer; @@ -387,6 +394,23 @@ typedef struct { int8_t inputStatus; } SStreamDispatchRsp; +typedef struct { + int64_t streamId; + int32_t srcTaskId; + int32_t srcNodeId; + int32_t dstTaskId; + int32_t dstNodeId; + int32_t retrieveLen; + SRetrieveTableRsp* pRetrieve; +} SStreamRetrieveReq; + +typedef struct { + int64_t streamId; + int32_t childId; + int32_t rspFromTaskId; + int32_t rspToTaskId; +} SStreamRetrieveRsp; + typedef struct { int64_t streamId; int32_t taskId; @@ -401,6 +425,7 @@ typedef struct { } SStreamTaskRecoverRsp; int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq); +int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq); int32_t streamLaunchByWrite(SStreamTask* pTask, int32_t vgId); int32_t streamSetupTrigger(SStreamTask* pTask); @@ -411,6 +436,9 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp); int32_t streamProcessRecoverReq(SStreamTask* pTask, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg); int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp); +int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pMsg); +int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp); + #ifdef __cplusplus } #endif diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 2cb0c65d35..2bf49fa006 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -26,8 +26,9 @@ extern "C" { extern bool gRaftDetailLog; -#define SYNC_INDEX_BEGIN 0 +#define SYNC_INDEX_BEGIN 0 #define SYNC_INDEX_INVALID -1 +#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF typedef uint64_t SyncNodeId; typedef int32_t SyncGroupId; @@ -156,13 +157,13 @@ typedef struct SSyncLogStore { SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore); // refactor, log[0 .. n] ==> log[m .. n] - int32_t (*syncLogSetBeginIndex)(struct SSyncLogStore* pLogStore, SyncIndex beginIndex); - int32_t (*syncLogResetBeginIndex)(struct SSyncLogStore* pLogStore); + // int32_t (*syncLogSetBeginIndex)(struct SSyncLogStore* pLogStore, SyncIndex beginIndex); + SyncIndex (*syncLogBeginIndex)(struct SSyncLogStore* pLogStore); SyncIndex (*syncLogEndIndex)(struct SSyncLogStore* pLogStore); bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore); int32_t (*syncLogEntryCount)(struct SSyncLogStore* pLogStore); - // bool (*syncLogInRange)(struct SSyncLogStore* pLogStore, SyncIndex index); + int32_t (*syncLogRestoreFromSnapshot)(struct SSyncLogStore* pLogStore, SyncIndex index); SyncIndex (*syncLogWriteIndex)(struct SSyncLogStore* pLogStore); SyncIndex (*syncLogLastIndex)(struct SSyncLogStore* pLogStore); @@ -199,7 +200,7 @@ const char* syncGetMyRoleStr(int64_t rid); SyncTerm syncGetMyTerm(int64_t rid); SyncGroupId syncGetVgId(int64_t rid); void syncGetEpSet(int64_t rid, SEpSet* pEpSet); -int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); +int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak); bool syncEnvIsStart(); const char* syncStr(ESyncState state); bool syncIsRestoreFinish(int64_t rid); diff --git a/include/libs/sync/syncTools.h b/include/libs/sync/syncTools.h index 37b465e56e..e51b20a404 100644 --- a/include/libs/sync/syncTools.h +++ b/include/libs/sync/syncTools.h @@ -43,7 +43,7 @@ void setElectTimerMS(int64_t rid, int32_t electTimerMS); void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS); // for compatibility, the same as syncPropose -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak); +int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak); // utils const char* syncUtilState2String(ESyncState state); @@ -468,7 +468,7 @@ typedef struct SyncLeaderTransfer { SRaftId destId; */ SNodeInfo newNodeInfo; - SRaftId newLeaderId; + SRaftId newLeaderId; } SyncLeaderTransfer; SyncLeaderTransfer* syncLeaderTransferBuild(int32_t vgId); @@ -489,17 +489,16 @@ void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg); void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg); void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg); - // --------------------------------------------- typedef struct SyncReconfigFinish { - uint32_t bytes; - int32_t vgId; - uint32_t msgType; - SSyncCfg oldCfg; - SSyncCfg newCfg; + uint32_t bytes; + int32_t vgId; + uint32_t msgType; + SSyncCfg oldCfg; + SSyncCfg newCfg; SyncIndex newCfgIndex; - SyncTerm newCfgTerm; - uint64_t newCfgSeqNum; + SyncTerm newCfgTerm; + uint64_t newCfgSeqNum; } SyncReconfigFinish; @@ -521,8 +520,6 @@ void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg); void syncReconfigFinishLog(const SyncReconfigFinish* pMsg); void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); - - // on message ---------------------- int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index c7d1ccd3de..92701db2ad 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -195,7 +195,6 @@ void walCloseReadHandle(SWalReadHandle *); int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver); // only for tq usage -// int32_t walReadWithHandle_s(SWalReadHandle *pRead, int64_t ver, SWalReadHead **ppHead); void walSetReaderCapacity(SWalReadHandle *pRead, int32_t capacity); int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead); int32_t walFetchBody(SWalReadHandle *pRead, SWalHead **ppHead); @@ -211,13 +210,8 @@ void walCloseRef(SWalRef *); int32_t walRefVer(SWalRef *, int64_t ver); int32_t walUnrefVer(SWal *); -// deprecated -#if 0 -int32_t walRead(SWal *, SWalHead **, int64_t ver); -int32_t walReadWithFp(SWal *, FWalWrite writeFp, int64_t verStart, int32_t readNum); -#endif - // lifecycle check +bool walIsEmpty(SWal *); int64_t walGetFirstVer(SWal *); int64_t walGetSnapshotVer(SWal *); int64_t walGetLastVer(SWal *); diff --git a/include/os/os.h b/include/os/os.h index 41180ba49e..254c16efbe 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -104,8 +104,6 @@ extern "C" { #include "osTimezone.h" #include "osEnv.h" -void osDefaultInit(); - #ifdef __cplusplus } #endif diff --git a/include/util/taoserror.h b/include/util/taoserror.h index eb68f52a40..8af5945300 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -71,6 +71,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE TAOS_DEF_ERROR_CODE(0, 0x0029) #define TSDB_CODE_INVALID_TIMESTAMP TAOS_DEF_ERROR_CODE(0, 0x0030) #define TSDB_CODE_MSG_DECODE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0031) +#define TSDB_CODE_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0032) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0040) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0041) diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 06fa9fd9aa..102656da2b 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -33,7 +33,8 @@ typedef enum { CFG_STYPE_ENV_CMD, CFG_STYPE_APOLLO_URL, CFG_STYPE_ARG_LIST, - CFG_STYPE_TAOS_OPTIONS + CFG_STYPE_TAOS_OPTIONS, + CFG_STYPE_ALTER_CMD, } ECfgSrcType; typedef enum { @@ -104,6 +105,8 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal); const char *cfgStypeStr(ECfgSrcType type); const char *cfgDtypeStr(ECfgDataType type); +void cfgDumpItemValue(SConfigItem *pItem, char* buf, int32_t bufSize, int32_t* pLen); + void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl); diff --git a/include/util/tdef.h b/include/util/tdef.h index 5304dba741..5befa6a67f 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -134,7 +134,7 @@ typedef enum EOperatorType { OP_TYPE_MINUS, OP_TYPE_ASSIGN, - // bit operator + // bitwise operator OP_TYPE_BIT_AND, OP_TYPE_BIT_OR, @@ -443,8 +443,8 @@ enum { #define VNODE_HANDLE -3 #define BNODE_HANDLE -4 -#define TSDB_CONFIG_OPTION_LEN 16 -#define TSDB_CONIIG_VALUE_LEN 48 +#define TSDB_CONFIG_OPTION_LEN 32 +#define TSDB_CONFIG_VALUE_LEN 64 #define TSDB_CONFIG_NUMBER 8 #define QUERY_ID_SIZE 20 diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index cfe507e505..2b918412fe 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -215,6 +215,7 @@ typedef struct SRequestObj { SQueryExecMetric metric; SRequestSendRecvBody body; bool stableQuery; + bool validateOnly; bool killed; uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog @@ -235,7 +236,12 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveT bool freeAfterUse); void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); void doFreeReqResultInfo(SReqResultInfo* pResInfo); -SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen); +int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq); +void syncCatalogFn(SMetaData* pResult, void* param, int32_t code); + +SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly); +TAOS_RES *taosQueryImpl(TAOS *taos, const char *sql, bool validateOnly); +void taosAsyncQueryImpl(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, bool validateOnly); static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { SMqRspObj* msg = (SMqRspObj*)res; @@ -301,7 +307,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port, int connType); -SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen); +SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly); int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 37b8866e25..51e709ac58 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -237,6 +237,10 @@ static SAppInstInfo* getAppInfo(SRequestObj* pRequest) { return pRequest->pTscOb void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { SRetrieveTableRsp* pRsp = NULL; + if (pRequest->validateOnly) { + pRequest->body.queryFp(pRequest->body.param, pRequest, 0); + return; + } int32_t code = qExecCommand(pQuery->pRoot, &pRsp); if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { @@ -261,6 +265,11 @@ void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { } int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { + if (pRequest->validateOnly) { + pRequest->body.queryFp(pRequest->body.param, pRequest, 0); + return TSDB_CODE_SUCCESS; + } + // drop table if exists not_exists_table if (NULL == pQuery->pCmdMsg) { pRequest->body.queryFp(pRequest->body.param, pRequest, 0); @@ -276,8 +285,11 @@ int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); int64_t transporterId = 0; - asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg); - return TSDB_CODE_SUCCESS; + int32_t code = asyncSendMsgToServer(pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg); + if (code) { + pRequest->body.queryFp(pRequest->body.param, pRequest, code); + } + return code; } int compareQueryNodeLoad(const void* elem1, const void* elem2) { @@ -851,15 +863,19 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue switch (pQuery->execMode) { case QUERY_EXEC_MODE_LOCAL: - code = execLocalCmd(pRequest, pQuery); + if (!pRequest->validateOnly) { + code = execLocalCmd(pRequest, pQuery); + } break; case QUERY_EXEC_MODE_RPC: - code = execDdlQuery(pRequest, pQuery); + if (!pRequest->validateOnly) { + code = execDdlQuery(pRequest, pQuery); + } break; case QUERY_EXEC_MODE_SCHEDULE: { SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad)); code = getPlan(pRequest, pQuery, &pRequest->body.pDag, pMnodeList); - if (TSDB_CODE_SUCCESS == code) { + if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { SArray* pNodeList = NULL; buildSyncExecNodeList(pRequest, &pNodeList, pMnodeList); @@ -894,7 +910,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue return pRequest; } -SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) { +SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly) { SRequestObj* pRequest = NULL; SQuery* pQuery = NULL; @@ -904,6 +920,8 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) { return NULL; } + pRequest->validateOnly = validateOnly; + code = parseSql(pRequest, false, &pQuery, NULL); if (code != TSDB_CODE_SUCCESS) { pRequest->code = code; @@ -945,7 +963,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData *pResultM pRequest->requestId); } - if (TSDB_CODE_SUCCESS == code) { + if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { SArray* pNodeList = NULL; buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); @@ -962,7 +980,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData *pResultM code = schedulerAsyncExecJob(&req, &pRequest->body.queryJob); taosArrayDestroy(pNodeList); } else { - tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), + tscDebug("0x%" PRIx64 " plan not executed, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code), pRequest->requestId); pRequest->body.queryFp(pRequest->body.param, pRequest, code); } @@ -1045,14 +1063,14 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList) { return TSDB_CODE_SUCCESS; } -SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { +SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen, bool validateOnly) { SRequestObj* pRequest = NULL; int32_t retryNum = 0; int32_t code = 0; do { destroyRequest(pRequest); - pRequest = launchQuery(pTscObj, sql, sqlLen); + pRequest = launchQuery(pTscObj, sql, sqlLen, validateOnly); if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) { break; } @@ -1507,7 +1525,7 @@ static int32_t estimateJsonLen(SReqResultInfo* pResultInfo, int32_t numOfCols, i char* jsonInnerData = data + CHAR_BYTES; if (jsonInnerType == TSDB_DATA_TYPE_NULL) { len += (VARSTR_HEADER_SIZE + strlen(TSDB_DATA_NULL_STR_L)); - } else if (jsonInnerType & TD_TAG_JSON) { + } else if (tTagIsJson(data)) { len += (VARSTR_HEADER_SIZE + ((const STag*)(data))->len); } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value" len += varDataTLen(jsonInnerData) + CHAR_BYTES * 2; @@ -1592,7 +1610,7 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int if (jsonInnerType == TSDB_DATA_TYPE_NULL) { sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L); varDataSetLen(dst, strlen(varDataVal(dst))); - } else if (jsonInnerType & TD_TAG_JSON) { + } else if (tTagIsJson(data)) { char* jsonString = parseTagDatatoJson(data); STR_TO_VARSTR(dst, jsonString); taosMemoryFree(jsonString); @@ -1819,3 +1837,251 @@ _OVER: } return code; } + +int32_t appendTbToReq(SArray* pList, int32_t pos1, int32_t len1, int32_t pos2, int32_t len2, const char* str, int32_t acctId, char* db) { + SName name; + + if (len1 <= 0) { + return -1; + } + + const char *dbName = db; + const char *tbName = NULL; + int32_t dbLen = 0; + int32_t tbLen = 0; + if (len2 > 0) { + dbName = str + pos1; + dbLen = len1; + tbName = str + pos2; + tbLen = len2; + } else { + dbLen = strlen(db); + tbName = str + pos1; + tbLen = len1; + } + + if (tNameSetDbName(&name, acctId, dbName, dbLen)) { + return -1; + } + + if (tNameAddTbName(&name, tbName, tbLen)) { + return -1; + } + + taosArrayPush(pList, &name); + + return TSDB_CODE_SUCCESS; +} + +int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq) { + *pReq = taosArrayInit(10, sizeof(SName)); + if (NULL == *pReq) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + bool inEscape = false; + int32_t code = 0; + + int32_t vIdx = 0; + int32_t vPos[2]; + int32_t vLen[2]; + + memset(vPos, -1, sizeof(vPos)); + memset(vLen, 0, sizeof(vLen)); + + for (int32_t i = 0; ; ++i) { + if (0 == *(tbList + i)) { + if (vPos[vIdx] >= 0 && vLen[vIdx] <= 0) { + vLen[vIdx] = i - vPos[vIdx]; + } + + code = appendTbToReq(*pReq, vPos[0], vLen[0], vPos[1], vLen[1], tbList, acctId, dbName); + if (code) { + goto _return; + } + + break; + } + + if ('`' == *(tbList + i)) { + inEscape = !inEscape; + if (!inEscape) { + if (vPos[vIdx] >= 0) { + vLen[vIdx] = i - vPos[vIdx]; + } else { + goto _return; + } + } + + continue; + } + + if (inEscape) { + if (vPos[vIdx] < 0) { + vPos[vIdx] = i; + } + continue; + } + + if ('.' == *(tbList + i)) { + if (vPos[vIdx] < 0) { + goto _return; + } + if (vLen[vIdx] <= 0) { + vLen[vIdx] = i - vPos[vIdx]; + } + vIdx++; + if (vIdx >= 2) { + goto _return; + } + continue; + } + + if (',' == *(tbList + i)) { + if (vPos[vIdx] < 0) { + goto _return; + } + if (vLen[vIdx] <= 0) { + vLen[vIdx] = i - vPos[vIdx]; + } + + code = appendTbToReq(*pReq, vPos[0], vLen[0], vPos[1], vLen[1], tbList, acctId, dbName); + if (code) { + goto _return; + } + + memset(vPos, -1, sizeof(vPos)); + memset(vLen, 0, sizeof(vLen)); + vIdx = 0; + continue; + } + + if (' ' == *(tbList + i) || '\r' == *(tbList + i) || '\t' == *(tbList + i) || '\n' == *(tbList + i)) { + if (vPos[vIdx] >= 0 && vLen[vIdx] <= 0) { + vLen[vIdx] = i - vPos[vIdx]; + } + continue; + } + + if (('a' <= *(tbList + i) && 'z' >= *(tbList + i)) || + ('A' <= *(tbList + i) && 'Z' >= *(tbList + i)) || + ('0' <= *(tbList + i) && '9' >= *(tbList + i))) { + if (vLen[vIdx] > 0) { + goto _return; + } + if (vPos[vIdx] < 0) { + vPos[vIdx] = i; + } + continue; + } + + goto _return; + } + + return TSDB_CODE_SUCCESS; + +_return: + + terrno = TSDB_CODE_TSC_INVALID_OPERATION; + + taosArrayDestroy(*pReq); + *pReq = NULL; + + return terrno; +} + +void syncCatalogFn(SMetaData* pResult, void* param, int32_t code) { + SSyncQueryParam *pParam = param; + pParam->pRequest->code = code; + + tsem_post(&pParam->sem); +} + + +void syncQueryFn(void *param, void *res, int32_t code) { + SSyncQueryParam *pParam = param; + pParam->pRequest = res; + pParam->pRequest->code = code; + + tsem_post(&pParam->sem); +} + +void taosAsyncQueryImpl(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, bool validateOnly) { + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); + if (pTscObj == NULL || sql == NULL || NULL == fp) { + terrno = TSDB_CODE_INVALID_PARA; + if (pTscObj) { + releaseTscObj(*(int64_t *)taos); + } else { + terrno = TSDB_CODE_TSC_DISCONNECTED; + } + fp(param, NULL, terrno); + return; + } + + size_t sqlLen = strlen(sql); + if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { + tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); + terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; + + fp(param, NULL, terrno); + return; + } + + SRequestObj *pRequest = NULL; + int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + fp(param, NULL, terrno); + return; + } + + pRequest->validateOnly = validateOnly; + pRequest->body.queryFp = fp; + pRequest->body.param = param; + doAsyncQuery(pRequest, false); +} + + +TAOS_RES *taosQueryImpl(TAOS *taos, const char *sql, bool validateOnly) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); + if (pTscObj == NULL || sql == NULL) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + +#if SYNC_ON_TOP_OF_ASYNC + SSyncQueryParam *param = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); + tsem_init(¶m->sem, 0, 0); + + taosAsyncQueryImpl(taos, sql, syncQueryFn, param, validateOnly); + tsem_wait(¶m->sem); + + releaseTscObj(*(int64_t *)taos); + + return param->pRequest; +#else + size_t sqlLen = strlen(sql); + if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { + releaseTscObj(*(int64_t *)taos); + tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); + terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; + return NULL; + } + + TAOS_RES *pRes = execQuery(pTscObj, sql, sqlLen, validateOnly); + + releaseTscObj(*(int64_t *)taos); + + return pRes; +#endif +} + + + diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index ab4d14b1cc..515136bb27 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -81,12 +81,6 @@ void taos_cleanup(void) { taosCloseLog(); } -setConfRet taos_set_config(const char *config) { - // TODO - setConfRet ret = {SET_CONF_RET_SUCC, {0}}; - return ret; -} - TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db); if (user == NULL) { @@ -205,51 +199,9 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { return pResInfo->userFields; } -static void syncQueryFn(void *param, void *res, int32_t code) { - SSyncQueryParam *pParam = param; - pParam->pRequest = res; - pParam->pRequest->code = code; - - tsem_post(&pParam->sem); -} TAOS_RES *taos_query(TAOS *taos, const char *sql) { - if (NULL == taos) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return NULL; - } - - STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); - if (pTscObj == NULL || sql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return NULL; - } - -#if SYNC_ON_TOP_OF_ASYNC - SSyncQueryParam *param = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); - tsem_init(¶m->sem, 0, 0); - - taos_query_a(taos, sql, syncQueryFn, param); - tsem_wait(¶m->sem); - - releaseTscObj(*(int64_t *)taos); - - return param->pRequest; -#else - size_t sqlLen = strlen(sql); - if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { - releaseTscObj(*(int64_t *)taos); - tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); - terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - return NULL; - } - - TAOS_RES *pRes = execQuery(pTscObj, sql, sqlLen); - - releaseTscObj(*(int64_t *)taos); - - return pRes; -#endif + return taosQueryImpl(taos, sql, false); } TAOS_ROW taos_fetch_row(TAOS_RES *res) { @@ -290,6 +242,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { pResultInfo->current += 1; return pResultInfo->row; } + } else if (TD_RES_TMQ_META(res)) { + return NULL; } else { // assert to avoid un-initialization error ASSERT(0); @@ -639,7 +593,14 @@ int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { return pResInfo->pCol[columnIndex].offset; } -int taos_validate_sql(TAOS *taos, const char *sql) { return true; } +int taos_validate_sql(TAOS *taos, const char *sql) { + TAOS_RES* pObj = taosQueryImpl(taos, sql, true); + + int code = taos_errno(pObj); + + taos_free_result(pObj); + return code; +} void taos_reset_current_db(TAOS *taos) { STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); @@ -729,38 +690,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { - STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); - if (pTscObj == NULL || sql == NULL || NULL == fp) { - terrno = TSDB_CODE_INVALID_PARA; - if (pTscObj) { - releaseTscObj(*(int64_t *)taos); - } else { - terrno = TSDB_CODE_TSC_DISCONNECTED; - } - fp(param, NULL, terrno); - return; - } - - size_t sqlLen = strlen(sql); - if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { - tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); - terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; - - fp(param, NULL, terrno); - return; - } - - SRequestObj *pRequest = NULL; - int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); - if (code != TSDB_CODE_SUCCESS) { - terrno = code; - fp(param, NULL, terrno); - return; - } - - pRequest->body.queryFp = fp; - pRequest->body.param = param; - doAsyncQuery(pRequest, false); + taosAsyncQueryImpl(taos, sql, fp, param, false); } int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) { @@ -953,10 +883,75 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { } int taos_load_table_info(TAOS *taos, const char *tableNameList) { - // TODO - return -1; + const int32_t MAX_TABLE_NAME_LENGTH = 12 * 1024 * 1024; // 12MB list + int32_t code = 0; + SRequestObj *pRequest = NULL; + SCatalogReq catalogReq = {0}; + + if (NULL == tableNameList) { + return TSDB_CODE_SUCCESS; + } + + int32_t length = (int32_t)strlen(tableNameList); + if (0 == length) { + return TSDB_CODE_SUCCESS; + } else if (length > MAX_TABLE_NAME_LENGTH) { + tscError("tableNameList too long, length:%d, maximum allowed:%d", length, MAX_TABLE_NAME_LENGTH); + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + STscObj *pTscObj = acquireTscObj(*(int64_t *)taos); + if (pTscObj == NULL) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return terrno; + } + + code = transferTableNameList(tableNameList, pTscObj->acctId, pTscObj->db, &catalogReq.pTableMeta); + if (code) { + goto _return; + } + + SCatalog* pCtg = NULL; + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg); + if (code != TSDB_CODE_SUCCESS) { + goto _return; + } + + char* sql = "taos_load_table_info"; + code = buildRequest(pTscObj, sql, strlen(sql), &pRequest); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + goto _return; + } + + SSyncQueryParam param = {0}; + tsem_init(¶m.sem, 0, 0); + param.pRequest = pRequest; + + SRequestConnInfo conn = {.pTrans = pTscObj->pAppInfo->pTransporter, + .requestId = pRequest->requestId, + .requestObjRefId = pRequest->self}; + + conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); + + code = catalogAsyncGetAllMeta(pCtg, &conn, pRequest->requestId, &catalogReq, syncCatalogFn, ¶m, NULL); + if (code) { + goto _return; + } + + tsem_wait(¶m.sem); + +_return: + + taosArrayDestroy(catalogReq.pTableMeta); + destroyRequest(pRequest); + + releaseTscObj(*(int64_t *)taos); + + return code; } + TAOS_STMT *taos_stmt_init(TAOS *taos) { STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 3c349f61a1..637a7ee5dd 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -54,6 +54,7 @@ struct tmq_conf_t { int8_t autoCommit; int8_t resetOffset; int8_t withTbName; + int8_t useSnapshot; uint16_t port; int32_t autoCommitInterval; char* ip; @@ -69,6 +70,7 @@ struct tmq_t { char groupId[TSDB_CGROUP_LEN]; char clientId[256]; int8_t withTbName; + int8_t useSnapshot; int8_t autoCommit; int32_t autoCommitInterval; int32_t resetOffsetCfg; @@ -282,6 +284,18 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } } + if (strcmp(key, "experiment.use.snapshot") == 0) { + if (strcmp(value, "true") == 0) { + conf->useSnapshot = true; + return TMQ_CONF_OK; + } else if (strcmp(value, "false") == 0) { + conf->useSnapshot = false; + return TMQ_CONF_OK; + } else { + return TMQ_CONF_INVALID; + } + } + if (strcmp(key, "td.connect.ip") == 0) { conf->ip = strdup(value); return TMQ_CONF_OK; @@ -953,6 +967,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { strcpy(pTmq->clientId, conf->clientId); strcpy(pTmq->groupId, conf->groupId); pTmq->withTbName = conf->withTbName; + pTmq->useSnapshot = conf->useSnapshot; pTmq->autoCommit = conf->autoCommit; pTmq->autoCommitInterval = conf->autoCommitInterval; pTmq->commitCb = conf->commitCb; @@ -1145,8 +1160,6 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { // handle meta rsp int8_t rspType = ((SMqRspHead*)pMsg->pData)->mqMsgType; - if (rspType == TMQ_MSG_TYPE__POLL_META_RSP) { - } SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM); if (pRspWrapper == NULL) { @@ -1159,19 +1172,19 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { pRspWrapper->vgHandle = pVg; pRspWrapper->topicHandle = pTopic; - memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead)); - if (rspType == TMQ_MSG_TYPE__POLL_RSP) { + memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead)); tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->dataRsp); } else { ASSERT(rspType == TMQ_MSG_TYPE__POLL_META_RSP); + memcpy(&pRspWrapper->metaRsp, pMsg->pData, sizeof(SMqRspHead)); tDecodeSMqMetaRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->metaRsp); } taosMemoryFree(pMsg->pData); - tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pVg->vgId, - pRspWrapper->dataRsp.reqOffset, pRspWrapper->dataRsp.rspOffset); + tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld, type %d", tmq->consumerId, pVg->vgId, + pRspWrapper->dataRsp.reqOffset, pRspWrapper->dataRsp.rspOffset, rspType); taosWriteQitem(tmq->mqueue, pRspWrapper); tsem_post(&tmq->rspSem); @@ -1534,6 +1547,8 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t timeout, SMqClientTopic* pReq->currentOffset = reqOffset; pReq->reqId = generateRequestId(); + pReq->useSnapshot = tmq->useSnapshot; + pReq->head.vgId = htonl(pVg->vgId); pReq->head.contLen = htonl(sizeof(SMqPollReq)); return pReq; @@ -1541,7 +1556,7 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t timeout, SMqClientTopic* SMqMetaRspObj* tmqBuildMetaRspFromWrapper(SMqPollRspWrapper* pWrapper) { SMqMetaRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqMetaRspObj)); - pRspObj->resType = RES_TYPE__TMQ; + pRspObj->resType = RES_TYPE__TMQ_META; tstrncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN); tstrncpy(pRspObj->db, pWrapper->topicHandle->db, TSDB_DB_FNAME_LEN); pRspObj->vgId = pWrapper->vgHandle->vgId; @@ -1659,7 +1674,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset) return 0; } -SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { +void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { while (1) { SMqRspWrapper* rspWrapper = NULL; taosGetQitem(tmq->qall, (void**)&rspWrapper); @@ -1699,18 +1714,18 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { } else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_META_RSP) { SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; int32_t consumerEpoch = atomic_load_32(&tmq->epoch); - if (pollRspWrapper->dataRsp.head.epoch == consumerEpoch) { + if (pollRspWrapper->metaRsp.head.epoch == consumerEpoch) { SMqClientVg* pVg = pollRspWrapper->vgHandle; /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ - pVg->currentOffset = pollRspWrapper->dataRsp.rspOffset; + pVg->currentOffset = pollRspWrapper->metaRsp.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); // build rsp - SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper); + SMqMetaRspObj* pRsp = tmqBuildMetaRspFromWrapper(pollRspWrapper); taosFreeQitem(pollRspWrapper); return pRsp; } else { tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", - pollRspWrapper->dataRsp.head.epoch, consumerEpoch); + pollRspWrapper->metaRsp.head.epoch, consumerEpoch); taosFreeQitem(pollRspWrapper); } } else { @@ -1727,8 +1742,8 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { } TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { - SMqRspObj* rspObj; - int64_t startTime = taosGetTimestampMs(); + void* rspObj; + int64_t startTime = taosGetTimestampMs(); #if 0 tmqHandleAllDelayedTask(tmq); @@ -1856,7 +1871,7 @@ const char* tmq_get_table_name(TAOS_RES* res) { return NULL; } -int32_t tmq_get_raw_meta(TAOS_RES* res, const void** raw_meta, int32_t* raw_meta_len) { +int32_t tmq_get_raw_meta(TAOS_RES* res, void** raw_meta, int32_t* raw_meta_len) { if (TD_RES_TMQ_META(res)) { SMqMetaRspObj* pMetaRspObj = (SMqMetaRspObj*)res; *raw_meta = pMetaRspObj->metaRsp.metaRsp; diff --git a/source/common/src/systable.c b/source/common/src/systable.c index e7b6342150..455f204542 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -231,7 +231,13 @@ static const SSysDbTableSchema transSchema[] = { static const SSysDbTableSchema configSchema[] = { {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "value", .bytes = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "value", .bytes = TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SSysDbTableSchema variablesSchema[] = { + {.name = "dnode_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "value", .bytes = TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysTableMeta infosMeta[] = { @@ -253,6 +259,7 @@ static const SSysTableMeta infosMeta[] = { {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, {TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)}, + {TSDB_INS_TABLE_DNODE_VARIABLES, variablesSchema, tListLen(variablesSchema)}, }; static const SSysDbTableSchema connectionsSchema[] = { diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 3c3d3e953d..593f8c5c0b 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -110,7 +110,7 @@ int32_t getJsonValueLen(const char* data) { dataLen = DOUBLE_BYTES + CHAR_BYTES; } else if (*data == TSDB_DATA_TYPE_BOOL) { dataLen = CHAR_BYTES + CHAR_BYTES; - } else if (*data & TD_TAG_JSON) { // json string + } else if (tTagIsJson(data)) { // json string dataLen = ((STag*)(data))->len; } else { ASSERT(0); @@ -214,7 +214,7 @@ static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, c } } -int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity, +int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, uint32_t* capacity, const SColumnInfoData* pSource, uint32_t numOfRow2) { ASSERT(pColumnInfoData != NULL && pSource != NULL && pColumnInfoData->info.type == pSource->info.type); if (numOfRow2 == 0) { @@ -263,6 +263,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, in pColumnInfoData->varmeta.length = len + oldLen; } else { if (finalNumOfRows > *capacity) { + ASSERT(finalNumOfRows * pColumnInfoData->info.bytes); char* tmp = taosMemoryRealloc(pColumnInfoData->pData, finalNumOfRows * pColumnInfoData->info.bytes); if (tmp == NULL) { return TSDB_CODE_VND_OUT_OF_MEMORY; @@ -292,22 +293,19 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, in return numOfRow1 + numOfRow2; } -int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows) { +int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows, + const SDataBlockInfo* pBlockInfo) { ASSERT(pColumnInfoData != NULL && pSource != NULL && pColumnInfoData->info.type == pSource->info.type); if (numOfRows <= 0) { return numOfRows; } + if (pBlockInfo != NULL) { + ASSERT(pBlockInfo->capacity >= numOfRows); + } + if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { - // Handle the bitmap - char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * numOfRows); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pColumnInfoData->varmeta.offset = (int32_t*)p; memcpy(pColumnInfoData->varmeta.offset, pSource->varmeta.offset, sizeof(int32_t) * numOfRows); - if (pColumnInfoData->varmeta.allocLen < pSource->varmeta.length) { char* tmp = taosMemoryRealloc(pColumnInfoData->pData, pSource->varmeta.length); if (tmp == NULL) { @@ -318,27 +316,11 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p pColumnInfoData->varmeta.allocLen = pSource->varmeta.length; } - memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length); pColumnInfoData->varmeta.length = pSource->varmeta.length; + memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length); } else { - char* tmp = taosMemoryRealloc(pColumnInfoData->nullbitmap, BitmapLen(numOfRows)); - if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pColumnInfoData->nullbitmap = tmp; memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows)); - - if (pSource->pData) { - int32_t newSize = numOfRows * pColumnInfoData->info.bytes; - tmp = taosMemoryRealloc(pColumnInfoData->pData, newSize); - if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pColumnInfoData->pData = tmp; - memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows); - } + memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows); } pColumnInfoData->hasNull = pSource->hasNull; @@ -346,10 +328,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p return 0; } -size_t blockDataGetNumOfCols(const SSDataBlock* pBlock) { - ASSERT(pBlock && pBlock->info.numOfCols == taosArrayGetSize(pBlock->pDataBlock)); - return pBlock->info.numOfCols; -} +size_t blockDataGetNumOfCols(const SSDataBlock* pBlock) { return taosArrayGetSize(pBlock->pDataBlock); } size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) { return pBlock->info.rows; } @@ -358,7 +337,8 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex) return 0; } - if (pDataBlock->info.numOfCols <= 0) { + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + if (numOfCols <= 0) { return -1; } @@ -382,7 +362,8 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { assert(pSrc != NULL && pDest != NULL); int32_t capacity = pDest->info.capacity; - for (int32_t i = 0; i < pDest->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pDest->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i); SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i); @@ -398,9 +379,8 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { size_t blockDataGetSize(const SSDataBlock* pBlock) { assert(pBlock != NULL); - size_t total = 0; - int32_t numOfCols = pBlock->info.numOfCols; - + size_t total = 0; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); total += colDataGetFullLength(pColInfoData, pBlock->info.rows); @@ -415,7 +395,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd int32_t pageSize) { ASSERT(pBlock != NULL && stopIndex != NULL); - int32_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); int32_t numOfRows = pBlock->info.rows; int32_t bitmapChar = 1; @@ -476,33 +456,24 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3 return NULL; } - SSDataBlock* pDst = taosMemoryCalloc(1, sizeof(SSDataBlock)); + SSDataBlock* pDst = createDataBlock(); if (pDst == NULL) { return NULL; } pDst->info = pBlock->info; - pDst->info.rows = 0; - pDst->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); - - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfo = {0}; SColumnInfoData* pSrcCol = taosArrayGet(pBlock->pDataBlock, i); colInfo.info = pSrcCol->info; - - if (IS_VAR_DATA_TYPE(pSrcCol->info.type)) { - SVarColAttr* pAttr = &colInfo.varmeta; - pAttr->offset = taosMemoryCalloc(rowCount, sizeof(int32_t)); - } else { - colInfo.nullbitmap = taosMemoryCalloc(1, BitmapLen(rowCount)); - colInfo.pData = taosMemoryCalloc(rowCount, colInfo.info.bytes); - } - - taosArrayPush(pDst->pDataBlock, &colInfo); + blockDataAppendColInfo(pDst, &colInfo); } - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + blockDataEnsureCapacity(pDst, rowCount); + + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i); SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, i); @@ -540,7 +511,7 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock) { // write the number of rows *(uint32_t*)buf = pBlock->info.rows; - int32_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); int32_t numOfRows = pBlock->info.rows; char* pStart = buf + sizeof(uint32_t); @@ -570,7 +541,7 @@ int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock) { int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { pBlock->info.rows = *(int32_t*)buf; - int32_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); const char* pStart = buf + sizeof(uint32_t); for (int32_t i = 0; i < numOfCols; ++i) { @@ -619,7 +590,8 @@ int32_t blockDataFromBuf1(SSDataBlock* pBlock, const char* buf, size_t capacity) pBlock->info.rows = *(int32_t*)buf; pBlock->info.groupId = *(uint64_t*)(buf + sizeof(int32_t)); - int32_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + const char* pStart = buf + sizeof(uint32_t) + sizeof(uint64_t); for (int32_t i = 0; i < numOfCols; ++i) { @@ -665,7 +637,7 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) { if (pBlock->info.rowSize == 0) { size_t rowSize = 0; - size_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); rowSize += pColInfo->info.bytes; @@ -692,7 +664,7 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { ASSERT(pBlock != NULL); double rowSize = 0; - size_t numOfCols = pBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); rowSize += pColInfo->info.bytes; @@ -761,7 +733,7 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) { static int32_t doAssignOneTuple(SColumnInfoData* pDstCols, int32_t numOfRows, const SSDataBlock* pSrcBlock, int32_t tupleIndex) { int32_t code = 0; - int32_t numOfCols = pSrcBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pSrcBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pDst = &pDstCols[i]; @@ -784,7 +756,7 @@ static int32_t doAssignOneTuple(SColumnInfoData* pDstCols, int32_t numOfRows, co return TSDB_CODE_SUCCESS; } -static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataBlock, int32_t* index) { +static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataBlock, const int32_t* index) { #if 0 for (int32_t i = 0; i < pDataBlock->info.rows; ++i) { int32_t code = doAssignOneTuple(pCols, i, pDataBlock, index[i]); @@ -793,7 +765,8 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB } } #else - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pDst = &pCols[i]; SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i); @@ -820,7 +793,7 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) { int32_t rows = pDataBlock->info.rows; - int32_t numOfCols = pDataBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData)); if (pCols == NULL) { @@ -847,7 +820,7 @@ static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) { } static void copyBackToBlock(SSDataBlock* pDataBlock, SColumnInfoData* pCols) { - int32_t numOfCols = pDataBlock->info.numOfCols; + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i); @@ -908,8 +881,10 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { } } + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + if (taosArrayGetSize(pOrderInfo) == 1 && (!sortColumnHasNull)) { - if (pDataBlock->info.numOfCols == 1) { + if (numOfCols == 1) { if (!varTypeSort) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, 0); SBlockOrderInfo* pOrder = taosArrayGet(pOrderInfo, 0); @@ -925,7 +900,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { return TSDB_CODE_SUCCESS; } else { // var data type } - } else if (pDataBlock->info.numOfCols == 2) { + } else if (numOfCols == 2) { } } @@ -1119,33 +1094,39 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF void blockDataCleanup(SSDataBlock* pDataBlock) { pDataBlock->info.rows = 0; - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); colInfoDataCleanup(p, pDataBlock->info.capacity); } } -int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, uint32_t numOfRows) { - if (0 == numOfRows || numOfRows <= existRows) { +static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows) { + ASSERT(numOfRows > 0 && pBlockInfo->capacity >= pBlockInfo->rows); + if (numOfRows < pBlockInfo->capacity) { return TSDB_CODE_SUCCESS; } + // todo temp disable it + // ASSERT(pColumn->info.bytes != 0); + + int32_t existedRows = pBlockInfo->rows; + if (IS_VAR_DATA_TYPE(pColumn->info.type)) { char* tmp = taosMemoryRealloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows); - if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } pColumn->varmeta.offset = (int32_t*)tmp; - memset(&pColumn->varmeta.offset[existRows], 0, sizeof(int32_t) * (numOfRows - existRows)); + memset(&pColumn->varmeta.offset[existedRows], 0, sizeof(int32_t) * (numOfRows - existedRows)); } else { char* tmp = taosMemoryRealloc(pColumn->nullbitmap, BitmapLen(numOfRows)); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - int32_t oldLen = BitmapLen(existRows); + int32_t oldLen = BitmapLen(existedRows); pColumn->nullbitmap = tmp; memset(&pColumn->nullbitmap[oldLen], 0, BitmapLen(numOfRows) - oldLen); @@ -1158,8 +1139,8 @@ int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, size_t existRows, ui if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - memset(tmp + pColumn->info.bytes * existRows, 0, pColumn->info.bytes * (numOfRows - existRows)); + memset(tmp + pColumn->info.bytes * existedRows, 0, pColumn->info.bytes * (numOfRows - existedRows)); pColumn->pData = tmp; } @@ -1176,17 +1157,27 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) { } } +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows) { + SDataBlockInfo info = {0}; + return doEnsureCapacity(pColumn, &info, numOfRows); +} + int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) { int32_t code = 0; + ASSERT(numOfRows > 0); + if (numOfRows == 0) { return TSDB_CODE_SUCCESS; } - pDataBlock->info.capacity = numOfRows; + if (pDataBlock->info.capacity < numOfRows) { + pDataBlock->info.capacity = numOfRows; + } - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); - code = colInfoDataEnsureCapacity(p, pDataBlock->info.rows, numOfRows); + code = doEnsureCapacity(p, &pDataBlock->info, numOfRows); if (code) { return code; } @@ -1204,46 +1195,74 @@ void* blockDataDestroy(SSDataBlock* pBlock) { taosMemoryFreeClear(pBlock); return NULL; } +int32_t assignOneDataBlock(SSDataBlock* dst, const SSDataBlock* src) { + ASSERT(src != NULL); + + dst->info = src->info; + dst->info.rows = 0; + dst->info.capacity = 0; + + size_t numOfCols = taosArrayGetSize(src->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* p = taosArrayGet(src->pDataBlock, i); + SColumnInfoData colInfo = {.hasNull = true, .info = p->info}; + blockDataAppendColInfo(dst, &colInfo); + } + + int32_t code = blockDataEnsureCapacity(dst, src->info.rows); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + return -1; + } + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pDst = taosArrayGet(dst->pDataBlock, i); + SColumnInfoData* pSrc = taosArrayGet(src->pDataBlock, i); + if (pSrc->pData == NULL) { + continue; + } + + colDataAssign(pDst, pSrc, src->info.rows, &src->info); + } + + dst->info.rows = src->info.rows; + dst->info.capacity = src->info.rows; + return 0; +} SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) { if (pDataBlock == NULL) { return NULL; } - int32_t numOfCols = pDataBlock->info.numOfCols; - - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - - pBlock->info.numOfCols = numOfCols; - pBlock->info.hasVarCol = pDataBlock->info.hasVarCol; - pBlock->info.rowSize = pDataBlock->info.rowSize; - pBlock->info.groupId = pDataBlock->info.groupId; - pBlock->info.childId = pDataBlock->info.childId; - pBlock->info.type = pDataBlock->info.type; + SSDataBlock* pBlock = createDataBlock(); + pBlock->info = pDataBlock->info; + pBlock->info.rows = 0; + pBlock->info.capacity = 0; + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData colInfo = {0}; SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); - colInfo.info = p->info; - colInfo.hasNull = true; - taosArrayPush(pBlock->pDataBlock, &colInfo); + SColumnInfoData colInfo = {.hasNull = true, .info = p->info}; + blockDataAppendColInfo(pBlock, &colInfo); } if (copyData) { + int32_t code = blockDataEnsureCapacity(pBlock, pDataBlock->info.rows); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + blockDataDestroy(pBlock); + return NULL; + } + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i); SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i); - - int32_t code = colInfoDataEnsureCapacity(pDst, 0, pDataBlock->info.rows); - if (code != TSDB_CODE_SUCCESS) { - return NULL; - } - if (pSrc->pData == NULL) { continue; } - colDataAssign(pDst, pSrc, pDataBlock->info.rows); + + colDataAssign(pDst, pSrc, pDataBlock->info.rows, &pDataBlock->info); } pBlock->info.rows = pDataBlock->info.rows; @@ -1253,16 +1272,75 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) { return pBlock; } +SSDataBlock* createDataBlock() { + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + if (pBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + } + + pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + if (pBlock->pDataBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pBlock); + } + + return pBlock; +} + +int32_t blockDataAppendColInfo(SSDataBlock* pBlock, SColumnInfoData* pColInfoData) { + ASSERT(pBlock != NULL && pColInfoData != NULL); + if (pBlock->pDataBlock == NULL) { + pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + if (pBlock->pDataBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + } + + void* p = taosArrayPush(pBlock->pDataBlock, pColInfoData); + if (p == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + // todo disable it temporarily + // ASSERT(pColInfoData->info.type != 0); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + pBlock->info.hasVarCol = true; + } + + pBlock->info.rowSize += pColInfoData->info.bytes; + return TSDB_CODE_SUCCESS; +} + +SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId) { + SColumnInfoData col = {.hasNull = true}; + col.info.colId = colId; + col.info.type = type; + col.info.bytes = bytes; + + return col; +} + +SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index) { + ASSERT(pBlock != NULL); + if (index >= taosArrayGetSize(pBlock->pDataBlock)) { + return NULL; + } + + return taosArrayGet(pBlock->pDataBlock, index); +} + size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { - int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(pBlock->info.numOfCols); + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + int32_t payloadSize = pageSize - blockDataGetSerialMetaSize(numOfCols); int32_t rowSize = pBlock->info.rowSize; - int32_t nRows = payloadSize / rowSize; // the true value must be less than the value of nRows int32_t additional = 0; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i); if (IS_VAR_DATA_TYPE(pCol->info.type)) { additional += nRows * sizeof(int32_t); @@ -1346,7 +1424,8 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n) { if (pBlock->info.rows <= n) { blockDataCleanup(pBlock); } else { - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); colDataTrimFirstNRows(pColInfoData, n, pBlock->info.rows); } @@ -1358,7 +1437,7 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n) { int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { int64_t tbUid = pBlock->info.uid; - int16_t numOfCols = pBlock->info.numOfCols; + int16_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); int16_t hasVarCol = pBlock->info.hasVarCol; int32_t rows = pBlock->info.rows; int32_t sz = taosArrayGetSize(pBlock->pDataBlock); @@ -1393,8 +1472,10 @@ int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) { int32_t sz; - buf = taosDecodeFixedI64(buf, &pBlock->info.uid); - buf = taosDecodeFixedI16(buf, &pBlock->info.numOfCols); + int16_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + + buf = taosDecodeFixedU64(buf, &pBlock->info.uid); + buf = taosDecodeFixedI16(buf, &numOfCols); buf = taosDecodeFixedI16(buf, &pBlock->info.hasVarCol); buf = taosDecodeFixedI32(buf, &pBlock->info.rows); buf = taosDecodeFixedI32(buf, &sz); @@ -1503,12 +1584,13 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) { int32_t sz = taosArrayGetSize(dataBlocks); for (int32_t i = 0; i < sz; i++) { SSDataBlock* pDataBlock = taosArrayGet(dataBlocks, i); - int32_t colNum = pDataBlock->info.numOfCols; - int32_t rows = pDataBlock->info.rows; + size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); + + int32_t rows = pDataBlock->info.rows; printf("%s |block type %d |child id %d|\n", flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId); for (int32_t j = 0; j < rows; j++) { printf("%s |", flag); - for (int32_t k = 0; k < colNum; k++) { + for (int32_t k = 0; k < numOfCols; k++) { SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k); void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes); if (colDataIsNull(pColInfoData, rows, j, NULL)) { @@ -1561,7 +1643,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks int32_t bufSize = sizeof(SSubmitReq); for (int32_t i = 0; i < sz; ++i) { SDataBlockInfo* pBlkInfo = &((SSDataBlock*)taosArrayGet(pDataBlocks, i))->info; - bufSize += pBlkInfo->rows * (TD_ROW_HEAD_LEN + pBlkInfo->rowSize + BitmapLen(pBlkInfo->numOfCols)); + + int32_t numOfCols = taosArrayGetSize(pDataBlocks); + bufSize += pBlkInfo->rows * (TD_ROW_HEAD_LEN + pBlkInfo->rowSize + BitmapLen(numOfCols)); bufSize += sizeof(SSubmitBlk); } @@ -1579,10 +1663,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks for (int32_t i = 0; i < sz; ++i) { SSDataBlock* pDataBlock = taosArrayGet(pDataBlocks, i); - int32_t colNum = pDataBlock->info.numOfCols; + int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock); int32_t rows = pDataBlock->info.rows; - int32_t rowSize = pDataBlock->info.rowSize; - int64_t groupId = pDataBlock->info.groupId; + // int32_t rowSize = pDataBlock->info.rowSize; + // int64_t groupId = pDataBlock->info.groupId; if (colNum <= 1) { // invalid if only with TS col @@ -1800,8 +1884,6 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen } const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t numOfRows, const char* pData) { - blockDataEnsureCapacity(pBlock, numOfRows); - const char* pStart = pData; int32_t dataLen = *(int32_t*)pStart; @@ -1815,9 +1897,6 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t taosArraySetSize(pBlock->pDataBlock, numOfCols); } - pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock); - ASSERT(pBlock->pDataBlock->size >= numOfCols); - for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); pColInfoData->info.type = *(int16_t*)pStart; @@ -1842,28 +1921,26 @@ const char* blockCompressDecode(SSDataBlock* pBlock, int32_t numOfCols, int32_t SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - pColInfoData->varmeta.length = colLen[i]; - pColInfoData->varmeta.allocLen = colLen[i]; - memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows); pStart += sizeof(int32_t) * numOfRows; - if (colLen[i] > 0) { - taosMemoryFreeClear(pColInfoData->pData); - pColInfoData->pData = taosMemoryMalloc(colLen[i]); + if (colLen[i] > 0 && pColInfoData->varmeta.allocLen < colLen[i]) { + char* tmp = taosMemoryRealloc(pColInfoData->pData, colLen[i]); + if (tmp == NULL) { + return NULL; + } + + pColInfoData->pData = tmp; + pColInfoData->varmeta.allocLen = colLen[i]; } + + pColInfoData->varmeta.length = colLen[i]; } else { - if (pColInfoData->nullbitmap == NULL) { - pColInfoData->nullbitmap = taosMemoryCalloc(1, BitmapLen(numOfRows)); - } memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows)); pStart += BitmapLen(numOfRows); } if (colLen[i] > 0) { - if (pColInfoData->pData == NULL) { - pColInfoData->pData = taosMemoryCalloc(1, colLen[i]); - } memcpy(pColInfoData->pData, pStart, colLen[i]); } diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 1ddb606ccf..8460a27a0e 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -924,6 +924,18 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) { return n; } + +bool tTagIsJson(const void *pTag){ + return (((const STag *)pTag)->flags & TD_TAG_JSON); +} + +bool tTagIsJsonNull(void *data){ + STag *pTag = (STag*)data; + int8_t isJson = tTagIsJson(pTag); + if(!isJson) return false; + return ((STag*)data)->nTag == 0; +} + int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) { int32_t code = 0; uint8_t *p = NULL; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 269c92a670..e4bb30b001 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -187,6 +187,9 @@ bool tsStartUdfd = true; // internal int32_t tsTransPullupInterval = 2; int32_t tsMqRebalanceInterval = 2; +int32_t tsTtlUnit = 86400; +int32_t tsTtlPushInterval = 60; + void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary) { tstrncpy(tsDiskCfg[index].dir, v1, TSDB_FILENAME_LEN); @@ -467,6 +470,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "mqRebalanceInterval", tsMqRebalanceInterval, 1, 10000, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "ttlUnit", tsTtlUnit, 1, 86400*365, 1) != 0) return -1; + if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushInterval, 1, 10000, 1) != 0) return -1; if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1; return 0; @@ -619,6 +624,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32; tsMqRebalanceInterval = cfgGetItem(pCfg, "mqRebalanceInterval")->i32; + tsTtlUnit = cfgGetItem(pCfg, "ttlUnit")->i32; + tsTtlPushInterval = cfgGetItem(pCfg, "ttlPushInterval")->i32; tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; @@ -629,9 +636,376 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { return 0; } +int32_t taosSetCfg(SConfig *pCfg, char* name) { + int32_t len = strlen(name); + char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0}; + strntolower(lowcaseName, name, TMIN(CFG_NAME_MAX_LEN, len)); + + switch (lowcaseName[0]) { + case 'a': { + if (strcasecmp("asyncLog", name) == 0) { + tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval; + } + break; + } + case 'b': { + if (strcasecmp("bnodeShmSize", name) == 0) { + tsBnodeShmSize = cfgGetItem(pCfg, "bnodeShmSize")->i32; + } + break; + } + case 'c': { + if (strcasecmp("charset", name) == 0) { + const char *locale = cfgGetItem(pCfg, "locale")->str; + const char *charset = cfgGetItem(pCfg, "charset")->str; + taosSetSystemLocale(locale, charset); + osSetSystemLocale(locale, charset); + } else if (strcasecmp("compressMsgSize", name) == 0) { + tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32; + } else if (strcasecmp("compressColData", name) == 0) { + tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; + } else if (strcasecmp("countAlwaysReturnValue", name) == 0) { + tsCountAlwaysReturnValue = cfgGetItem(pCfg, "countAlwaysReturnValue")->i32; + } else if (strcasecmp("cDebugFlag", name) == 0) { + cDebugFlag = cfgGetItem(pCfg, "cDebugFlag")->i32; + } + break; + } + case 'd': { + if (strcasecmp("deadLockKillQuery", name) == 0) { + tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->i32; + } else if (strcasecmp("dDebugFlag", name) == 0) { + dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; + } + break; + } + case 'e': { + if (strcasecmp("enableCoreFile", name) == 0) { + bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; + taosSetConsoleEcho(enableCore); + } + break; + } + case 'f': { + if (strcasecmp("fqdn", name) == 0) { + tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); + tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); + + char defaultFirstEp[TSDB_EP_LEN] = {0}; + snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); + + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); + SEp firstEp = {0}; + taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); + snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); + cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype); + } else if (strcasecmp("firstEp", name) == 0) { + tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); + tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); + + char defaultFirstEp[TSDB_EP_LEN] = {0}; + snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); + + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); + SEp firstEp = {0}; + taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); + snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); + cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype); + } else if (strcasecmp("fsDebugFlag", name) == 0) { + fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32; + } else if (strcasecmp("fnDebugFlag", name) == 0) { + fnDebugFlag = cfgGetItem(pCfg, "fnDebugFlag")->i32; + } + break; + } + case 'i': { + if (strcasecmp("idxDebugFlag", name) == 0) { + idxDebugFlag = cfgGetItem(pCfg, "idxDebugFlag")->i32; + } + break; + } + case 'j': { + if (strcasecmp("jniDebugFlag", name) == 0) { + jniDebugFlag = cfgGetItem(pCfg, "jniDebugFlag")->i32; + } + break; + } + case 'k': { + if (strcasecmp("keepColumnName", name) == 0) { + tsKeepOriginalColumnName = cfgGetItem(pCfg, "keepColumnName")->bval; + } + break; + } + case 'l': { + if (strcasecmp("locale", name) == 0) { + const char *locale = cfgGetItem(pCfg, "locale")->str; + const char *charset = cfgGetItem(pCfg, "charset")->str; + taosSetSystemLocale(locale, charset); + osSetSystemLocale(locale, charset); + } else if (strcasecmp("logDir", name) == 0) { + tstrncpy(tsLogDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX); + taosExpandDir(tsLogDir, tsLogDir, PATH_MAX); + } else if (strcasecmp("logKeepDays", name) == 0) { + tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32; + } + break; + } + case 'm': { + switch (lowcaseName[1]) { + case 'a': { + if (strcasecmp("maxShellConns", name) == 0) { + tsMaxShellConns = cfgGetItem(pCfg, "maxShellConns")->i32; + } else if (strcasecmp("maxNumOfDistinctRes", name) == 0) { + tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32; + } else if (strcasecmp("maxStreamCompDelay", name) == 0) { + tsMaxStreamComputDelay = cfgGetItem(pCfg, "maxStreamCompDelay")->i32; + } else if (strcasecmp("maxFirstStreamCompDelay", name) == 0) { + tsStreamCompStartDelay = cfgGetItem(pCfg, "maxFirstStreamCompDelay")->i32; + } + break; + } + case 'd': { + if (strcasecmp("mDebugFlag", name) == 0) { + mDebugFlag = cfgGetItem(pCfg, "mDebugFlag")->i32; + } + break; + } + case 'i': { + if (strcasecmp("minimalTempDirGB", name) == 0) { + tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; + } else if (strcasecmp("minimalDataDirGB", name) == 0) { + tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval; + } else if (strcasecmp("minSlidingTime", name) == 0) { + tsMinSlidingTime = cfgGetItem(pCfg, "minSlidingTime")->i32; + } else if (strcasecmp("minIntervalTime", name) == 0) { + tsMinIntervalTime = cfgGetItem(pCfg, "minIntervalTime")->i32; + } else if (strcasecmp("minimalLogDirGB", name) == 0) { + tsLogSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval; + } + break; + } + case 'n': { + if (strcasecmp("mnodeShmSize", name) == 0) { + tsMnodeShmSize = cfgGetItem(pCfg, "mnodeShmSize")->i32; + } + break; + } + case 'o': { + if (strcasecmp("monitor", name) == 0) { + tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; + } else if (strcasecmp("monitorInterval", name) == 0) { + tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32; + } else if (strcasecmp("monitorFqdn", name) == 0) { + tstrncpy(tsMonitorFqdn, cfgGetItem(pCfg, "monitorFqdn")->str, TSDB_FQDN_LEN); + } else if (strcasecmp("monitorPort", name) == 0) { + tsMonitorPort = (uint16_t)cfgGetItem(pCfg, "monitorPort")->i32; + } else if (strcasecmp("monitorMaxLogs", name) == 0) { + tsMonitorMaxLogs = cfgGetItem(pCfg, "monitorMaxLogs")->i32; + } else if (strcasecmp("monitorComp", name) == 0) { + tsMonitorComp = cfgGetItem(pCfg, "monitorComp")->bval; + } + break; + } + case 'q': { + if (strcasecmp("mqRebalanceInterval", name) == 0) { + tsMqRebalanceInterval = cfgGetItem(pCfg, "mqRebalanceInterval")->i32; + } + break; + } + case 'u': { + if (strcasecmp("multiProcess", name) == 0) { + tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval; + } + break; + } + default: + terrno = TSDB_CODE_CFG_NOT_FOUND; + return -1; + } + break; + } + case 'n': { + if (strcasecmp("numOfTaskQueueThreads", name) == 0) { + tsNumOfTaskQueueThreads = cfgGetItem(pCfg, "numOfTaskQueueThreads")->i32; + } else if (strcasecmp("numOfRpcThreads", name) == 0) { + tsNumOfRpcThreads = cfgGetItem(pCfg, "numOfRpcThreads")->i32; + } else if (strcasecmp("numOfCommitThreads", name) == 0) { + tsNumOfCommitThreads = cfgGetItem(pCfg, "numOfCommitThreads")->i32; + } else if (strcasecmp("numOfMnodeQueryThreads", name) == 0) { + tsNumOfMnodeQueryThreads = cfgGetItem(pCfg, "numOfMnodeQueryThreads")->i32; + } else if (strcasecmp("numOfMnodeReadThreads", name) == 0) { + tsNumOfMnodeReadThreads = cfgGetItem(pCfg, "numOfMnodeReadThreads")->i32; + } else if (strcasecmp("numOfVnodeQueryThreads", name) == 0) { + tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32; + } else if (strcasecmp("numOfVnodeFetchThreads", name) == 0) { + tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; + } else if (strcasecmp("numOfVnodeWriteThreads", name) == 0) { + tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; + } else if (strcasecmp("numOfVnodeSyncThreads", name) == 0) { + tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; + } else if (strcasecmp("numOfVnodeMergeThreads", name) == 0) { + tsNumOfVnodeMergeThreads = cfgGetItem(pCfg, "numOfVnodeMergeThreads")->i32; + } else if (strcasecmp("numOfQnodeQueryThreads", name) == 0) { + tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; + } else if (strcasecmp("numOfQnodeFetchThreads", name) == 0) { + tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchThreads")->i32; + } else if (strcasecmp("numOfSnodeSharedThreads", name) == 0) { + tsNumOfSnodeSharedThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; + } else if (strcasecmp("numOfSnodeUniqueThreads", name) == 0) { + tsNumOfSnodeUniqueThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; + } else if (strcasecmp("numOfLogLines", name) == 0) { + tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; + } + break; + } + case 'p': { + if (strcasecmp("printAuth", name) == 0) { + tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval; + } + break; + } + case 'q': { + if (strcasecmp("queryPolicy", name) == 0) { + tsQueryPolicy = cfgGetItem(pCfg, "queryPolicy")->i32; + } else if (strcasecmp("querySmaOptimize", name) == 0) { + tsQuerySmaOptimize = cfgGetItem(pCfg, "querySmaOptimize")->i32; + } else if (strcasecmp("queryBufferSize", name) == 0) { + tsQueryBufferSize = cfgGetItem(pCfg, "queryBufferSize")->i32; + if (tsQueryBufferSize >= 0) { + tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; + } + } else if (strcasecmp("qnodeShmSize", name) == 0) { + tsQnodeShmSize = cfgGetItem(pCfg, "qnodeShmSize")->i32; + } else if (strcasecmp("qDebugFlag", name) == 0) { + qDebugFlag = cfgGetItem(pCfg, "qDebugFlag")->i32; + } + break; + } + case 'r': { + if (strcasecmp("retryStreamCompDelay", name) == 0) { + tsRetryStreamCompDelay = cfgGetItem(pCfg, "retryStreamCompDelay")->i32; + } else if (strcasecmp("retrieveBlockingModel", name) == 0) { + tsRetrieveBlockingModel = cfgGetItem(pCfg, "retrieveBlockingModel")->bval; + } else if (strcasecmp("rpcQueueMemoryAllowed", name) == 0) { + tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64; + } else if (strcasecmp("rpcDebugFlag", name) == 0) { + rpcDebugFlag = cfgGetItem(pCfg, "rpcDebugFlag")->i32; + } + break; + } + case 's': { + if (strcasecmp("secondEp", name) == 0) { + SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp"); + SEp secondEp = {0}; + taosGetFqdnPortFromEp(strlen(pSecondpItem->str) == 0 ? tsFirst : pSecondpItem->str, &secondEp); + snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port); + cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype); + } else if (strcasecmp("smlChildTableName", name) == 0) { + tstrncpy(tsSmlChildTableName, cfgGetItem(pCfg, "smlChildTableName")->str, TSDB_TABLE_NAME_LEN); + } else if (strcasecmp("smlTagName", name) == 0) { + tstrncpy(tsSmlTagName, cfgGetItem(pCfg, "smlTagName")->str, TSDB_COL_NAME_LEN); + } else if (strcasecmp("smlDataFormat", name) == 0) { + tsSmlDataFormat = cfgGetItem(pCfg, "smlDataFormat")->bval; + } else if (strcasecmp("shellActivityTimer", name) == 0) { + tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; + } else if (strcasecmp("supportVnodes", name) == 0) { + tsNumOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; + } else if (strcasecmp("statusInterval", name) == 0) { + tsStatusInterval = cfgGetItem(pCfg, "statusInterval")->i32; + } else if (strcasecmp("streamCompDelayRatio", name) == 0) { + tsStreamComputDelayRatio = cfgGetItem(pCfg, "streamCompDelayRatio")->fval; + } else if (strcasecmp("slaveQuery", name) == 0) { + tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval; + } else if (strcasecmp("snodeShmSize", name) == 0) { + tsSnodeShmSize = cfgGetItem(pCfg, "snodeShmSize")->i32; + } else if (strcasecmp("serverPort", name) == 0) { + tstrncpy(tsLocalFqdn, cfgGetItem(pCfg, "fqdn")->str, TSDB_FQDN_LEN); + tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); + + char defaultFirstEp[TSDB_EP_LEN] = {0}; + snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); + + SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp"); + SEp firstEp = {0}; + taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp); + snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port); + cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype); + } else if (strcasecmp("sDebugFlag", name) == 0) { + sDebugFlag = cfgGetItem(pCfg, "sDebugFlag")->i32; + } else if (strcasecmp("smaDebugFlag", name) == 0) { + smaDebugFlag = cfgGetItem(pCfg, "smaDebugFlag")->i32; + } + break; + } + case 't': { + if (strcasecmp("timezone", name) == 0) { + SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); + osSetTimezone(pItem->str); + uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr); + cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype); + } else if (strcasecmp("tempDir", name) == 0) { + tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); + taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); + if (taosMulMkDir(tsTempDir) != 0) { + uError("failed to create tempDir:%s since %s", tsTempDir, terrstr()); + return -1; + } + } else if (strcasecmp("telemetryReporting", name) == 0) { + tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; + } else if (strcasecmp("telemetryInterval", name) == 0) { + tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32; + } else if (strcasecmp("telemetryServer", name) == 0) { + tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN); + } else if (strcasecmp("telemetryPort", name) == 0) { + tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32; + } else if (strcasecmp("transPullupInterval", name) == 0) { + tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32; + } else if (strcasecmp("tmrDebugFlag", name) == 0) { + tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32; + } else if (strcasecmp("tsdbDebugFlag", name) == 0) { + tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32; + } else if (strcasecmp("tqDebugFlag", name) == 0) { + tqDebugFlag = cfgGetItem(pCfg, "tqDebugFlag")->i32; + } + break; + } + case 'u': { + if (strcasecmp("udf", name) == 0) { + tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; + } else if (strcasecmp("uDebugFlag", name) == 0) { + uDebugFlag = cfgGetItem(pCfg, "uDebugFlag")->i32; + } + break; + } + case 'v': { + if (strcasecmp("vnodeShmSize", name) == 0) { + tsVnodeShmSize = cfgGetItem(pCfg, "vnodeShmSize")->i32; + } else if (strcasecmp("vDebugFlag", name) == 0) { + vDebugFlag = cfgGetItem(pCfg, "vDebugFlag")->i32; + } + break; + } + case 'w': { + if (strcasecmp("wDebugFlag", name) == 0) { + wDebugFlag = cfgGetItem(pCfg, "wDebugFlag")->i32; + } + break; + } + default: + terrno = TSDB_CODE_CFG_NOT_FOUND; + return -1; + } + + return 0; +} + + int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { - osDefaultInit(); + if (tsCfg == NULL) osDefaultInit(); SConfig *pCfg = cfgInit(); if (pCfg == NULL) return -1; @@ -753,9 +1127,9 @@ void taosCleanupCfg() { } void taosCfgDynamicOptions(const char *option, const char *value) { - if (strcasecmp(option, "debugFlag") == 0) { - int32_t debugFlag = atoi(value); - taosSetAllDebugFlag(debugFlag); + if (strncasecmp(option, "debugFlag", 9) == 0) { + int32_t flag = atoi(value); + taosSetAllDebugFlag(flag); } if (strcasecmp(option, "resetlog") == 0) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a8f8ad00e1..dde282c4e3 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -539,7 +539,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq const char *pFunc = taosArrayGet(pReq->pFuncs, i); if (tEncodeCStr(&encoder, pFunc) < 0) return -1; } - + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -621,7 +621,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR if (NULL == pReq->pFuncs) return -1; } for (int32_t i = 0; i < numOfFuncs; ++i) { - char* pFunc = NULL; + char *pFunc = NULL; if (tDecodeCStrAlloc(&decoder, &pFunc) < 0) return -1; if (taosArrayPush(pReq->pFuncs, pFunc) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -783,6 +783,8 @@ int32_t tSerializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pReq if (tEncodeI64(&encoder, pReq->interval) < 0) return -1; if (tEncodeI64(&encoder, pReq->offset) < 0) return -1; if (tEncodeI64(&encoder, pReq->sliding) < 0) return -1; + if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1; + if (tEncodeI64(&encoder, pReq->maxDelay) < 0) return -1; if (tEncodeI32(&encoder, pReq->exprLen) < 0) return -1; if (tEncodeI32(&encoder, pReq->tagsFilterLen) < 0) return -1; if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1; @@ -821,6 +823,8 @@ int32_t tDeserializeSMCreateSmaReq(void *buf, int32_t bufLen, SMCreateSmaReq *pR if (tDecodeI64(&decoder, &pReq->interval) < 0) return -1; if (tDecodeI64(&decoder, &pReq->offset) < 0) return -1; if (tDecodeI64(&decoder, &pReq->sliding) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->watermark) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->maxDelay) < 0) return -1; if (tDecodeI32(&decoder, &pReq->exprLen) < 0) return -1; if (tDecodeI32(&decoder, &pReq->tagsFilterLen) < 0) return -1; if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1; @@ -1500,6 +1504,33 @@ int32_t tDeserializeSMCfgDnodeReq(void *buf, int32_t bufLen, SMCfgDnodeReq *pReq return 0; } +int32_t tSerializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->config) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->value) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDCfgDnodeReq(void *buf, int32_t bufLen, SDCfgDnodeReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->config) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->value) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + int32_t tSerializeSCreateDnodeReq(void *buf, int32_t bufLen, SCreateDnodeReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -1841,7 +1872,7 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { if (tEncodeI64(&encoder, pRsp->watermark1) < 0) return -1; if (tEncodeI64(&encoder, pRsp->watermark2) < 0) return -1; if (tEncodeI32(&encoder, pRsp->ttl) < 0) return -1; - + int32_t numOfFuncs = taosArrayGetSize(pRsp->pFuncs); if (tEncodeI32(&encoder, numOfFuncs) < 0) return -1; for (int32_t i = 0; i < numOfFuncs; ++i) { @@ -1849,19 +1880,19 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { if (tEncodeCStr(&encoder, pFunc) < 0) return -1; } - if (tEncodeI32(&encoder, pRsp->commentLen) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->commentLen) < 0) return -1; if (pRsp->commentLen > 0) { if (tEncodeCStr(&encoder, pRsp->pComment) < 0) return -1; } - + for (int32_t i = 0; i < pRsp->numOfColumns + pRsp->numOfTags; ++i) { SSchema *pSchema = &pRsp->pSchemas[i]; if (tEncodeSSchema(&encoder, pSchema) < 0) return -1; } - if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; - if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1; - + if (tEncodeI32(&encoder, pRsp->tagsLen) < 0) return -1; + if (tEncodeBinary(&encoder, pRsp->pTags, pRsp->tagsLen) < 0) return -1; + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1918,7 +1949,7 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) } if (tDecodeI32(&decoder, &pRsp->tagsLen) < 0) return -1; - if (tDecodeBinaryAlloc(&decoder, (void**)&pRsp->pTags, NULL) < 0) return -1; + if (tDecodeBinaryAlloc(&decoder, (void **)&pRsp->pTags, NULL) < 0) return -1; tEndDecode(&decoder); @@ -1934,7 +1965,7 @@ void tFreeSTableCfgRsp(STableCfgRsp *pRsp) { taosMemoryFreeClear(pRsp->pComment); taosMemoryFreeClear(pRsp->pSchemas); taosMemoryFreeClear(pRsp->pTags); - + taosArrayDestroy(pRsp->pFuncs); } @@ -2194,6 +2225,32 @@ int32_t tDeserializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq return 0; } +int32_t tSerializeSDnodeListReq(void *buf, int32_t bufLen, SDnodeListReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->rowNum) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDnodeListReq(void *buf, int32_t bufLen, SDnodeListReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->rowNum) < 0) return -1; + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + + int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -2237,6 +2294,50 @@ int32_t tDeserializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp void tFreeSQnodeListRsp(SQnodeListRsp *pRsp) { taosArrayDestroy(pRsp->qnodeList); } +int32_t tSerializeSDnodeListRsp(void *buf, int32_t bufLen, SDnodeListRsp *pRsp) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + int32_t num = taosArrayGetSize(pRsp->dnodeList); + if (tEncodeI32(&encoder, num) < 0) return -1; + for (int32_t i = 0; i < num; ++i) { + SEpSet *pEpSet = taosArrayGet(pRsp->dnodeList, i); + if (tEncodeSEpSet(&encoder, pEpSet) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDnodeListRsp(void *buf, int32_t bufLen, SDnodeListRsp *pRsp) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + int32_t num = 0; + if (tDecodeI32(&decoder, &num) < 0) return -1; + if (NULL == pRsp->dnodeList) { + pRsp->dnodeList = taosArrayInit(num, sizeof(SEpSet)); + if (NULL == pRsp->dnodeList) return -1; + } + + for (int32_t i = 0; i < num; ++i) { + SEpSet epSet = {0}; + if (tDecodeSEpSet(&decoder, &epSet) < 0) return -1; + taosArrayPush(pRsp->dnodeList, &epSet); + } + tEndDecode(&decoder); + + tDecoderClear(&decoder); + return 0; +} + +void tFreeSDnodeListRsp(SDnodeListRsp *pRsp) { taosArrayDestroy(pRsp->dnodeList); } + + int32_t tSerializeSCompactDbReq(void *buf, int32_t bufLen, SCompactDbReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -2733,6 +2834,31 @@ void tFreeSTableIndexInfo(void *info) { taosMemoryFree(pInfo->expr); } +int32_t tSerializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) { + SEncoder encoder = {0}; + tEncoderInit(&encoder, buf, bufLen); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pReq->useless) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tEncoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) { + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->useless) < 0) return -1; + + tEndDecode(&decoder); + tDecoderClear(&decoder); + return 0; +} + int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); diff --git a/source/common/src/tname.c b/source/common/src/tname.c index ce454d439d..fb3a2d7464 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -214,6 +214,20 @@ int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t name return 0; } +int32_t tNameAddTbName(SName* dst, const char* tbName, size_t nameLen) { + assert(dst != NULL && tbName != NULL && nameLen > 0); + + // too long account id or too long db name + if (nameLen >= tListLen(dst->tname) || nameLen <= 0) { + return -1; + } + + dst->type = TSDB_TABLE_NAME_T; + tstrncpy(dst->tname, tbName, nameLen + 1); + return 0; +} + + int32_t tNameSetAcctId(SName* dst, int32_t acctId) { assert(dst != NULL); dst->acctId = acctId; diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 0b59e9b6cc..8fbdeb0654 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -76,22 +76,28 @@ void deltaToUtcInitOnce() { static int64_t parseFraction(char* str, char** end, int32_t timePrec); static int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, char delim); -static int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec); -static int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec); +static int32_t parseLocaltime(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim); +static int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim); static char* forwardToTimeStringEnd(char* str); static bool checkTzPresent(const char* str, int32_t len); -static int32_t (*parseLocaltimeFp[])(char* timestr, int32_t len, int64_t* utime, int32_t timePrec) = {parseLocaltime, - parseLocaltimeDst}; +static int32_t (*parseLocaltimeFp[])(char* timestr, int32_t len, int64_t* utime, int32_t timePrec, char delim) = {parseLocaltime, + parseLocaltimeDst}; int32_t taosParseTime(const char* timestr, int64_t* utime, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ if (strnchr(timestr, 'T', len, false) != NULL) { - return parseTimeWithTz(timestr, utime, timePrec, 'T'); - } else if (checkTzPresent(timestr, len)) { - return parseTimeWithTz(timestr, utime, timePrec, 0); + if (checkTzPresent(timestr, len)) { + return parseTimeWithTz(timestr, utime, timePrec, 'T'); + } else { + return (*parseLocaltimeFp[day_light])((char*)timestr, len, utime, timePrec, 'T'); + } } else { - return (*parseLocaltimeFp[day_light])((char*)timestr, len, utime, timePrec); + if (checkTzPresent(timestr, len)) { + return parseTimeWithTz(timestr, utime, timePrec, 0); + } else { + return (*parseLocaltimeFp[day_light])((char*)timestr, len, utime, timePrec, 0); + } } } @@ -333,13 +339,25 @@ static FORCE_INLINE bool validateTm(struct tm* pTm) { return true; } -int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePrec) { +int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) { *time = 0; struct tm tm = {0}; - char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + char *str; + if (delim == 'T') { + str = taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); + } else if (delim == 0) { + str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + } else { + str = NULL; + } + if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { - return -1; + //if parse failed, try "%Y-%m-%d" format + str = taosStrpTime(timestr, "%Y-%m-%d", &tm); + if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { + return -1; + } } #ifdef _MSC_VER @@ -367,14 +385,26 @@ int32_t parseLocaltime(char* timestr, int32_t len, int64_t* time, int32_t timePr return 0; } -int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t timePrec) { +int32_t parseLocaltimeDst(char* timestr, int32_t len, int64_t* time, int32_t timePrec, char delim) { *time = 0; struct tm tm = {0}; tm.tm_isdst = -1; - char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + char *str; + if (delim == 'T') { + str = taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); + } else if (delim == 0) { + str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm); + } else { + str = NULL; + } + if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { - return -1; + //if parse failed, try "%Y-%m-%d" format + str = taosStrpTime(timestr, "%Y-%m-%d", &tm); + if (str == NULL || (((str - timestr) < len) && (*str != '.')) || !validateTm(&tm)) { + return -1; + } } /* mktime will be affected by TZ, set by using taos_options */ diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index 2adb558d01..8460d71e56 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -88,26 +88,15 @@ TEST(testCase, toInteger_test) { } TEST(testCase, Datablock_test) { - SSDataBlock* b = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); - b->info.numOfCols = 2; - b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + SSDataBlock* b = createDataBlock(); - SColumnInfoData infoData = {0}; - infoData.info.bytes = 4; - infoData.info.type = TSDB_DATA_TYPE_INT; - infoData.info.colId = 1; - - infoData.pData = (char*)taosMemoryCalloc(40, infoData.info.bytes); - infoData.nullbitmap = (char*)taosMemoryCalloc(1, sizeof(char) * (40 / 8)); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, 4, 1); taosArrayPush(b->pDataBlock, &infoData); + blockDataAppendColInfo(b, &infoData); - SColumnInfoData infoData1 = {0}; - infoData1.info.bytes = 40; - infoData1.info.type = TSDB_DATA_TYPE_BINARY; - infoData1.info.colId = 2; - - infoData1.varmeta.offset = (int32_t*)taosMemoryCalloc(40, sizeof(uint32_t)); - taosArrayPush(b->pDataBlock, &infoData1); + SColumnInfoData infoData1 = createColumnInfoData(TSDB_DATA_TYPE_BINARY, 40, 2); + blockDataAppendColInfo(b, &infoData1); + blockDataEnsureCapacity(b, 40); char* str = "the value of: %d"; char buf[128] = {0}; @@ -222,28 +211,17 @@ TEST(testCase, non_var_dataBlock_split_test) { #endif TEST(testCase, var_dataBlock_split_test) { - SSDataBlock* b = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); - b->info.numOfCols = 2; - b->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); - int32_t numOfRows = 1000000; - SColumnInfoData infoData = {0}; - infoData.info.bytes = 4; - infoData.info.type = TSDB_DATA_TYPE_INT; - infoData.info.colId = 1; + SSDataBlock* b = createDataBlock(); - infoData.pData = (char*)taosMemoryCalloc(numOfRows, infoData.info.bytes); - infoData.nullbitmap = (char*)taosMemoryCalloc(1, sizeof(char) * (numOfRows / 8)); - taosArrayPush(b->pDataBlock, &infoData); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, 4, 1); + blockDataAppendColInfo(b, &infoData); - SColumnInfoData infoData1 = {0}; - infoData1.info.bytes = 40; - infoData1.info.type = TSDB_DATA_TYPE_BINARY; - infoData1.info.colId = 2; + SColumnInfoData infoData1 = createColumnInfoData(TSDB_DATA_TYPE_BINARY, 40, 2); + blockDataAppendColInfo(b, &infoData1); - infoData1.varmeta.offset = (int32_t*)taosMemoryCalloc(numOfRows, sizeof(uint32_t)); - taosArrayPush(b->pDataBlock, &infoData1); + blockDataEnsureCapacity(b, numOfRows); char buf[41] = {0}; char buf1[100] = {0}; diff --git a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h index ee811c0071..4479c06bea 100644 --- a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h +++ b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h @@ -45,6 +45,7 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); // dmWorker.c int32_t dmPutNodeMsgToMgmtQueue(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 3e55469a4a..3d1ece0b64 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -15,6 +15,10 @@ #define _DEFAULT_SOURCE #include "dmInt.h" +#include "systable.h" + + +extern SConfig *tsCfg; static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { if (pMgmt->pData->dnodeId == 0 || pMgmt->pData->clusterId == 0) { @@ -119,8 +123,15 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { - dError("config req is received, but not supported yet"); - return TSDB_CODE_OPS_NOT_SUPPORT; + SDCfgDnodeReq cfgReq = {0}; + if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value); + taosCfgDynamicOptions(cfgReq.config, cfgReq.value); + return 0; } static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) { @@ -175,6 +186,130 @@ int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { return 0; } +SSDataBlock* dmBuildVariablesBlock(void) { + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + size_t size = 0; + const SSysTableMeta* pMeta = NULL; + getInfosDbMeta(&pMeta, &size); + + int32_t index = 0; + for (int32_t i = 0; i < size; ++i) { + if (strcmp(pMeta[i].name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) { + index = i; + break; + } + } + + pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData)); + + for (int32_t i = 0; i < pMeta[index].colNum; ++i) { + SColumnInfoData colInfoData = {0}; + colInfoData.info.colId = i + 1; + colInfoData.info.type = pMeta[index].schema[i].type; + colInfoData.info.bytes = pMeta[index].schema[i].bytes; + taosArrayPush(pBlock->pDataBlock, &colInfoData); + } + + pBlock->info.hasVarCol = true; + + return pBlock; +} + +int32_t dmAppendVariablesToBlock(SSDataBlock* pBlock, int32_t dnodeId) { + int32_t numOfCfg = taosArrayGetSize(tsCfg->array); + int32_t numOfRows = 0; + blockDataEnsureCapacity(pBlock, numOfCfg); + + for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { + SConfigItem *pItem = taosArrayGet(tsCfg->array, i); + + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + colDataAppend(pColInfo, i, (const char *)&dnodeId, false); + + char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); + pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + colDataAppend(pColInfo, i, name, false); + + char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; + int32_t valueLen = 0; + cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen); + varDataSetLen(value, valueLen); + pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + colDataAppend(pColInfo, i, value, false); + + numOfRows++; + } + + + pBlock->info.rows = numOfRows; + + return TSDB_CODE_SUCCESS; +} + + + +int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { + int32_t size = 0; + int32_t rowsRead = 0; + + SRetrieveTableReq retrieveReq = {0}; + if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + SSDataBlock* pBlock = dmBuildVariablesBlock(); + + dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId); + + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols + + blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(numOfCols); + + SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + dError("failed to retrieve data since %s", terrstr()); + blockDataDestroy(pBlock); + return -1; + } + + char *pStart = pRsp->data; + *(int32_t *)pStart = htonl(numOfCols); + pStart += sizeof(int32_t); // number of columns + + for (int32_t i = 0; i < numOfCols; ++i) { + SSysTableSchema *pSchema = (SSysTableSchema *)pStart; + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, i); + + pSchema->bytes = htonl(pColInfo->info.bytes); + pSchema->colId = htons(pColInfo->info.colId); + pSchema->type = pColInfo->info.type; + + pStart += sizeof(SSysTableSchema); + } + + int32_t len = 0; + blockCompressEncode(pBlock, pStart, &len, numOfCols, false); + + pRsp->numOfRows = htonl(pBlock->info.rows); + pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision + pRsp->completed = 1; + pMsg->info.rsp = pRsp; + pMsg->info.rspLen = size; + dDebug("dnode variables retrieve completed"); + + blockDataDestroy(pBlock); + return TSDB_CODE_SUCCESS; +} + + SArray *dmGetMsgHandles() { int32_t code = -1; SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle)); @@ -191,6 +326,7 @@ SArray *dmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_BNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; // Requests handled by MNODE if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 9ffa0e606a..89e8aa976e 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -141,6 +141,9 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { case TDMT_DND_SERVER_STATUS: code = dmProcessServerRunStatus(pMgmt, pMsg); break; + case TDMT_DND_SYSTABLE_RETRIEVE: + code = dmProcessRetrieve(pMgmt, pMsg); + break; default: terrno = TSDB_CODE_MSG_NOT_PROCESSED; break; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 474e6ab378..f9c54674f3 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -17,7 +17,7 @@ #include "mmInt.h" void mmGetMonitorInfo(SMnodeMgmt *pMgmt, SMonMmInfo *pInfo) { - mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->grant); + mndGetMonitorInfo(pMgmt->pMnode, &pInfo->cluster, &pInfo->vgroup, &pInfo->stb, &pInfo->grant); } int32_t mmProcessGetMonitorInfoReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { @@ -161,6 +161,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_QNODE_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_DNODE_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_SNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_BNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index e1ffc3bdb7..7cb41ca77c 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -101,6 +101,8 @@ SArray *smGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; code = 0; _OVER: diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index d9502ec8f3..00d83f0ad4 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -359,6 +359,8 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 71bbc8ddd4..5e1ef23f1c 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -28,10 +28,10 @@ static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) { } static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SVnodeMgmt *pMgmt = pInfo->ahandle; - int32_t code = -1; + SVnodeMgmt *pMgmt = pInfo->ahandle; + int32_t code = -1; + const STraceId *trace = &pMsg->info.traceId; - STraceId *trace = &pMsg->info.traceId; dGTrace("msg:%p, get from vnode-mgmt queue", pMsg); switch (pMsg->msgType) { case TDMT_MON_VM_INFO: @@ -48,50 +48,52 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { break; default: terrno = TSDB_CODE_MSG_NOT_PROCESSED; - dError("msg:%p, not processed in vnode-mgmt queue", pMsg); + dGError("msg:%p, not processed in vnode-mgmt queue", pMsg); } if (IsReq(pMsg)) { if (code != 0) { if (terrno != 0) code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); + dGError("msg:%p, failed to process since %s", pMsg, terrstr()); } vmSendRsp(pMsg, code); } - dTrace("msg:%p, is freed, code:0x%x", pMsg, code); + dGTrace("msg:%p, is freed, code:0x%x", pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SVnodeObj *pVnode = pInfo->ahandle; + SVnodeObj *pVnode = pInfo->ahandle; + const STraceId *trace = &pMsg->info.traceId; - dTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p get from vnode-query queue", pVnode->vgId, pMsg); int32_t code = vnodeProcessQueryMsg(pVnode->pImpl, pMsg); if (code != 0) { if (terrno != 0) code = terrno; - dError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, terrstr()); + dGError("vgId:%d, msg:%p failed to query since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } - dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); + dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SVnodeObj *pVnode = pInfo->ahandle; + SVnodeObj *pVnode = pInfo->ahandle; + const STraceId *trace = &pMsg->info.traceId; - dTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p get from vnode-fetch queue", pVnode->vgId, pMsg); int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); if (code != 0) { if (terrno != 0) code = terrno; - dError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr()); + dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } - dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); + dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } @@ -102,16 +104,17 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf for (int32_t i = 0; i < numOfMsgs; ++i) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - dTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg); + const STraceId *trace = &pMsg->info.traceId; + dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg); int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL); if (code != 0) { if (terrno != 0) code = terrno; - dError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr()); + dGError("vgId:%d, msg:%p failed to sync since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } - dTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); + dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } @@ -123,55 +126,57 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO for (int32_t i = 0; i < numOfMsgs; ++i) { if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - dTrace("vgId:%d, msg:%p get from vnode-merge queue", pVnode->vgId, pMsg); + const STraceId *trace = &pMsg->info.traceId; + dGTrace("vgId:%d, msg:%p get from vnode-merge queue", pVnode->vgId, pMsg); int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); if (code != 0) { if (terrno != 0) code = terrno; - dError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr()); + dGError("vgId:%d, msg:%p failed to merge since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } - dTrace("msg:%p, is freed, code:0x%x", pMsg, code); + dGTrace("msg:%p, is freed, code:0x%x", pMsg, code); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); } } static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) { - SMsgHead *pHead = pMsg->pCont; - int32_t code = 0; + const STraceId *trace = &pMsg->info.traceId; + SMsgHead *pHead = pMsg->pCont; + int32_t code = 0; pHead->contLen = ntohl(pHead->contLen); pHead->vgId = ntohl(pHead->vgId); SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) { - dError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(), - TMSG_INFO(pMsg->msgType)); + dGError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s", pHead->vgId, pMsg, terrstr(), + TMSG_INFO(pMsg->msgType)); return terrno != 0 ? terrno : -1; } switch (qtype) { case QUERY_QUEUE: vnodePreprocessQueryMsg(pVnode->pImpl, pMsg); - dTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pQueryQ, pMsg); break; case FETCH_QUEUE: - dTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pFetchQ, pMsg); break; case WRITE_QUEUE: - dTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pWriteQ, pMsg); break; case SYNC_QUEUE: - dTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pSyncQ, pMsg); break; case APPLY_QUEUE: - dTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg); + dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pApplyQ, pMsg); break; default: @@ -193,13 +198,15 @@ int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsg int32_t vmPutMsgToFetchQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, FETCH_QUEUE); } int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { - dTrace("msg:%p, put into vnode-mgmt queue", pMsg); + const STraceId *trace = &pMsg->info.traceId; + dGTrace("msg:%p, put into vnode-mgmt queue", pMsg); taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg); return 0; } int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { - dTrace("msg:%p, put into vnode-monitor queue", pMsg); + const STraceId *trace = &pMsg->info.traceId; + dGTrace("msg:%p, put into vnode-monitor queue", pMsg); taosWriteQitem(pMgmt->monitorWorker.queue, pMsg); return 0; } diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 4761e3dc36..63d2a65df1 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -85,6 +85,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { dmProcessNetTestReq(pDnode, pRpc); return; case TDMT_MND_SYSTABLE_RETRIEVE_RSP: + case TDMT_DND_SYSTABLE_RETRIEVE_RSP: case TDMT_VND_FETCH_RSP: qWorkerProcessFetchRsp(NULL, NULL, pRpc, 0); return; diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index f599de384c..01958aa053 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -44,6 +44,7 @@ extern "C" { #endif + // clang-format off #define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 78e706f908..2185adc18b 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -127,14 +127,24 @@ TdFilePtr dmCheckRunning(const char *dataDir) { return NULL; } - int32_t ret = taosLockFile(pFile); - if (ret != 0) { + int32_t retryTimes = 0; + int32_t ret = 0; + do { + ret = taosLockFile(pFile); + if (ret == 0) break; + terrno = TAOS_SYSTEM_ERROR(errno); + taosMsleep(100); + retryTimes++; + dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes); + } while (retryTimes < 120); + + if (ret < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to lock file:%s since %s", filepath, terrstr()); taosCloseFile(&pFile); return NULL; } + terrno = 0; dDebug("lock file:%s to prevent repeated starts", filepath); return pFile; } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 958d82a75d..58266724a5 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -35,6 +35,7 @@ extern "C" { // clang-format off + #define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} #define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} #define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} @@ -77,7 +78,7 @@ typedef struct { typedef struct { SCacheObj *connCache; - SCacheObj *appCache; + SCacheObj *appCache; } SProfileMgmt; typedef struct { diff --git a/source/dnode/mnode/impl/inc/mndQnode.h b/source/dnode/mnode/impl/inc/mndQnode.h index 3e38565a4f..17615500c4 100644 --- a/source/dnode/mnode/impl/inc/mndQnode.h +++ b/source/dnode/mnode/impl/inc/mndQnode.h @@ -24,12 +24,12 @@ extern "C" { #define QNODE_LOAD_VALUE(pQnode) (pQnode ? (pQnode->load.numOfQueryInQueue + pQnode->load.numOfFetchInQueue) : 0) -int32_t mndInitQnode(SMnode *pMnode); -void mndCleanupQnode(SMnode *pMnode); - +int32_t mndInitQnode(SMnode *pMnode); +void mndCleanupQnode(SMnode *pMnode); SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId); -void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj); -int32_t mndCreateQnodeList(SMnode *pMnode, SArray** pList, int32_t limit); +void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj); +int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit); +int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 15d2c6cd5e..db81d8843e 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -27,12 +27,10 @@ void mndCleanupScheduler(SMnode* pMnode); int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub); -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); - int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType, int64_t watermark); -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); +int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSnode.h b/source/dnode/mnode/impl/inc/mndSnode.h index 180f18a6dd..ec7bb02ca7 100644 --- a/source/dnode/mnode/impl/inc/mndSnode.h +++ b/source/dnode/mnode/impl/inc/mndSnode.h @@ -22,9 +22,12 @@ extern "C" { #endif -int32_t mndInitSnode(SMnode *pMnode); -void mndCleanupSnode(SMnode *pMnode); -SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode); +int32_t mndInitSnode(SMnode *pMnode); +void mndCleanupSnode(SMnode *pMnode); +SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t qnodeId); +void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj); +SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode); +int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 58c3570c36..d3723326b9 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -19,6 +19,7 @@ #include "mndMnode.h" #include "mndQnode.h" #include "mndShow.h" +#include "mndSnode.h" #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" @@ -46,6 +47,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw); static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode); static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode); static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew); +static int32_t mndProcessDnodeListReq(SRpcMsg *pReq); static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq); static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq); @@ -75,6 +77,7 @@ int32_t mndInitDnode(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq); mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp); mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq); + mndSetMsgHandle(pMnode, TDMT_MND_DNODE_LIST, mndProcessDnodeListReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig); @@ -370,7 +373,8 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id); if (pObj != NULL) { if (pObj->state != statusReq.mload.syncState) { - mInfo("dnode:%d, mnode syncstate from %s to %s", pObj->id, syncStr(pObj->state), syncStr(statusReq.mload.syncState)); + mInfo("dnode:%d, mnode syncstate from %s to %s", pObj->id, syncStr(pObj->state), + syncStr(statusReq.mload.syncState)); pObj->state = statusReq.mload.syncState; pObj->stateStartTime = taosGetTimestampMs(); } @@ -497,6 +501,59 @@ _OVER: return code; } +static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SSdb *pSdb = pMnode->pSdb; + SDnodeObj *pObj = NULL; + void *pIter = NULL; + SDnodeListRsp rsp = {0}; + int32_t code = -1; + + rsp.dnodeList = taosArrayInit(5, sizeof(SEpSet)); + if (NULL == rsp.dnodeList) { + mError("failed to alloc epSet while process dnode list req"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + while (1) { + pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj); + if (pIter == NULL) break; + + SEpSet epSet = {0}; + epSet.numOfEps = 1; + tstrncpy(epSet.eps[0].fqdn, pObj->fqdn, TSDB_FQDN_LEN); + epSet.eps[0].port = pObj->port; + + (void)taosArrayPush(rsp.dnodeList, &epSet); + + sdbRelease(pSdb, pObj); + } + + int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &rsp); + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + tSerializeSDnodeListRsp(pRsp, rspLen, &rsp); + + pReq->info.rspLen = rspLen; + pReq->info.rsp = pRsp; + code = 0; + +_OVER: + + if (code != 0) { + mError("failed to get dnode list since %s", terrstr()); + } + + tFreeSDnodeListRsp(&rsp); + + return code; +} + static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; @@ -508,7 +565,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) { goto _OVER; } - mDebug("dnode:%s:%d, start to create", createReq.fqdn, createReq.port); + mInfo("dnode:%s:%d, start to create", createReq.fqdn, createReq.port); if (createReq.fqdn[0] == 0 || createReq.port <= 0 || createReq.port > UINT16_MAX) { terrno = TSDB_CODE_MND_INVALID_DNODE_EP; @@ -538,7 +595,8 @@ _OVER: return code; } -static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, int32_t numOfVnodes) { +static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, SQnodeObj *pQObj, + SSnodeObj *pSObj, int32_t numOfVnodes) { int32_t code = -1; SSdbRaw *pRaw = NULL; STrans *pTrans = NULL; @@ -546,7 +604,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq); if (pTrans == NULL) goto _OVER; mndTransSetSerial(pTrans); - mDebug("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id); + mInfo("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id); pRaw = mndDnodeActionEncode(pDnode); if (pRaw == NULL || mndTransAppendRedolog(pTrans, pRaw) != 0) goto _OVER; @@ -559,13 +617,25 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM pRaw = NULL; if (pMObj != NULL) { - mDebug("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id); + mInfo("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id); if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER; } + + if (pQObj != NULL) { + mInfo("trans:%d, qnode on dnode:%d will be dropped", pTrans->id, pDnode->id); + if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj) != 0) goto _OVER; + } + + if (pSObj != NULL) { + mInfo("trans:%d, snode on dnode:%d will be dropped", pTrans->id, pDnode->id); + if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj) != 0) goto _OVER; + } + if (numOfVnodes > 0) { - mDebug("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id); + mInfo("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id); if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER; } + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -577,30 +647,34 @@ _OVER: } static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { - SMnode *pMnode = pReq->info.node; - int32_t code = -1; - SDnodeObj *pDnode = NULL; - SMnodeObj *pMObj = NULL; - SMDropMnodeReq dropReq = {0}; + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + SDnodeObj *pDnode = NULL; + SMnodeObj *pMObj = NULL; + SQnodeObj *pQObj = NULL; + SSnodeObj *pSObj = NULL; + SDropDnodeReq dropReq = {0}; - if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { + if (tDeserializeSDropDnodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { terrno = TSDB_CODE_INVALID_MSG; goto _OVER; } - mDebug("dnode:%d, start to drop", dropReq.dnodeId); - - if (dropReq.dnodeId <= 0) { - terrno = TSDB_CODE_MND_INVALID_DNODE_ID; - goto _OVER; - } + mInfo("dnode:%d, start to drop, ep:%s:%d", dropReq.dnodeId, dropReq.fqdn, dropReq.port); pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId); if (pDnode == NULL) { - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - goto _OVER; + char ep[TSDB_EP_LEN + 1] = {0}; + snprintf(ep, sizeof(ep), dropReq.fqdn, dropReq.port); + pDnode = mndAcquireDnodeByEp(pMnode, ep); + if (pDnode == NULL) { + terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + goto _OVER; + } } + pQObj = mndAcquireQnode(pMnode, dropReq.dnodeId); + pSObj = mndAcquireSnode(pMnode, dropReq.dnodeId); pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId); if (pMObj != NULL) { if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) { @@ -627,7 +701,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { goto _OVER; } - code = mndDropDnode(pMnode, pReq, pDnode, pMObj, numOfVnodes); + code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: @@ -637,6 +711,8 @@ _OVER: mndReleaseDnode(pMnode, pDnode); mndReleaseMnode(pMnode, pMObj); + mndReleaseQnode(pMnode, pQObj); + mndReleaseSnode(pMnode, pSObj); return code; } @@ -649,23 +725,46 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { return -1; } + mInfo("dnode:%d, start to config, option:%s, value:%s", cfgReq.dnodeId, cfgReq.config, cfgReq.value); SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId); if (pDnode == NULL) { mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr()); return -1; } - SEpSet epSet = mndGetDnodeEpset(pDnode); mndReleaseDnode(pMnode, pDnode); - int32_t bufLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq); + SDCfgDnodeReq dcfgReq = {0}; + if (strncasecmp(cfgReq.config, "debugFlag", 9) == 0) { + const char *value = cfgReq.value; + int32_t flag = atoi(value); + if (flag <= 0) { + flag = atoi(cfgReq.config + 10); + } + if (flag <= 0 || flag > 255) { + mError("dnode:%d, failed to config debugFlag since value:%d", cfgReq.dnodeId, flag); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + + strcpy(dcfgReq.config, "debugFlag"); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); + } else if (strcasecmp(cfgReq.config, "resetlog") == 0) { + strcpy(dcfgReq.config, "resetlog"); + } else { + terrno = TSDB_CODE_INVALID_CFG; + mError("dnode:%d, failed to config since %s", cfgReq.dnodeId, terrstr()); + return -1; + } + + int32_t bufLen = tSerializeSDCfgDnodeReq(NULL, 0, &dcfgReq); void *pBuf = rpcMallocCont(bufLen); if (pBuf == NULL) return -1; - tSerializeSMCfgDnodeReq(pBuf, bufLen, &cfgReq); + tSerializeSDCfgDnodeReq(pBuf, bufLen, &dcfgReq); mDebug("dnode:%d, send config req to dnode, app:%p", cfgReq.dnodeId, pReq->info.ahandle); - SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen, .info = pReq->info}; + SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen}; return tmsgSendReq(&epSet, &rpcMsg); } @@ -679,28 +778,28 @@ static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p int32_t totalRows = 0; int32_t numOfRows = 0; char *cfgOpts[TSDB_CONFIG_NUMBER] = {0}; - char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0}; + char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONFIG_VALUE_LEN + 1] = {0}; char *pWrite = NULL; int32_t cols = 0; cfgOpts[totalRows] = "statusInterval"; - snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%d", tsStatusInterval); + snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval); totalRows++; cfgOpts[totalRows] = "timezone"; - snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr); + snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsTimezoneStr); totalRows++; cfgOpts[totalRows] = "locale"; - snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsLocale); + snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsLocale); totalRows++; cfgOpts[totalRows] = "charset"; - snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset); + snprintf(cfgVals[totalRows], TSDB_CONFIG_VALUE_LEN, "%s", tsCharset); totalRows++; char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; - char bufVal[TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; + char bufVal[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; for (int32_t i = 0; i < totalRows; i++) { cols = 0; @@ -709,7 +808,7 @@ static int32_t mndRetrieveConfigs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)buf, false); - STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONIIG_VALUE_LEN); + STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONFIG_VALUE_LEN); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)bufVal, false); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 675a3aa03f..000e1041d0 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -65,6 +65,13 @@ static void mndPullupTrans(SMnode *pMnode) { } } +static void mndTtlTimer(SMnode *pMnode) { + int32_t contLen = 0; + void *pReq = mndBuildTimerMsg(&contLen); + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TTL_TIMER, .pCont = pReq, .contLen = contLen}; + tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); +} + static void mndCalMqRebalance(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); @@ -83,41 +90,6 @@ static void mndPullupTelem(SMnode *pMnode) { } } -static void mndPushTtlTime(SMnode *pMnode) { - SSdb *pSdb = pMnode->pSdb; - SVgObj *pVgroup = NULL; - void *pIter = NULL; - - while (1) { - pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); - if (pIter == NULL) break; - - int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); - SMsgHead *pHead = rpcMallocCont(contLen); - if (pHead == NULL) { - sdbCancelFetch(pSdb, pIter); - sdbRelease(pSdb, pVgroup); - continue; - } - - pHead->contLen = htonl(contLen); - pHead->vgId = htonl(pVgroup->vgId); - - int32_t t = taosGetTimestampSec(); - *(int32_t *)(POINTER_SHIFT(pHead, sizeof(SMsgHead))) = htonl(t); - - SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; - SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); - int32_t code = tmsgSendReq(&epSet, &rpcMsg); - if (code != 0) { - mError("failed to send ttl time seed msg, code:0x%x", code); - } else { - mInfo("send ttl time seed msg, time:%d", t); - } - sdbRelease(pSdb, pVgroup); - } -} - static void *mndThreadFp(void *param) { SMnode *pMnode = param; int64_t lastTime = 0; @@ -125,14 +97,13 @@ static void *mndThreadFp(void *param) { while (1) { lastTime++; - - if (lastTime % (864000) == 0) { // sleep 1 day for ttl - mndPushTtlTime(pMnode); - } - taosMsleep(100); if (mndGetStop(pMnode)) break; + if (lastTime % (tsTransPullupInterval * 10) == 1) { + mndTtlTimer(pMnode); + } + if (lastTime % (tsTransPullupInterval * 10) == 0) { mndPullupTrans(pMnode); } @@ -558,12 +529,12 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { if (!IsReq(pMsg)) return 0; if (mndAcquireRpcRef(pMsg->info.node) == 0) return 0; if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER || - pMsg->msgType == TDMT_MND_TRANS_TIMER) { + pMsg->msgType == TDMT_MND_TRANS_TIMER || TDMT_MND_TTL_TIMER) { return -1; } const STraceId *trace = &pMsg->info.traceId; - mGError("msg:%p, failed to check mnode state since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); + mError("msg:%p, failed to check mnode state since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType)); SEpSet epSet = {0}; mndGetMnodeEpSet(pMsg->info.node, &epSet); @@ -584,7 +555,7 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { static int32_t mndCheckMsgContent(SRpcMsg *pMsg) { if (!IsReq(pMsg)) return 0; if (pMsg->contLen != 0 && pMsg->pCont != NULL) return 0; - + const STraceId *trace = &pMsg->info.traceId; mGError("msg:%p, failed to check msg, cont:%p contLen:%d, app:%p type:%s", pMsg, pMsg->pCont, pMsg->contLen, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType)); @@ -643,7 +614,7 @@ int64_t mndGenerateUid(char *name, int32_t len) { } int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo) { + SMonStbInfo *pStbInfo, SMonGrantInfo *pGrantInfo) { if (mndAcquireRpcRef(pMnode) != 0) return -1; SSdb *pSdb = pMnode->pSdb; @@ -652,7 +623,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr pClusterInfo->dnodes = taosArrayInit(sdbGetSize(pSdb, SDB_DNODE), sizeof(SMonDnodeDesc)); pClusterInfo->mnodes = taosArrayInit(sdbGetSize(pSdb, SDB_MNODE), sizeof(SMonMnodeDesc)); pVgroupInfo->vgroups = taosArrayInit(sdbGetSize(pSdb, SDB_VGROUP), sizeof(SMonVgroupDesc)); - if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL) { + pStbInfo->stbs = taosArrayInit(sdbGetSize(pSdb, SDB_STB), sizeof(SMonStbDesc)); + if (pClusterInfo->dnodes == NULL || pClusterInfo->mnodes == NULL || pVgroupInfo->vgroups == NULL || + pStbInfo->stbs == NULL) { mndReleaseRpcRef(pMnode); return -1; } @@ -661,6 +634,8 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version)); pClusterInfo->monitor_interval = tsMonitorInterval; pClusterInfo->connections_total = mndGetNumOfConnections(pMnode); + pClusterInfo->dbs_total = sdbGetSize(pSdb, SDB_DB); + pClusterInfo->stbs_total = sdbGetSize(pSdb, SDB_STB); void *pIter = NULL; while (1) { @@ -710,6 +685,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr if (pIter == NULL) break; pClusterInfo->vgroups_total++; + pClusterInfo->tbs_total += pVgroup->numOfTables; SMonVgroupDesc desc = {0}; desc.vgroup_id = pVgroup->vgId; @@ -740,6 +716,27 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr sdbRelease(pSdb, pVgroup); } + // stb info + pIter = NULL; + while (1) { + SStbObj *pStb = NULL; + pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb); + if (pIter == NULL) break; + + SMonStbDesc desc = {0}; + + SName name1 = {0}; + tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + tNameGetDbName(&name1, desc.database_name); + + SName name2 = {0}; + tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + tstrncpy(desc.stb_name, tNameGetTableName(&name2), TSDB_TABLE_NAME_LEN); + + taosArrayPush(pStbInfo->stbs, &desc); + sdbRelease(pSdb, pStb); + } + // grant info pGrantInfo->expire_time = (pMnode->grant.expireTimeMS - ms) / 86400000.0f; pGrantInfo->timeseries_total = pMnode->grant.timeseriesAllowed; diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 01e3bdcf13..832e328d96 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -447,7 +447,7 @@ static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnIn mError("failed to create new app %" PRIx64 " since %s", pReq->appId, terrstr()); return -1; } else { - mDebug("a new app %" PRIx64 "created", pReq->appId); + mDebug("a new app %" PRIx64 " is created", pReq->appId); mndReleaseApp(pMnode, pApp); return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index f5625f32d5..0a6c97e63c 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -354,6 +354,14 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn return 0; } +int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj) { + if (pObj == NULL) return 0; + if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) return -1; + if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) return -1; + if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + return 0; +} + static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) { int32_t code = -1; @@ -361,9 +369,7 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) { if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); - if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) goto _OVER; - if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) goto _OVER; - if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto _OVER; + if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 2b6258b10a..eb0ccbb5f7 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -37,7 +37,7 @@ extern bool tsSchedStreamToSnode; static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) { int32_t childId = taosArrayGetSize(pArray); - pTask->childId = childId; + pTask->selfChildId = childId; taosArrayPush(pArray, &pTask); return 0; } @@ -97,37 +97,7 @@ END: return terrno; } -int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type, int32_t nodeId) { - SEncoder encoder; - tEncoderInit(&encoder, NULL, 0); - tEncodeSStreamTask(&encoder, pTask); - int32_t size = encoder.pos; - int32_t tlen = sizeof(SMsgHead) + size; - tEncoderClear(&encoder); - void* buf = taosMemoryCalloc(1, tlen); - if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - ((SMsgHead*)buf)->vgId = htonl(nodeId); - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncoderInit(&encoder, abuf, size); - tEncodeSStreamTask(&encoder, pTask); - tEncoderClear(&encoder); - - STransAction action = {0}; - memcpy(&action.epSet, pEpSet, sizeof(SEpSet)); - action.pCont = buf; - action.contLen = tlen; - action.msgType = type; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(buf); - return -1; - } - return 0; -} - -int32_t mndAddSinkToTask(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, SStreamTask* pTask) { +int32_t mndAddSinkToTask(SMnode* pMnode, SStreamObj* pStream, SStreamTask* pTask) { pTask->dispatchType = TASK_DISPATCH__NONE; // sink if (pStream->smaId != 0) { @@ -142,7 +112,7 @@ int32_t mndAddSinkToTask(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, SS return 0; } -int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, SStreamTask* pTask) { +int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, SStreamObj* pStream, SStreamTask* pTask) { pTask->sinkType = TASK_SINK__NONE; if (pStream->fixedSinkVgId == 0) { pTask->dispatchType = TASK_DISPATCH__SHUFFLE; @@ -187,7 +157,7 @@ int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, STrans* pTrans, SStreamObj* return 0; } -int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) { +int32_t mndAssignTaskToVg(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) { int32_t msgLen; pTask->nodeId = pVgroup->vgId; pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); @@ -196,11 +166,11 @@ int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SS plan->execNode.epSet = pTask->epSet; if (qSubPlanToString(plan, &pTask->exec.qmsg, &msgLen) < 0) { + ASSERT(0); terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE || pTask->sinkType != TASK_SINK__NONE); - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId); return 0; } @@ -212,8 +182,7 @@ SSnodeObj* mndSchedFetchOneSnode(SMnode* pMnode) { return pObj; } -int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan, - const SSnodeObj* pSnode) { +int32_t mndAssignTaskToSnode(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, const SSnodeObj* pSnode) { int32_t msgLen; pTask->nodeId = SNODE_HANDLE; @@ -223,10 +192,10 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, plan->execNode.epSet = pTask->epSet; if (qSubPlanToString(plan, &pTask->exec.qmsg, &msgLen) < 0) { + ASSERT(0); terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - mndPersistTaskDeployReq(pTrans, pTask, &plan->execNode.epSet, TDMT_STREAM_TASK_DEPLOY, SNODE_HANDLE); return 0; } @@ -245,7 +214,7 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) { return pVgroup; } -int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { +int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, SStreamObj* pStream) { SSdb* pSdb = pMnode->pSdb; void* pIter = NULL; SArray* tasks = taosArrayGetP(pStream->tasks, 0); @@ -262,6 +231,7 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamOb } SStreamTask* pTask = tNewSStreamTask(pStream->uid); if (pTask == NULL) { + sdbRelease(pSdb, pVgroup); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -271,7 +241,7 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamOb pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); // source - pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; + pTask->isDataScan = 0; // exec pTask->execType = TASK_EXEC__NONE; @@ -290,13 +260,11 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamOb // dispatch pTask->dispatchType = TASK_DISPATCH__NONE; - - mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pVgroup->vgId); } return 0; } -int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { +int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, SStreamObj* pStream) { ASSERT(pStream->fixedSinkVgId != 0); SArray* tasks = taosArrayGetP(pStream->tasks, 0); SStreamTask* pTask = tNewSStreamTask(pStream->uid); @@ -306,6 +274,8 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* } mndAddTaskToTaskSet(tasks, pTask); + ASSERT(pStream->fixedSinkVg.vgId == pStream->fixedSinkVgId); + pTask->nodeId = pStream->fixedSinkVgId; #if 0 SVgObj* pVgroup = mndAcquireVgroup(pMnode, pStream->fixedSinkVgId); @@ -315,8 +285,9 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup); #endif pTask->epSet = mndGetVgroupEpset(pMnode, &pStream->fixedSinkVg); + // source - pTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; + pTask->isDataScan = 0; // exec pTask->execType = TASK_EXEC__NONE; @@ -334,13 +305,10 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* // dispatch pTask->dispatchType = TASK_DISPATCH__NONE; - - mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_STREAM_TASK_DEPLOY, pStream->fixedSinkVg.vgId); - return 0; } -int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { +int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { SSdb* pSdb = pMnode->pSdb; SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); if (pPlan == NULL) { @@ -365,9 +333,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // add extra sink hasExtraSink = true; if (pStream->fixedSinkVgId == 0) { - mndAddShuffleSinkTasksToStream(pMnode, pTrans, pStream); + if (mndAddShuffleSinkTasksToStream(pMnode, pStream) < 0) { + // TODO free + return -1; + } } else { - mndAddFixedSinkTaskToStream(pMnode, pTrans, pStream); + if (mndAddFixedSinkTaskToStream(pMnode, pStream) < 0) { + // TODO free + return -1; + } } } @@ -383,15 +357,23 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE); pInnerTask = tNewSStreamTask(pStream->uid); + if (pInnerTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + qDestroyQueryPlan(pPlan); + return -1; + } mndAddTaskToTaskSet(taskInnerLevel, pInnerTask); - // input - pInnerTask->inputType = TASK_INPUT_TYPE__DATA_BLOCK; + + pInnerTask->childEpInfo = taosArrayInit(0, sizeof(void*)); + + // source + pInnerTask->isDataScan = 0; // trigger pInnerTask->triggerParam = pStream->triggerParam; // dispatch - if (mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pInnerTask) < 0) { + if (mndAddDispatcherToInnerTask(pMnode, pStream, pInnerTask) < 0) { qDestroyQueryPlan(pPlan); return -1; } @@ -403,14 +385,13 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { SSnodeObj* pSnode = mndSchedFetchOneSnode(pMnode); if (pSnode == NULL) { SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); - if (mndAssignTaskToVg(pMnode, pTrans, pInnerTask, plan, pVgroup) < 0) { + if (mndAssignTaskToVg(pMnode, pInnerTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); return -1; } } else { - if (mndAssignTaskToSnode(pMnode, pTrans, pInnerTask, plan, pSnode) < 0) { - ASSERT(0); + if (mndAssignTaskToSnode(pMnode, pInnerTask, plan, pSnode) < 0) { sdbRelease(pSdb, pSnode); qDestroyQueryPlan(pPlan); return -1; @@ -418,7 +399,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { } } else { SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); - if (mndAssignTaskToVg(pMnode, pTrans, pInnerTask, plan, pVgroup) < 0) { + if (mndAssignTaskToVg(pMnode, pInnerTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); return -1; @@ -444,12 +425,16 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { continue; } SStreamTask* pTask = tNewSStreamTask(pStream->uid); + if (pInnerTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + return -1; + } mndAddTaskToTaskSet(taskSourceLevel, pTask); - pTask->dataScan = 1; - - // input - pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK; + // source + pTask->isDataScan = 1; // add fixed vg dispatch pTask->sinkType = TASK_SINK__NONE; @@ -462,11 +447,25 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { // exec pTask->execType = TASK_EXEC__PIPE; - if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { + if (mndAssignTaskToVg(pMnode, pTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); return -1; } + + SStreamChildEpInfo* pEpInfo = taosMemoryMalloc(sizeof(SStreamChildEpInfo)); + if (pEpInfo == NULL) { + ASSERT(0); + terrno = TSDB_CODE_OUT_OF_MEMORY; + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + return -1; + } + pEpInfo->childId = pTask->selfChildId; + pEpInfo->epSet = pTask->epSet; + pEpInfo->nodeId = pTask->nodeId; + pEpInfo->taskId = pTask->taskId; + taosArrayPush(pInnerTask->childEpInfo, &pEpInfo); } } @@ -489,26 +488,29 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { continue; } SStreamTask* pTask = tNewSStreamTask(pStream->uid); + if (pTask == NULL) { + sdbRelease(pSdb, pVgroup); + qDestroyQueryPlan(pPlan); + return -1; + } mndAddTaskToTaskSet(taskOneLevel, pTask); - pTask->dataScan = 1; - - // input - pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK; + // source + pTask->isDataScan = 1; // trigger pTask->triggerParam = pStream->triggerParam; // sink or dispatch if (hasExtraSink) { - mndAddDispatcherToInnerTask(pMnode, pTrans, pStream, pTask); + mndAddDispatcherToInnerTask(pMnode, pStream, pTask); } else { - mndAddSinkToTask(pMnode, pTrans, pStream, pTask); + mndAddSinkToTask(pMnode, pStream, pTask); } // exec pTask->execType = TASK_EXEC__PIPE; - if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) { + if (mndAssignTaskToVg(pMnode, pTask, plan, pVgroup) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); return -1; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index fed6a5a721..27de3883e9 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -236,7 +236,6 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { int32_t numOfCols = pShow->pMeta->numOfColumns; SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - pBlock->info.numOfCols = numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData idata = {0}; @@ -271,7 +270,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { } size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + - blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock->info.numOfCols); + blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)); SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); if (pRsp == NULL) { diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index c44fb03be2..05603f8554 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -533,7 +533,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea #if 0 smaObj.timezone = pCreate->timezone; #endif - smaObj.timezone = tsTimezone; // use timezone of server + smaObj.timezone = tsTimezone; // use timezone of server smaObj.interval = pCreate->interval; smaObj.offset = pCreate->offset; smaObj.sliding = pCreate->sliding; @@ -623,7 +623,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea if (mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER; // if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaVgroupRedoActions(pMnode, pTrans, pDb, &streamObj.fixedSinkVg, &smaObj) != 0) goto _OVER; - if (mndScheduleStream(pMnode, pTrans, &streamObj) != 0) goto _OVER; + if (mndScheduleStream(pMnode, &streamObj) != 0) goto _OVER; if (mndPersistStream(pMnode, pTrans, &streamObj) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 12188a3b3a..df1330197a 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -65,7 +65,7 @@ SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode) { return epSet; } -static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { +SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { SSnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_SNODE, &snodeId); if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; @@ -73,7 +73,7 @@ static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { return pObj; } -static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { +void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { SSdb *pSdb = pMnode->pSdb; sdbRelease(pSdb, pObj); } @@ -361,6 +361,14 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn return 0; } +int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj) { + if (pObj == NULL) return 0; + if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) return -1; + if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) return -1; + if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + return 0; +} + static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) { int32_t code = -1; @@ -368,10 +376,7 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) { if (pTrans == NULL) goto _OVER; mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - - if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) goto _OVER; - if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) goto _OVER; - if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto _OVER; + if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index e04662d22b..f1bae14c07 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -37,6 +37,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw); static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb); static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb); static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew); +static int32_t mndProcessTtlTimer(SRpcMsg *pReq); static int32_t mndProcessCreateStbReq(SRpcMsg *pReq); static int32_t mndProcessAlterStbReq(SRpcMsg *pReq); static int32_t mndProcessDropStbReq(SRpcMsg *pReq); @@ -63,6 +64,7 @@ int32_t mndInitStb(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_TABLE_META, mndProcessTableMetaReq); + mndSetMsgHandle(pMnode, TDMT_MND_TTL_TIMER, mndProcessTtlTimer); mndSetMsgHandle(pMnode, TDMT_MND_TABLE_CFG, mndProcessTableCfgReq); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STB, mndRetrieveStb); @@ -799,6 +801,43 @@ int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p return 0; } +static int32_t mndProcessTtlTimer(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); + SMsgHead *pHead = rpcMallocCont(contLen); + if (pHead == NULL) { + sdbCancelFetch(pSdb, pVgroup); + sdbRelease(pSdb, pVgroup); + continue; + } + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); + + int32_t t = taosGetTimestampSec(); + *(int32_t *)((char *)pHead + sizeof(SMsgHead)) = htonl(t); + + SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; + SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); + int32_t code = tmsgSendReq(&epSet, &rpcMsg); + if (code != 0) { + mError("failed to send ttl time seed, code:0x%x", code); + } else { + mDebug("send ttl time seed success, time:%d", t); + } + sdbRelease(pSdb, pVgroup); + } + + return 0; +} + static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 7e9069d5fc..96a82e2c18 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -320,11 +320,58 @@ FAIL: return 0; } +int32_t mndPersistTaskDeployReq(STrans *pTrans, const SStreamTask *pTask) { + SEncoder encoder; + tEncoderInit(&encoder, NULL, 0); + tEncodeSStreamTask(&encoder, pTask); + int32_t size = encoder.pos; + int32_t tlen = sizeof(SMsgHead) + size; + tEncoderClear(&encoder); + void *buf = taosMemoryCalloc(1, tlen); + if (buf == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + ((SMsgHead *)buf)->vgId = htonl(pTask->nodeId); + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tEncoderInit(&encoder, abuf, size); + tEncodeSStreamTask(&encoder, pTask); + tEncoderClear(&encoder); + + STransAction action = {0}; + memcpy(&action.epSet, &pTask->epSet, sizeof(SEpSet)); + action.pCont = buf; + action.contLen = tlen; + action.msgType = TDMT_STREAM_TASK_DEPLOY; + if (mndTransAppendRedoAction(pTrans, &action) != 0) { + taosMemoryFree(buf); + return -1; + } + return 0; +} + +int32_t mndPersistStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + int32_t level = taosArrayGetSize(pStream->tasks); + for (int32_t i = 0; i < level; i++) { + SArray *pLevel = taosArrayGetP(pStream->tasks, i); + int32_t sz = taosArrayGetSize(pLevel); + for (int32_t j = 0; j < sz; j++) { + SStreamTask *pTask = taosArrayGetP(pLevel, j); + if (mndPersistTaskDeployReq(pTrans, pTask) < 0) { + return -1; + } + } + } + return 0; +} + int32_t mndPersistStream(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + if (mndPersistStreamTasks(pMnode, pTrans, pStream) < 0) { + return -1; + } SSdbRaw *pCommitRaw = mndStreamActionEncode(pStream); if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); return -1; } sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); @@ -342,51 +389,6 @@ int32_t mndPersistDropStreamLog(SMnode *pMnode, STrans *pTrans, SStreamObj *pStr return 0; } -int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) { - SNode *pAst = NULL; - - if (nodesStringToNode(ast, &pAst) < 0) { - return -1; - } - - if (qExtractResultSchema(pAst, (int32_t *)&pStream->outputSchema.nCols, &pStream->outputSchema.pSchema) != 0) { - nodesDestroyNode(pAst); - return -1; - } - // free - nodesDestroyNode(pAst); - -#if 0 - printf("|"); - for (int i = 0; i < pStream->outputSchema.nCols; i++) { - printf(" %15s |", (char *)pStream->outputSchema.pSchema[i].name); - } - printf("\n=======================================================\n"); - -#endif - - if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, pStream->trigger, pStream->watermark, &pStream->physicalPlan)) { - mError("topic:%s, failed to get plan since %s", pStream->name, terrstr()); - return -1; - } - - if (mndScheduleStream(pMnode, pTrans, pStream) < 0) { - mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr()); - return -1; - } - mDebug("trans:%d, used to create stream:%s", pTrans->id, pStream->name); - - SSdbRaw *pCommitRaw = mndStreamActionEncode(pStream); - if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { - mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); - - return 0; -} - static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStreamObj *pStream, const char *user) { SStbObj *pStb = NULL; SDbObj *pDb = NULL; @@ -503,64 +505,6 @@ static int32_t mndDropStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pS return 0; } -static int32_t mndCreateStream(SMnode *pMnode, SRpcMsg *pReq, SCMCreateStreamReq *pCreate, SDbObj *pDb) { - mDebug("stream:%s to create", pCreate->name); - SStreamObj streamObj = {0}; - tstrncpy(streamObj.name, pCreate->name, TSDB_STREAM_FNAME_LEN); - tstrncpy(streamObj.sourceDb, pDb->name, TSDB_DB_FNAME_LEN); - tstrncpy(streamObj.targetSTbName, pCreate->targetStbFullName, TSDB_TABLE_FNAME_LEN); - streamObj.createTime = taosGetTimestampMs(); - streamObj.updateTime = streamObj.createTime; - streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); - streamObj.targetStbUid = mndGenerateUid(pCreate->targetStbFullName, TSDB_TABLE_FNAME_LEN); - streamObj.sourceDbUid = pDb->uid; - streamObj.version = 1; - streamObj.sql = pCreate->sql; - // TODO - streamObj.fixedSinkVgId = 0; - streamObj.smaId = 0; - streamObj.trigger = pCreate->triggerType; - streamObj.watermark = pCreate->watermark; - streamObj.triggerParam = pCreate->maxDelay; - - if (streamObj.targetSTbName[0]) { - pDb = mndAcquireDbByStb(pMnode, streamObj.targetSTbName); - if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; - } - tstrncpy(streamObj.targetDb, pDb->name, TSDB_DB_FNAME_LEN); - } - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq); - if (pTrans == NULL) { - mError("stream:%s, failed to create since %s", pCreate->name, terrstr()); - return -1; - } - mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); - - if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) { - mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - - if (streamObj.targetSTbName[0] && mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) { - mError("trans:%d, failed to create stb for stream since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - - mndTransDrop(pTrans); - return 0; -} - static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; @@ -631,7 +575,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { } // schedule stream task for stream obj - if (mndScheduleStream(pMnode, pTrans, &streamObj) < 0) { + if (mndScheduleStream(pMnode, &streamObj) < 0) { mError("stream:%s, failed to schedule since %s", createStreamReq.name, terrstr()); mndTransDrop(pTrans); goto _OVER; @@ -653,8 +597,6 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) { mndTransDrop(pTrans); - /*code = mndCreateStream(pMnode, pReq, &createStreamReq, pDb);*/ - /*if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;*/ code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 8666739dab..e3358b41df 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -75,7 +75,7 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM } int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) { - mInfo("start to read snapshot from sdb in atomic way"); + mDebug("start to read snapshot from sdb in atomic way"); SMnode *pMnode = pFsm->data; return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex); @@ -96,7 +96,7 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) { mndTransPullup(pMnode); mndSetRestore(pMnode, true); } else { - mInfo("mnode sync restore finished, and will set ready after first deploy"); + mInfo("mnode sync restore finished"); } } @@ -118,13 +118,13 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM } int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void **ppReader) { - mInfo("start to read snapshot from sdb"); + mDebug("start to read snapshot from sdb"); SMnode *pMnode = pFsm->data; return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, NULL, NULL, NULL); } int32_t mndSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { - mInfo("stop to read snapshot from sdb"); + mDebug("stop to read snapshot from sdb"); SMnode *pMnode = pFsm->data; return sdbStopRead(pMnode->pSdb, pReader); } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index de6a44d456..d1d88fdc90 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -56,6 +56,7 @@ static bool mndCannotExecuteTransAction(SMnode *pMnode) { return !pMnode->dep static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static int32_t mndProcessTransReq(SRpcMsg *pReq); +static int32_t mndProcessTtl(SRpcMsg *pReq); static int32_t mndProcessKillTransReq(SRpcMsg *pReq); static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); @@ -432,11 +433,11 @@ static const char *mndTransStr(ETrnStage stage) { } static void mndTransTestStartFunc(SMnode *pMnode, void *param, int32_t paramLen) { - mInfo("test trans start, param:%s, len:%d", (char *)param, paramLen); + mDebug("test trans start, param:%s, len:%d", (char *)param, paramLen); } static void mndTransTestStopFunc(SMnode *pMnode, void *param, int32_t paramLen) { - mInfo("test trans stop, param:%s, len:%d", (char *)param, paramLen); + mDebug("test trans stop, param:%s, len:%d", (char *)param, paramLen); } static TransCbFp mndTransGetCbFp(ETrnFunc ftype) { diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 94ddbcd409..ae13987d25 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -1017,6 +1017,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) return -1; + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; + mInfo("vgId:%d, vgroup info after move, replica:%d", newVg.vgId, newVg.replica); for (int32_t i = 0; i < newVg.replica; ++i) { mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); @@ -1025,6 +1030,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, } int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId) { + int32_t code = 0; SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId); if (pArray == NULL) return -1; @@ -1042,18 +1048,24 @@ int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t del } } + code = 0; if (vnIndex != -1) { mInfo("vgId:%d, vnode:%d will be removed from dnode:%d", pVgroup->vgId, vnIndex, delDnodeId); SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); - mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray); + code = mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray); mndReleaseDb(pMnode, pDb); } sdbRelease(pMnode->pSdb, pVgroup); + + if (code != 0) { + sdbCancelFetch(pMnode->pSdb, pIter); + break; + } } taosArrayDestroy(pArray); - return 0; + return code; } static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, @@ -1541,10 +1553,11 @@ static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SD static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDnodeObj *pSrc, SDnodeObj *pDst) { void *pIter = NULL; int32_t code = -1; + SSdb *pSdb = pMnode->pSdb; while (1) { SVgObj *pVgroup = NULL; - pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); if (pIter == NULL) break; bool existInSrc = false; @@ -1556,13 +1569,15 @@ static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDno } if (!existInSrc || existInDst) { - sdbRelease(pMnode->pSdb, pVgroup); + sdbRelease(pSdb, pVgroup); + continue; } SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); code = mndSetBalanceVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, pSrc, pDst); mndReleaseDb(pMnode, pDb); - sdbRelease(pMnode->pSdb, pVgroup); + sdbRelease(pSdb, pVgroup); + sdbCancelFetch(pSdb, pIter); break; } @@ -1581,15 +1596,25 @@ static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) { while (1) { taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes); - SDnodeObj *pSrc = taosArrayGet(pArray, 0); - SDnodeObj *pDst = taosArrayGet(pArray, taosArrayGetSize(pArray) - 1); + for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) { + SDnodeObj *pDnode = taosArrayGet(pArray, i); + mDebug("dnode:%d, equivalent vnodes:%d support:%d, score:%f", pDnode->id, pDnode->numOfVnodes, + pDnode->numOfSupportVnodes, (float)pDnode->numOfVnodes / pDnode->numOfSupportVnodes); + } + + SDnodeObj *pSrc = taosArrayGet(pArray, taosArrayGetSize(pArray) - 1); + SDnodeObj *pDst = taosArrayGet(pArray, 0); float srcScore = (float)(pSrc->numOfVnodes - 1) / pSrc->numOfSupportVnodes; float dstScore = (float)(pDst->numOfVnodes + 1) / pDst->numOfSupportVnodes; - if (srcScore + 0.0001 < dstScore) { - mDebug("trans:%d, balance vgroup from dnode:%d to dnode:%d", pTrans->id, pSrc->id, pDst->id); + mDebug("trans:%d, after balance, src dnode:%d score:%f, dst dnode:%d score:%f", pTrans->id, pSrc->id, srcScore, + pDst->id, dstScore); + + if (srcScore > dstScore - 0.000001) { code = mndBalanceVgroupBetweenDnode(pMnode, pTrans, pSrc, pDst); if (code == 0) { + pSrc->numOfVnodes--; + pDst->numOfVnodes++; numOfVgroups++; continue; } else { @@ -1623,7 +1648,13 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) { void *pIter = NULL; int64_t curMs = taosGetTimestampMs(); - mDebug("start to balance vgroup"); + SBalanceVgroupReq req = {0}; + if (tDeserializeSBalanceVgroupReq(pReq->pCont, pReq->contLen, &req) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto _OVER; + } + + mInfo("start to balance vgroup"); if (mndCheckOperAuth(pMnode, pReq->info.conn.user, MND_OPER_BALANCE_VGROUP) != 0) goto _OVER; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 47c4a4ed0f..ff4a9e4ead 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -519,7 +519,7 @@ static void sdbCloseIter(SSdbIter *pIter) { pIter->name = NULL; } - mInfo("sdbiter:%p, is closed, total:%" PRId64, pIter, pIter->total); + mDebug("sdbiter:%p, is closed, total:%" PRId64, pIter, pIter->total); taosMemoryFree(pIter); } @@ -556,7 +556,7 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter if (term != NULL) *term = commitTerm; if (config != NULL) *config = commitConfig; - mInfo("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s", + mDebug("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s", pIter, commitIndex, commitTerm, commitConfig, pIter->name); return 0; } @@ -583,14 +583,14 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) { taosMemoryFree(pBuf); return -1; } else if (readlen == 0) { - mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total); + mDebug("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total); *ppBuf = NULL; *len = 0; taosMemoryFree(pBuf); return 0; } else { // (readlen <= maxlen) pIter->total += readlen; - mInfo("sdbiter:%p, read:%d bytes from snapshot, total:%" PRId64, pIter, readlen, pIter->total); + mDebug("sdbiter:%p, read:%d bytes from snapshot, total:%" PRId64, pIter, readlen, pIter->total); *ppBuf = pBuf; *len = readlen; return 0; @@ -609,7 +609,7 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) { } *ppIter = pIter; - mInfo("sdbiter:%p, is created to write snapshot, file:%s", pIter, pIter->name); + mDebug("sdbiter:%p, is created to write snapshot, file:%s", pIter, pIter->name); return 0; } @@ -618,7 +618,7 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply) { if (!isApply) { sdbCloseIter(pIter); - mInfo("sdbiter:%p, not apply to sdb", pIter); + mDebug("sdbiter:%p, not apply to sdb", pIter); return 0; } @@ -641,7 +641,7 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply) { return -1; } - mInfo("sdbiter:%p, successfully applyed to sdb", pIter); + mDebug("sdbiter:%p, successfully applyed to sdb", pIter); return 0; } @@ -654,6 +654,6 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) { } pIter->total += writelen; - mInfo("sdbiter:%p, write:%d bytes to snapshot, total:%" PRId64, pIter, writelen, pIter->total); + mDebug("sdbiter:%p, write:%d bytes to snapshot, total:%" PRId64, pIter, writelen, pIter->total); return 0; } \ No newline at end of file diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index c2c4ea3a88..3a92cba773 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -105,13 +105,14 @@ static int32_t sndProcessTaskDeployReq(SSnode *pNode, SRpcMsg *pMsg) { ASSERT(pTask->execType != TASK_EXEC__NONE); - ASSERT(pTask->dataScan == 0); + ASSERT(pTask->isDataScan == 0); pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL); ASSERT(pTask->exec.executor); streamSetupTrigger(pTask); - qInfo("deploy stream: stream id %ld task id %d child id %d on snode", pTask->streamId, pTask->taskId, pTask->childId); + qInfo("deploy stream: stream id %ld task id %d child id %d on snode", pTask->streamId, pTask->taskId, + pTask->selfChildId); taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void *)); @@ -198,6 +199,34 @@ static int32_t sndProcessTaskDropReq(SSnode *pNode, SRpcMsg *pMsg) { return code; } +static int32_t sndProcessTaskRetrieveReq(SSnode *pNode, SRpcMsg *pMsg) { + SStreamMeta *pMeta = pNode->pMeta; + + char *msgStr = pMsg->pCont; + char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + SStreamRetrieveReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + tDecodeStreamRetrieveReq(&decoder, &req); + int32_t taskId = req.dstTaskId; + SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessRetrieveReq(pTask, &req, &rsp); + return 0; +} + +static int32_t sndProcessTaskRetrieveRsp(SSnode *pNode, SRpcMsg *pMsg) { + // + return 0; +} + int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { // stream deploy // stream stop/resume @@ -221,10 +250,14 @@ int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { return sndProcessTaskDispatchReq(pSnode, pMsg); case TDMT_STREAM_TASK_RECOVER: return sndProcessTaskRecoverReq(pSnode, pMsg); + case TDMT_STREAM_RETRIEVE: + return sndProcessTaskRecoverReq(pSnode, pMsg); case TDMT_STREAM_TASK_DISPATCH_RSP: return sndProcessTaskDispatchRsp(pSnode, pMsg); case TDMT_STREAM_TASK_RECOVER_RSP: return sndProcessTaskRecoverRsp(pSnode, pMsg); + case TDMT_STREAM_RETRIEVE_RSP: + return sndProcessTaskRecoverRsp(pSnode, pMsg); default: ASSERT(0); } diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 15eb35c700..b09ab34224 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -29,6 +29,7 @@ target_sources( # sma "src/sma/sma.c" "src/sma/smaEnv.c" + "src/sma/smaUtil.c" "src/sma/smaOpen.c" "src/sma/smaRollup.c" "src/sma/smaTimeRange.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 70d89102e6..c7e8e8dc86 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -149,8 +149,8 @@ int32_t tqReadHandleRemoveTbUidList(STqReadHandle *pHandle, const SArray *tbUidL int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver); bool tqNextDataBlock(STqReadHandle *pHandle); bool tqNextDataBlockFilterOut(STqReadHandle *pHandle, SHashObj *filterOutUids); -int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid, - int32_t *pNumOfRows, int16_t *pNumOfCols); +int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid, + int32_t *pNumOfRows); // sma int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days); @@ -195,6 +195,7 @@ struct SVnodeCfg { typedef struct { TSKEY lastKey; uint64_t uid; + uint64_t groupId; } STableKeyInfo; struct SMetaEntry { diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index 902e5e1bcc..1489b02492 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -34,7 +34,8 @@ extern "C" { typedef struct SSmaEnv SSmaEnv; typedef struct SSmaStat SSmaStat; -typedef struct SSmaStatItem SSmaStatItem; +typedef struct STSmaStat STSmaStat; +typedef struct SRSmaStat SRSmaStat; typedef struct SSmaKey SSmaKey; typedef struct SRSmaInfo SRSmaInfo; typedef struct SRSmaInfoItem SRSmaInfoItem; @@ -45,26 +46,38 @@ struct SSmaEnv { SSmaStat *pStat; }; -#define SMA_ENV_LOCK(env) ((env)->lock) -#define SMA_ENV_TYPE(env) ((env)->type) -#define SMA_ENV_STAT(env) ((env)->pStat) -#define SMA_ENV_STAT_ITEM(env) ((env)->pStat->tsmaStatItem) +#define SMA_ENV_LOCK(env) ((env)->lock) +#define SMA_ENV_TYPE(env) ((env)->type) +#define SMA_ENV_STAT(env) ((env)->pStat) -struct SSmaStatItem { +struct STSmaStat { int8_t state; // ETsdbSmaStat STSma *pTSma; // cache schema STSchema *pTSchema; }; +struct SRSmaStat { + SSma *pSma; + void *tmrHandle; + tmr_h tmrId; + int8_t tmrStat; + int32_t tmrSeconds; + SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo; +}; + struct SSmaStat { union { - SSmaStatItem tsmaStatItem; - SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo; + STSmaStat tsmaStat; // time-range-wise sma + SRSmaStat rsmaStat; // rollup sma }; T_REF_DECLARE() }; -#define SMA_STAT_ITEM(s) ((s)->tsmaStatItem) -#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash) +#define SMA_TSMA_STAT(s) (&(s)->tsmaStat) +#define SMA_RSMA_STAT(s) (&(s)->rsmaStat) +#define SMA_RSMA_INFO_HASH(s) ((s)->rsmaStat.rsmaInfoHash) +#define SMA_RSMA_TMR_HANDLE(s) ((s)->rsmaStat.tmrHandle) +#define SMA_RSMA_TMR_STAT(s) ((s)->rsmaStat.tmrStat) +#define RSMA_INFO_HASH(r) ((r)->rsmaInfoHash) void tdDestroySmaEnv(SSmaEnv *pSmaEnv); void *tdFreeSmaEnv(SSmaEnv *pSmaEnv); @@ -107,53 +120,51 @@ static FORCE_INLINE int32_t tdUnLockSmaEnv(SSmaEnv *pEnv) { return 0; } -static FORCE_INLINE int8_t tdSmaStat(SSmaStatItem *pStatItem) { - if (pStatItem) { - return atomic_load_8(&pStatItem->state); +static FORCE_INLINE int8_t tdSmaStat(STSmaStat *pTStat) { + if (pTStat) { + return atomic_load_8(&pTStat->state); } return TSDB_SMA_STAT_UNKNOWN; } -static FORCE_INLINE bool tdSmaStatIsOK(SSmaStatItem *pStatItem, int8_t *state) { - if (!pStatItem) { +static FORCE_INLINE bool tdSmaStatIsOK(STSmaStat *pTStat, int8_t *state) { + if (!pTStat) { return false; } if (state) { - *state = atomic_load_8(&pStatItem->state); + *state = atomic_load_8(&pTStat->state); return *state == TSDB_SMA_STAT_OK; } - return atomic_load_8(&pStatItem->state) == TSDB_SMA_STAT_OK; + return atomic_load_8(&pTStat->state) == TSDB_SMA_STAT_OK; } -static FORCE_INLINE bool tdSmaStatIsExpired(SSmaStatItem *pStatItem) { - return pStatItem ? (atomic_load_8(&pStatItem->state) & TSDB_SMA_STAT_EXPIRED) : true; +static FORCE_INLINE bool tdSmaStatIsExpired(STSmaStat *pTStat) { + return pTStat ? (atomic_load_8(&pTStat->state) & TSDB_SMA_STAT_EXPIRED) : true; } -static FORCE_INLINE bool tdSmaStatIsDropped(SSmaStatItem *pStatItem) { - return pStatItem ? (atomic_load_8(&pStatItem->state) & TSDB_SMA_STAT_DROPPED) : true; +static FORCE_INLINE bool tdSmaStatIsDropped(STSmaStat *pTStat) { + return pTStat ? (atomic_load_8(&pTStat->state) & TSDB_SMA_STAT_DROPPED) : true; } -static FORCE_INLINE void tdSmaStatSetOK(SSmaStatItem *pStatItem) { - if (pStatItem) { - atomic_store_8(&pStatItem->state, TSDB_SMA_STAT_OK); +static FORCE_INLINE void tdSmaStatSetOK(STSmaStat *pTStat) { + if (pTStat) { + atomic_store_8(&pTStat->state, TSDB_SMA_STAT_OK); } } -static FORCE_INLINE void tdSmaStatSetExpired(SSmaStatItem *pStatItem) { - if (pStatItem) { - atomic_or_fetch_8(&pStatItem->state, TSDB_SMA_STAT_EXPIRED); +static FORCE_INLINE void tdSmaStatSetExpired(STSmaStat *pTStat) { + if (pTStat) { + atomic_or_fetch_8(&pTStat->state, TSDB_SMA_STAT_EXPIRED); } } -static FORCE_INLINE void tdSmaStatSetDropped(SSmaStatItem *pStatItem) { - if (pStatItem) { - atomic_or_fetch_8(&pStatItem->state, TSDB_SMA_STAT_DROPPED); +static FORCE_INLINE void tdSmaStatSetDropped(STSmaStat *pTStat) { + if (pTStat) { + atomic_or_fetch_8(&pTStat->state, TSDB_SMA_STAT_DROPPED); } } -static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType); -void *tdFreeSmaStatItem(SSmaStatItem *pSmaStatItem); static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType); void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType); @@ -163,6 +174,51 @@ int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t version, const char *pMsg); int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg); int32_t tdProcessTSmaGetDaysImpl(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days); +typedef struct STFInfo STFInfo; +typedef struct STFile STFile; + +struct STFInfo { + uint32_t magic; + uint32_t ftype; + uint32_t fver; + uint64_t fsize; +}; + +struct STFile { + STFInfo info; + STfsFile f; + TdFilePtr pFile; + uint8_t state; +}; + +#define TD_FILE_F(tf) (&((tf)->f)) +#define TD_FILE_PFILE(tf) ((tf)->pFile) +#define TD_FILE_OPENED(tf) (TD_FILE_PFILE(tf) != NULL) +#define TD_FILE_FULL_NAME(tf) (TD_FILE_F(tf)->aname) +#define TD_FILE_REL_NAME(tf) (TD_FILE_F(tf)->rname) +#define TD_FILE_OPENED(tf) (TD_FILE_PFILE(tf) != NULL) +#define TD_FILE_CLOSED(tf) (!TD_FILE_OPENED(tf)) +#define TD_FILE_SET_CLOSED(f) (TD_FILE_PFILE(f) = NULL) +#define TD_FILE_STATE(tf) ((tf)->state) +#define TD_FILE_SET_STATE(tf, s) ((tf)->state = (s)) +#define TD_FILE_DID(tf) (TD_FILE_F(tf)->did) +#define TD_FILE_IS_OK(tf) (TD_FILE_STATE(tf) == TD_FILE_STATE_OK) +#define TD_FILE_IS_BAD(tf) (TD_FILE_STATE(tf) == TD_FILE_STATE_BAD) + +int32_t tdInitTFile(STFile *pTFile, STfs *pTfs, const char *fname); +int32_t tdCreateTFile(STFile *pTFile, STfs *pTfs, bool updateHeader, int8_t fType); +int32_t tdOpenTFile(STFile *pTFile, int flags); +int64_t tdReadTFile(STFile *pTFile, void *buf, int64_t nbyte); +int64_t tdSeekTFile(STFile *pTFile, int64_t offset, int whence); +int64_t tdWriteTFile(STFile *pTFile, void *buf, int64_t nbyte); +int64_t tdAppendTFile(STFile *pTFile, void *buf, int64_t nbyte, int64_t *offset); +int32_t tdRemoveTFile(STFile *pTFile); +int32_t tdLoadTFileHeader(STFile *pTFile, STFInfo *pInfo); +int32_t tdUpdateTFileHeader(STFile *pTFile); +void tdUpdateTFileMagic(STFile *pTFile, void *pCksm); +void tdCloseTFile(STFile *pTFile); +void tdGetVndFileName(int32_t vid, const char *dname, const char *fname, char *outputName); + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 8f6077e996..59c3e95b9c 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -150,6 +150,7 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead* // tqExec int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkRsp* pRsp, int32_t workerId); +int32_t tqScanSnapshot(STQ* pTq, const STqExecHandle* pExec, SMqDataBlkRsp* pRsp, int32_t workerId); int32_t tqSendPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataBlkRsp* pRsp); // tqMeta diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 7fa188d83a..32be479116 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -26,20 +26,19 @@ extern "C" { #endif // clang-format off +#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define vWarn(...) do { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define vInfo(...) do { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define vDebug(...) do { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", DEBUG_DEBUG, vDebugFlag, __VA_ARGS__); }} while(0) +#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0) -#define vFatal(...) { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} -#define vError(...) { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} -#define vWarn(...) { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define vInfo(...) { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); }} -#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", DEBUG_DEBUG, vDebugFlag, __VA_ARGS__); }} -#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} - -#define vGFatal(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vFatal(param ", gtid:%s", __VA_ARGS__, buf);} -#define vGError(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vError(param ", gtid:%s", __VA_ARGS__, buf);} -#define vGWarn(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vWarn (param ", gtid:%s", __VA_ARGS__, buf);} -#define vGInfo(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vInfo (param ", gtid:%s", __VA_ARGS__, buf);} -#define vGDebug(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vDebug(param ", gtid:%s", __VA_ARGS__, buf);} -#define vGTrace(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vTrace(param ", gtid:%s", __VA_ARGS__, buf);} +#define vGTrace(param, ...) do { if (vDebugFlag & DEBUG_TRACE) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vTrace(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define vGFatal(param, ...) do { if (vDebugFlag & DEBUG_FATAL) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vFatal(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define vGError(param, ...) do { if (vDebugFlag & DEBUG_ERROR) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vError(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define vGWarn(param, ...) do { if (vDebugFlag & DEBUG_WARN) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vWarn(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define vGInfo(param, ...) do { if (vDebugFlag & DEBUG_INFO) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vInfo(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define vGDebug(param, ...) do { if (vDebugFlag & DEBUG_DEBUG) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); vDebug(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) // clang-format on diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index c0dfebb08f..f7965f0902 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -149,6 +149,8 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg); SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid, const char* stbFullName, int32_t vgId); @@ -245,7 +247,6 @@ struct SVnode { struct STbUidStore { tb_uid_t suid; - tb_uid_t uid; // TODO: just for debugging, remove when uid provided in SSDataBlock SArray* tbUids; SHashObj* uidHash; }; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index a5ca90e55f..910f4bba51 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -219,11 +219,9 @@ _err: } int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ - metaRLock(pMeta); TBC * pCur; int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL); if (ret < 0) { - metaULock(pMeta); return ret; } @@ -249,6 +247,7 @@ int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ tdbTbcClose(pCur); tdbFree(pKey); + return 0; } @@ -265,8 +264,8 @@ struct SMCtbCursor { SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMCtbCursor *pCtbCur = NULL; SCtbIdxKey ctbIdxKey; - int ret; - int c; + int ret = 0; + int c = 0; pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); if (pCtbCur == NULL) { @@ -613,9 +612,6 @@ const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t type, STagVal *val) { ASSERT(pEntry->type == TSDB_CHILD_TABLE); STag *tag = (STag *)pEntry->ctbEntry.pTags; if (type == TSDB_DATA_TYPE_JSON) { - if (tag->nTag == 0) { - return NULL; - } return tag; } bool find = tTagGet(tag, val); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index bf5d5912f9..ab512f7774 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -375,6 +375,7 @@ int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) { metaWLock(pMeta); int ret = metaTtlSmaller(pMeta, ttl, tbUids); if(ret != 0){ + metaULock(pMeta); return ret; } for (int i = 0; i < taosArrayGetSize(tbUids); ++i) { @@ -400,8 +401,7 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ if (ttlDays <= 0) return; - ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; -// ttlKey->dtime = ctime / 1000 + ttlDays; + ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit; ttlKey->uid = pME->uid; } diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index a80af2b202..4e907e93ca 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -21,9 +21,10 @@ typedef struct SSmaStat SSmaStat; // declaration of static functions -static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType); +static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma); static SSmaEnv *tdNewSmaEnv(const SSma *pSma, int8_t smaType, const char *path); static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, const char *path, SSmaEnv **pEnv); +static void *tdFreeTSmaStat(STSmaStat *pStat); // implementation @@ -45,7 +46,7 @@ static SSmaEnv *tdNewSmaEnv(const SSma *pSma, int8_t smaType, const char *path) return NULL; } - if (tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType) != TSDB_CODE_SUCCESS) { + if (tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma) != TSDB_CODE_SUCCESS) { tdFreeSmaEnv(pEnv); return NULL; } @@ -105,7 +106,7 @@ int32_t tdUnRefSmaStat(SSma *pSma, SSmaStat *pStat) { return 0; } -static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) { +static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma) { ASSERT(pSmaStat != NULL); if (*pSmaStat) { // no lock @@ -125,10 +126,23 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) { } if (smaType == TSDB_SMA_TYPE_ROLLUP) { - SMA_STAT_INFO_HASH(*pSmaStat) = taosHashInit( - RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); + SMA_RSMA_STAT(*pSmaStat)->pSma = (SSma*)pSma; + // init timer + SMA_RSMA_TMR_HANDLE(*pSmaStat) = taosTmrInit(10000, 100, 10000, "RSMA_G"); + if (!SMA_RSMA_TMR_HANDLE(*pSmaStat)) { + taosMemoryFreeClear(*pSmaStat); + return TSDB_CODE_FAILED; + } + + atomic_store_8(&SMA_RSMA_TMR_STAT(*pSmaStat), TASK_TRIGGER_STATUS__ACTIVE); - if (!SMA_STAT_INFO_HASH(*pSmaStat)) { + // init hash + SMA_RSMA_INFO_HASH(*pSmaStat) = taosHashInit( + RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); + if (!SMA_RSMA_INFO_HASH(*pSmaStat)) { + if (SMA_RSMA_TMR_HANDLE(*pSmaStat)) { + taosTmrCleanUp(SMA_RSMA_TMR_HANDLE(*pSmaStat)); + } taosMemoryFreeClear(*pSmaStat); return TSDB_CODE_FAILED; } @@ -141,16 +155,16 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) { return TSDB_CODE_SUCCESS; } -void *tdFreeSmaStatItem(SSmaStatItem *pSmaStatItem) { - if (pSmaStatItem) { - tDestroyTSma(pSmaStatItem->pTSma); - taosMemoryFreeClear(pSmaStatItem->pTSma); - taosMemoryFreeClear(pSmaStatItem); +static void *tdFreeTSmaStat(STSmaStat *pStat) { + if (pStat) { + tDestroyTSma(pStat->pTSma); + taosMemoryFreeClear(pStat->pTSma); + taosMemoryFreeClear(pStat); } return NULL; } -void* tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { +void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { tdDestroySmaState(pSmaStat, smaType); taosMemoryFreeClear(pSmaStat); return NULL; @@ -165,16 +179,19 @@ void* tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) { if (pSmaStat) { if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { - tdFreeSmaStatItem(&pSmaStat->tsmaStatItem); + tdFreeTSmaStat(&pSmaStat->tsmaStat); } else if (smaType == TSDB_SMA_TYPE_ROLLUP) { + if (SMA_RSMA_TMR_HANDLE(pSmaStat)) { + taosTmrCleanUp(SMA_RSMA_TMR_HANDLE(pSmaStat)); + } // TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready. - void *infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), NULL); + void *infoHash = taosHashIterate(SMA_RSMA_INFO_HASH(pSmaStat), NULL); while (infoHash) { SRSmaInfo *pInfoHash = *(SRSmaInfo **)infoHash; tdFreeRSmaInfo(pInfoHash); - infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), infoHash); + infoHash = taosHashIterate(SMA_RSMA_INFO_HASH(pSmaStat), infoHash); } - taosHashCleanup(SMA_STAT_INFO_HASH(pSmaStat)); + taosHashCleanup(SMA_RSMA_INFO_HASH(pSmaStat)); } else { ASSERT(0); } @@ -273,4 +290,4 @@ void smaTimerCleanUp(void *timer, int8_t *initFlag) { taosTmrCleanUp(timer); atomic_store_8(initFlag, 0); } -} +} \ No newline at end of file diff --git a/source/dnode/vnode/src/sma/smaOpen.c b/source/dnode/vnode/src/sma/smaOpen.c index a1c47a96c0..383c264e7b 100644 --- a/source/dnode/vnode/src/sma/smaOpen.c +++ b/source/dnode/vnode/src/sma/smaOpen.c @@ -137,4 +137,17 @@ int32_t smaClose(SSma *pSma) { taosMemoryFreeClear(pSma); } return 0; +} + +/** + * @brief rsma env restore + * + * @param pSma + * @return int32_t + */ +int32_t smaRestore(SSma *pSma) { + if (!pSma) return 0; + // iterate all stables to restore the rsma env + + return TSDB_CODE_SUCCESS; } \ No newline at end of file diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 1f18f6cb87..3c2f710fa7 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -16,35 +16,17 @@ #include "sma.h" #include "tstream.h" -static FORCE_INLINE int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); -static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids); -static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *rsmaItem, - tb_uid_t suid, int8_t level); +typedef enum { TD_QTASK_TMP_FILE = 0, TD_QTASK_CUR_FILE } TD_QTASK_FILE_T; +static const char *tdQTaskInfoFname[] = {"qtaskinfo.t", "qtaskinfo"}; -#define SET_RSMA_INFO_ITEM_PARAMS(__idx, __level) \ - if (param->qmsg[__idx]) { \ - pRSmaInfo->items[__idx].pRsmaInfo = pRSmaInfo; \ - pRSmaInfo->items[__idx].taskInfo = qCreateStreamExecTaskInfo(param->qmsg[0], &handle); \ - if (!pRSmaInfo->items[__idx].taskInfo) { \ - goto _err; \ - } \ - pRSmaInfo->items[__idx].triggerStatus = TASK_TRIGGER_STATUS__IN_ACTIVE; \ - if (param->maxdelay[__idx] < 1) { \ - int64_t msInterval = \ - convertTimeFromPrecisionToUnit(pRetention[__level].freq, pTsdbCfg->precision, TIME_UNIT_MILLISECOND); \ - pRSmaInfo->items[__idx].maxDelay = msInterval; \ - } else { \ - pRSmaInfo->items[__idx].maxDelay = param->maxdelay[__idx]; \ - } \ - if (pRSmaInfo->items[__idx].maxDelay > TSDB_MAX_ROLLUP_MAX_DELAY) { \ - pRSmaInfo->items[__idx].maxDelay = TSDB_MAX_ROLLUP_MAX_DELAY; \ - } \ - pRSmaInfo->items[__idx].level = TSDB_RETENTION_L##__level; \ - pRSmaInfo->items[__idx].tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA"); \ - if (!pRSmaInfo->items[__idx].tmrHandle) { \ - goto _err; \ - } \ - } +static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid); +static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids); +static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaInfo *pRSmaInfo, SReadHandle *handle, + int8_t idx); +static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *rsmaItem, + tb_uid_t suid, int8_t level); +static void tdRSmaFetchTrigger(void *param, void *tmrId); +static void tdRSmaPersistTrigger(void *param, void *tmrId); struct SRSmaInfoItem { SRSmaInfo *pRsmaInfo; @@ -56,14 +38,6 @@ struct SRSmaInfoItem { int8_t triggerStatus; // TASK_TRIGGER_STATUS__IN_ACTIVE/TASK_TRIGGER_STATUS__ACTIVE int32_t maxDelay; }; - -typedef struct { - int64_t suid; - SRSmaInfoItem *pItem; - SSma *pSma; - STSchema *pTSchema; -} SRSmaTriggerParam; - struct SRSmaInfo { STSchema *pTSchema; SSma *pSma; @@ -81,7 +55,7 @@ static FORCE_INLINE void tdFreeTaskHandle(qTaskInfo_t *taskHandle) { void *tdFreeRSmaInfo(SRSmaInfo *pInfo) { if (pInfo) { - for (int32_t i = 0; i < TSDB_RETENTION_MAX; ++i) { + for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) { SRSmaInfoItem *pItem = &pInfo->items[i]; if (pItem->taskInfo) { tdFreeTaskHandle(pItem->taskInfo); @@ -118,7 +92,7 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA return TSDB_CODE_FAILED; } - pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t)); + pRSmaInfo = taosHashGet(SMA_RSMA_INFO_HASH(pStat), suid, sizeof(tb_uid_t)); if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { smaError("vgId:%d, failed to get rsma info for uid:%" PRIi64, SMA_VID(pSma), *suid); terrno = TSDB_CODE_RSMA_INVALID_STAT; @@ -187,7 +161,7 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui SSmaStat *pStat = SMA_ENV_STAT(pEnv); SHashObj *infoHash = NULL; - if (!pStat || !(infoHash = SMA_STAT_INFO_HASH(pStat))) { + if (!pStat || !(infoHash = SMA_RSMA_INFO_HASH(pStat))) { terrno = TSDB_CODE_RSMA_INVALID_STAT; return TSDB_CODE_FAILED; } @@ -213,6 +187,40 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui return TSDB_CODE_SUCCESS; } +static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaInfo *pRSmaInfo, SReadHandle *pReadHandle, + int8_t idx) { + SRetention *pRetention = SMA_RETENTION(pSma); + STsdbCfg *pTsdbCfg = SMA_TSDB_CFG(pSma); + + if (param->qmsg[idx]) { + SRSmaInfoItem *pItem = &(pRSmaInfo->items[idx]); + pItem->pRsmaInfo = pRSmaInfo; + pItem->taskInfo = qCreateStreamExecTaskInfo(param->qmsg[0], pReadHandle); + if (!pItem->taskInfo) { + goto _err; + } + pItem->triggerStatus = TASK_TRIGGER_STATUS__IN_ACTIVE; + if (param->maxdelay[idx] < TSDB_MIN_ROLLUP_MAX_DELAY) { + int64_t msInterval = + convertTimeFromPrecisionToUnit(pRetention[idx + 1].freq, pTsdbCfg->precision, TIME_UNIT_MILLISECOND); + pItem->maxDelay = (int32_t)msInterval; + } else { + pItem->maxDelay = (int32_t)param->maxdelay[idx]; + } + if (pItem->maxDelay > TSDB_MAX_ROLLUP_MAX_DELAY) { + pItem->maxDelay = TSDB_MAX_ROLLUP_MAX_DELAY; + } + pItem->level = (idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2); + pItem->tmrHandle = taosTmrInit(10000, 100, 10000, "RSMA"); + if (!pItem->tmrHandle) { + goto _err; + } + } + return TSDB_CODE_SUCCESS; +_err: + return TSDB_CODE_FAILED; +} + /** * @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam. * @@ -246,7 +254,7 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { SSmaStat *pStat = SMA_ENV_STAT(pEnv); SRSmaInfo *pRSmaInfo = NULL; - pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t)); + pRSmaInfo = taosHashGet(SMA_RSMA_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t)); if (pRSmaInfo) { ASSERT(0); // TODO: free original pRSmaInfo is exists abnormally smaWarn("vgId:%d, rsma info already exists for stb: %s, %" PRIi64, SMA_VID(pSma), pReq->name, pReq->suid); @@ -282,14 +290,14 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) { pRSmaInfo->pSma = pSma; pRSmaInfo->suid = pReq->suid; - SRetention *pRetention = SMA_RETENTION(pSma); - STsdbCfg *pTsdbCfg = SMA_TSDB_CFG(pSma); + if (tdSetRSmaInfoItemParams(pSma, param, pRSmaInfo, &handle, 0) < 0) { + goto _err; + } + if (tdSetRSmaInfoItemParams(pSma, param, pRSmaInfo, &handle, 1) < 0) { + goto _err; + } - SET_RSMA_INFO_ITEM_PARAMS(0, 1); - SET_RSMA_INFO_ITEM_PARAMS(1, 2); - - if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) != - TSDB_CODE_SUCCESS) { + if (taosHashPut(SMA_RSMA_INFO_HASH(pStat), &pReq->suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) < 0) { goto _err; } else { smaDebug("vgId:%d, register rsma info succeed for suid:%" PRIi64, SMA_VID(pSma), pReq->suid); @@ -418,7 +426,6 @@ static int32_t tdFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) { if (!pBlock) break; tdUidStorePut(pStore, msgIter.suid, NULL); - pStore->uid = msgIter.uid; // TODO: remove, just for debugging } if (terrno != TSDB_CODE_SUCCESS) return -1; @@ -439,8 +446,9 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) if (!output) { break; } + if (!pResult) { - pResult = taosArrayInit(0, sizeof(SSDataBlock)); + pResult = taosArrayInit(1, sizeof(SSDataBlock)); if (!pResult) { terrno = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_FAILED; @@ -451,7 +459,7 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) } if (taosArrayGetSize(pResult) > 0) { -#if 0 +#if 1 char flag[10] = {0}; snprintf(flag, 10, "level %" PRIi8, pItem->level); blockDebugShowData(pResult, flag); @@ -459,14 +467,12 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb1 : pSma->pRSmaTsdb2); SSubmitReq *pReq = NULL; if (buildSubmitReqFromDataBlock(&pReq, pResult, pRSmaInfo->pTSchema, SMA_VID(pSma), pRSmaInfo->suid) < 0) { - taosArrayDestroy(pResult); - return TSDB_CODE_FAILED; + goto _err; } if (pReq && tdProcessSubmitReq(sinkTsdb, INT64_MAX, pReq) < 0) { - taosArrayDestroy(pResult); taosMemoryFreeClear(pReq); - return TSDB_CODE_FAILED; + goto _err; } taosMemoryFreeClear(pReq); @@ -479,7 +485,10 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) } taosArrayDestroy(pResult); - return 0; + return TSDB_CODE_SUCCESS; +_err: + taosArrayDestroy(pResult); + return TSDB_CODE_FAILED; } /** @@ -488,13 +497,12 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType) * @param param * @param tmrId */ -static void rsmaTriggerByTimer(void *param, void *tmrId) { - // SRSmaTriggerParam *pParam = (SRSmaTriggerParam *)param; - // SRSmaInfoItem *pItem = pParam->pItem; +static void tdRSmaFetchTrigger(void *param, void *tmrId) { SRSmaInfoItem *pItem = param; if (atomic_load_8(&pItem->triggerStatus) == TASK_TRIGGER_STATUS__ACTIVE) { - smaTrace("level %" PRIi8 " status is active for tb suid:%" PRIi64, pItem->level, pItem->pRsmaInfo->suid); + smaWarn("%s:%d THREAD:%" PRIi64 " level %" PRIi8 " status is active for tb suid:%" PRIi64, __func__, __LINE__, + taosGetSelfPthreadId(), pItem->level, pItem->pRsmaInfo->suid); SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; atomic_store_8(&pItem->triggerStatus, TASK_TRIGGER_STATUS__IN_ACTIVE); @@ -502,10 +510,11 @@ static void rsmaTriggerByTimer(void *param, void *tmrId) { tdFetchAndSubmitRSmaResult(pItem, STREAM_DATA_TYPE_SSDATA_BLOCK); } else { - smaTrace("level %" PRIi8 " status is inactive for tb suid:%" PRIi64, pItem->level, pItem->pRsmaInfo->suid); + smaWarn("%s:%d THREAD:%" PRIi64 " level %" PRIi8 " status is inactive for tb suid:%" PRIi64, __func__, __LINE__, + taosGetSelfPthreadId(), pItem->level, pItem->pRsmaInfo->suid); } - // taosTmrReset(rsmaTriggerByTimer, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); + // taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); } static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType, SRSmaInfoItem *pItem, @@ -518,16 +527,20 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3 smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, pItem->taskInfo, suid); - // inputType = STREAM_DATA_TYPE_SUBMIT_BLOCK(1) - if (qSetStreamInput(pItem->taskInfo, pMsg, inputType, true) < 0) { + if (qSetStreamInput(pItem->taskInfo, pMsg, inputType, true) < 0) { // STREAM_DATA_TYPE_SUBMIT_BLOCK smaError("vgId:%d, rsma % " PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno)); return TSDB_CODE_FAILED; } - // SRSmaTriggerParam triggerParam = {.suid = suid, .pItem = pItem, .pSma = pSma, .pTSchema = pTSchema}; tdFetchAndSubmitRSmaResult(pItem, STREAM_DATA_TYPE_SUBMIT_BLOCK); atomic_store_8(&pItem->triggerStatus, TASK_TRIGGER_STATUS__ACTIVE); - taosTmrReset(rsmaTriggerByTimer, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); + smaWarn("%s:%d THREAD:%" PRIi64 " process rsma insert", __func__, __LINE__, taosGetSelfPthreadId()); + + SSmaEnv *pEnv = SMA_RSMA_ENV(pSma); + SRSmaStat *pStat = SMA_RSMA_STAT(pEnv->pStat); + + taosTmrStart(tdRSmaPersistTrigger, 5000, pStat, pStat->tmrHandle); + taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId); return TSDB_CODE_SUCCESS; } @@ -542,7 +555,7 @@ static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb SSmaStat *pStat = SMA_ENV_STAT(pEnv); SRSmaInfo *pRSmaInfo = NULL; - pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &suid, sizeof(tb_uid_t)); + pRSmaInfo = taosHashGet(SMA_RSMA_INFO_HASH(pStat), &suid, sizeof(tb_uid_t)); if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) { smaDebug("vgId:%d, return as no rsma info for suid:%" PRIu64, SMA_VID(pSma), suid); @@ -594,3 +607,106 @@ int32_t tdProcessRSmaSubmit(SSma *pSma, void *pMsg, int32_t inputType) { } return TSDB_CODE_SUCCESS; } + +void tdRSmaQTaskGetFName(int32_t vid, int8_t ftype, char* outputName) { + tdGetVndFileName(vid, "rsma", tdQTaskInfoFname[ftype], outputName); +} + +static void *tdRSmaPersistExec(void *param) { + setThreadName("rsma-task-persist"); + SRSmaStat *pRSmaStat = param; + SSma *pSma = pRSmaStat->pSma; + STfs *pTfs = pSma->pVnode->pTfs; + int64_t toffset = 0; + + void *infoHash = taosHashIterate(RSMA_INFO_HASH(pRSmaStat), NULL); + if (!infoHash) { + goto _end; + } + + STFile tFile = {0}; + int32_t vid = 2; + char qTaskInfoFName[TSDB_FILENAME_LEN]; + tdRSmaQTaskGetFName(vid, TD_QTASK_TMP_FILE, qTaskInfoFName); + tdInitTFile(&tFile, pTfs, qTaskInfoFName); + tdCreateTFile(&tFile, pTfs, true, -1); + + while (infoHash) { + SRSmaInfo *pRSmaInfo = *(SRSmaInfo **)infoHash; + char *pOutput = NULL; + int32_t len = 0; + if (qSerializeTaskStatus(pRSmaInfo->items[0].taskInfo, &pOutput, &len) < 0) { + smaError("serialize rsma task for table %" PRIi64 " failed since %s", pRSmaInfo->items[0].pRsmaInfo->suid, + terrstr(terrno)); + } else { + smaWarn("serialize rsma task for table %" PRIi64 " success and len is %d", pRSmaInfo->items[0].pRsmaInfo->suid, + len); + } + tdAppendTFile(&tFile, &len, sizeof(len), &toffset); + tdAppendTFile(&tFile, pOutput, len, &toffset); + + taosMemoryFree(pOutput); + infoHash = taosHashIterate(RSMA_INFO_HASH(pRSmaStat), infoHash); + } +_end: + + if (tdUpdateTFileHeader(&tFile) < 0) { + smaError("vgId:%d, failed to update tfile %s header since %s", vid, TD_FILE_FULL_NAME(&tFile), tstrerror(terrno)); + tdCloseTFile(&tFile); + tdRemoveTFile(&tFile); + return NULL; + } + + tdCloseTFile(&tFile); + + char newFName[TSDB_FILENAME_LEN]; + strncpy(newFName, TD_FILE_FULL_NAME(&tFile), TSDB_FILENAME_LEN); + char *pos = strstr(newFName, tdQTaskInfoFname[TD_QTASK_TMP_FILE]); + strncpy(pos, tdQTaskInfoFname[TD_QTASK_CUR_FILE], TSDB_FILENAME_LEN - POINTER_DISTANCE(pos, newFName)); + taosRenameFile(TD_FILE_FULL_NAME(&tFile), newFName); + + atomic_store_8(&pRSmaStat->tmrStat, TASK_TRIGGER_STATUS__ACTIVE); + return NULL; +_err: + atomic_store_8(&pRSmaStat->tmrStat, TASK_TRIGGER_STATUS__ACTIVE); + // remove the .tmp file + return NULL; +} + +static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) { + smaWarn("%s:%d entry ", __func__, __LINE__); + TdThread threadId; + TdThreadAttr thAttr; + taosThreadAttrInit(&thAttr); + taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_DETACHED); + + if (taosThreadCreate(&threadId, &thAttr, tdRSmaPersistExec, pRSmaStat) != 0) { + smaError("failed to create thread to persist rsma qTaskInfo since %s", strerror(errno)); + } + + taosThreadAttrDestroy(&thAttr); + smaWarn("%s:%d end ", __func__, __LINE__); +} + +/** + * @brief trigger to persist rsma qTaskInfo + * + * @param param + * @param tmrId + */ +static void tdRSmaPersistTrigger(void *param, void *tmrId) { + SRSmaStat *pRSmaStat = param; + + if (atomic_load_8(&pRSmaStat->tmrStat) == TASK_TRIGGER_STATUS__ACTIVE) { + smaWarn("%s:%d THREAD:%" PRIi64 " rsma persistence start since active", __func__, __LINE__, taosGetSelfPthreadId()); + atomic_store_8(&pRSmaStat->tmrStat, TASK_TRIGGER_STATUS__IN_ACTIVE); + + // execution + tdRSmaPersistTask(pRSmaStat); + } else { + smaWarn("%s:%d THREAD:%" PRIi64 " rsma persistence not start since inactive", __func__, __LINE__, + taosGetSelfPthreadId()); + } + + taosTmrReset(tdRSmaPersistTrigger, 3600000, pRSmaStat, pRSmaStat->tmrHandle, &pRSmaStat->tmrId); +} \ No newline at end of file diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index 4352c466c5..2244b91c28 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -129,7 +129,7 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) { SSmaEnv *pEnv = SMA_TSMA_ENV(pSma); SSmaStat *pStat = NULL; - SSmaStatItem *pItem = NULL; + STSmaStat *pItem = NULL; if (!pEnv || !(pStat = SMA_ENV_STAT(pEnv))) { terrno = TSDB_CODE_TSMA_INVALID_STAT; @@ -137,7 +137,7 @@ int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) { } tdRefSmaStat(pSma, pStat); - pItem = &pStat->tsmaStatItem; + pItem = &pStat->tsmaStat; ASSERT(pItem); diff --git a/source/dnode/vnode/src/sma/smaUtil.c b/source/dnode/vnode/src/sma/smaUtil.c new file mode 100644 index 0000000000..76690a3bde --- /dev/null +++ b/source/dnode/vnode/src/sma/smaUtil.c @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "sma.h" + +#define TD_FILE_HEAD_SIZE 512 + +#define TD_FILE_STATE_OK 0 +#define TD_FILE_STATE_BAD 1 + +#define TD_FILE_INIT_MAGIC 0xFFFFFFFF + + +static int32_t tdEncodeTFInfo(void **buf, STFInfo *pInfo); +static void *tdDecodeTFInfo(void *buf, STFInfo *pInfo); + +static int32_t tdEncodeTFInfo(void **buf, STFInfo *pInfo) { + int32_t tlen = 0; + + tlen += taosEncodeFixedU32(buf, pInfo->magic); + tlen += taosEncodeFixedU32(buf, pInfo->ftype); + tlen += taosEncodeFixedU32(buf, pInfo->fver); + tlen += taosEncodeFixedU64(buf, pInfo->fsize); + + return tlen; +} + +static void *tdDecodeTFInfo(void *buf, STFInfo *pInfo) { + buf = taosDecodeFixedU32(buf, &(pInfo->magic)); + buf = taosDecodeFixedU32(buf, &(pInfo->ftype)); + buf = taosDecodeFixedU32(buf, &(pInfo->fver)); + buf = taosDecodeFixedU64(buf, &(pInfo->fsize)); + return buf; +} + +int64_t tdWriteTFile(STFile *pTFile, void *buf, int64_t nbyte) { + ASSERT(TD_FILE_OPENED(pTFile)); + + int64_t nwrite = taosWriteFile(pTFile->pFile, buf, nbyte); + if (nwrite < nbyte) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return nwrite; +} + +int64_t tdSeekTFile(STFile *pTFile, int64_t offset, int whence) { + ASSERT(TD_FILE_OPENED(pTFile)); + + int64_t loffset = taosLSeekFile(TD_FILE_PFILE(pTFile), offset, whence); + if (loffset < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return loffset; +} + +int64_t tdReadTFile(STFile *pTFile, void *buf, int64_t nbyte) { + ASSERT(TD_FILE_OPENED(pTFile)); + + int64_t nread = taosReadFile(pTFile->pFile, buf, nbyte); + if (nread < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return nread; +} + +int32_t tdUpdateTFileHeader(STFile *pTFile) { + char buf[TD_FILE_HEAD_SIZE] = "\0"; + + if (tdSeekTFile(pTFile, 0, SEEK_SET) < 0) { + return -1; + } + + void *ptr = buf; + tdEncodeTFInfo(&ptr, &(pTFile->info)); + + taosCalcChecksumAppend(0, (uint8_t *)buf, TD_FILE_HEAD_SIZE); + if (tdWriteTFile(pTFile, buf, TD_FILE_HEAD_SIZE) < 0) { + return -1; + } + + return 0; +} + +int32_t tdLoadTFileHeader(STFile *pTFile, STFInfo *pInfo) { + char buf[TD_FILE_HEAD_SIZE] = "\0"; + uint32_t _version; + + ASSERT(TD_FILE_OPENED(pTFile)); + + if (tdSeekTFile(pTFile, 0, SEEK_SET) < 0) { + return -1; + } + + if (tdReadTFile(pTFile, buf, TD_FILE_HEAD_SIZE) < 0) { + return -1; + } + + if (!taosCheckChecksumWhole((uint8_t *)buf, TD_FILE_HEAD_SIZE)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + void *pBuf = buf; + pBuf = tdDecodeTFInfo(pBuf, pInfo); + return 0; +} + +void tdUpdateTFileMagic(STFile *pTFile, void *pCksm) { + pTFile->info.magic = taosCalcChecksum(pTFile->info.magic, (uint8_t *)(pCksm), sizeof(TSCKSUM)); +} + +int64_t tdAppendTFile(STFile *pTFile, void *buf, int64_t nbyte, int64_t *offset) { + ASSERT(TD_FILE_OPENED(pTFile)); + + int64_t toffset; + + if ((toffset = tdSeekTFile(pTFile, 0, SEEK_END)) < 0) { + return -1; + } + + ASSERT(pTFile->info.fsize == toffset); + + if (offset) { + *offset = toffset; + } + + if (tdWriteTFile(pTFile, buf, nbyte) < 0) { + return -1; + } + + pTFile->info.fsize += nbyte; + + return nbyte; +} + +int32_t tdOpenTFile(STFile *pTFile, int flags) { + ASSERT(!TD_FILE_OPENED(pTFile)); + + pTFile->pFile = taosOpenFile(TD_FILE_FULL_NAME(pTFile), flags); + if (pTFile->pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + +void tdCloseTFile(STFile *pTFile) { + if (TD_FILE_OPENED(pTFile)) { + taosCloseFile(&pTFile->pFile); + TD_FILE_SET_CLOSED(pTFile); + } +} + +void tdGetVndFileName(int32_t vid, const char *dname, const char *fname, char *outputName) { + snprintf(outputName, TSDB_FILENAME_LEN, "vnode/vnode%d/%s/%s", vid, dname, fname); +} + +int32_t tdInitTFile(STFile *pTFile, STfs *pTfs, const char *fname) { + char fullname[TSDB_FILENAME_LEN]; + SDiskID did = {0}; + + TD_FILE_SET_STATE(pTFile, TD_FILE_STATE_OK); + TD_FILE_SET_CLOSED(pTFile); + + memset(&(pTFile->info), 0, sizeof(pTFile->info)); + pTFile->info.magic = TD_FILE_INIT_MAGIC; + + if (tfsAllocDisk(pTfs, 0, &did) < 0) { + terrno = TSDB_CODE_NO_AVAIL_DISK; + return -1; + } + + tfsInitFile(pTfs, &(pTFile->f), did, fname); + + return 0; +} + +int32_t tdCreateTFile(STFile *pTFile, STfs *pTfs, bool updateHeader, int8_t fType) { + ASSERT(pTFile->info.fsize == 0 && pTFile->info.magic == TD_FILE_INIT_MAGIC); + + pTFile->pFile = taosOpenFile(TD_FILE_FULL_NAME(pTFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); + if (pTFile->pFile == NULL) { + if (errno == ENOENT) { + // Try to create directory recursively + char *s = strdup(TD_FILE_REL_NAME(pTFile)); + if (tfsMkdirRecurAt(pTfs, taosDirName(s), TD_FILE_DID(pTFile)) < 0) { + taosMemoryFreeClear(s); + return -1; + } + taosMemoryFreeClear(s); + + pTFile->pFile = taosOpenFile(TD_FILE_FULL_NAME(pTFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); + if (pTFile->pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } else { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + if (!updateHeader) { + return 0; + } + + pTFile->info.fsize += TD_FILE_HEAD_SIZE; + pTFile->info.fver = 0; + + if (tdUpdateTFileHeader(pTFile) < 0) { + tdCloseTFile(pTFile); + tdRemoveTFile(pTFile); + return -1; + } + + return 0; +} + +int32_t tdRemoveTFile(STFile *pTFile) { return tfsRemoveFile(TD_FILE_F(pTFile)); } \ No newline at end of file diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 3ce02dc50a..cca3a58588 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -227,19 +227,16 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { consumerEpoch = atomic_val_compare_exchange_32(&pHandle->epoch, consumerEpoch, reqEpoch); } - SWalHead* pHeadWithCkSum = taosMemoryMalloc(sizeof(SWalHead) + 2048); - if (pHeadWithCkSum == NULL) { - return -1; - } - - walSetReaderCapacity(pHandle->pWalReader, 2048); - SMqDataBlkRsp rsp = {0}; rsp.reqOffset = pReq->currentOffset; rsp.blockData = taosArrayInit(0, sizeof(void*)); rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t)); + if (rsp.blockData == NULL || rsp.blockDataLen == NULL) { + return -1; + } + rsp.withTbName = pReq->withTbName; if (rsp.withTbName) { rsp.blockTbName = taosArrayInit(0, sizeof(void*)); @@ -253,6 +250,32 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { rsp.blockSchema = taosArrayInit(0, sizeof(void*)); } +#if 1 + if (pReq->useSnapshot) { + // TODO set ver into snapshot + int64_t lastVer = walGetCommittedVer(pTq->pWal); + if (rsp.reqOffset < lastVer) { + tqInfo("retrieve using snapshot req offset %ld last ver %ld", rsp.reqOffset, lastVer); + tqScanSnapshot(pTq, &pHandle->execHandle, &rsp, workerId); + + if (rsp.blockNum != 0) { + rsp.withTbName = false; + rsp.rspOffset = lastVer; + tqInfo("direct send by snapshot req offset %ld rsp offset %ld", rsp.reqOffset, rsp.rspOffset); + fetchOffset = lastVer; + goto SEND_RSP; + } + } + } +#endif + + SWalHead* pHeadWithCkSum = taosMemoryMalloc(sizeof(SWalHead) + 2048); + if (pHeadWithCkSum == NULL) { + return -1; + } + + walSetReaderCapacity(pHandle->pWalReader, 2048); + while (1) { consumerEpoch = atomic_load_32(&pHandle->epoch); if (consumerEpoch > reqEpoch) { @@ -283,7 +306,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { pHead->msgType == TDMT_VND_DROP_STB || pHead->msgType == TDMT_VND_CREATE_TABLE || pHead->msgType == TDMT_VND_ALTER_TABLE || pHead->msgType == TDMT_VND_DROP_TABLE || pHead->msgType == TDMT_VND_DROP_TTL_TABLE); - // return + tqInfo("fetch meta msg, ver: %ld, type: %d", pHead->version, pHead->msgType); SMqMetaRsp metaRsp = {0}; metaRsp.reqOffset = pReq->currentOffset; metaRsp.rspOffset = fetchOffset; @@ -292,6 +315,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { metaRsp.metaRsp = pHead->body; if (tqSendMetaPollRsp(pTq, pMsg, pReq, &metaRsp) < 0) { code = -1; + goto OVER; } code = 0; goto OVER; @@ -308,6 +332,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { taosMemoryFree(pHeadWithCkSum); +SEND_RSP: ASSERT(taosArrayGetSize(rsp.blockData) == rsp.blockNum); ASSERT(taosArrayGetSize(rsp.blockDataLen) == rsp.blockNum); if (rsp.withSchema) { @@ -364,6 +389,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { pHandle->epoch = -1; pHandle->execHandle.subType = req.subType; + pHandle->fetchMeta = req.withMeta; pHandle->pWalReader = walOpenReadHandle(pTq->pVnode->pWal); for (int32_t i = 0; i < 5; i++) { @@ -376,6 +402,8 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { SReadHandle handle = { .reader = pHandle->execHandle.pExecReader[i], .meta = pTq->pVnode->pMeta, + .vnode = pTq->pVnode, + .initTsdbReader = 1, }; pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle); ASSERT(pHandle->execHandle.execCol.task[i]); @@ -426,6 +454,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { ASSERT(0); } tDecoderClear(&decoder); + ASSERT(pTask->isDataScan == 0 || pTask->isDataScan == 1); pTask->execStatus = TASK_EXEC_STATUS__IDLE; @@ -441,12 +470,13 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { // exec if (pTask->execType != TASK_EXEC__NONE) { // expand runners - if (pTask->dataScan) { + if (pTask->isDataScan) { STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); SReadHandle handle = { .reader = pStreamReader, .meta = pTq->pVnode->pMeta, .vnode = pTq->pVnode, + .initTsdbReader = 1, }; /*pTask->exec.inputHandle = pStreamReader;*/ pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); @@ -476,7 +506,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { streamSetupTrigger(pTask); - tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->childId, TD_VID(pTq->pVnode)); + tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->selfChildId, TD_VID(pTq->pVnode)); taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*)); @@ -505,7 +535,7 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) { if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) { continue; } - if (pTask->inputType != STREAM_INPUT__DATA_SUBMIT) continue; + if (!pTask->isDataScan) continue; if (!failed) { if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) { @@ -616,3 +646,29 @@ int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen) { return code; #endif } + +int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) { + char* msgStr = pMsg->pCont; + char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + SStreamRetrieveReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + tDecodeStreamRetrieveReq(&decoder, &req); + int32_t taskId = req.dstTaskId; + SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + return 0; + } + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessRetrieveReq(pTask, &req, &rsp); + return 0; +} + +int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg) { + // + return 0; +} diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c index 7c75d88a83..be8fef1249 100644 --- a/source/dnode/vnode/src/tq/tqExec.c +++ b/source/dnode/vnode/src/tq/tqExec.c @@ -29,7 +29,7 @@ static int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataBlkRsp* pRs // TODO enable compress int32_t actualLen = 0; - blockCompressEncode(pBlock, pRetrieve->data, &actualLen, pBlock->info.numOfCols, false); + blockCompressEncode(pBlock, pRetrieve->data, &actualLen, taosArrayGetSize(pBlock->pDataBlock), false); actualLen += sizeof(SRetrieveTableRsp); ASSERT(actualLen <= dataStrLen); taosArrayPush(pRsp->blockDataLen, &actualLen); @@ -60,6 +60,31 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, const STqExecHandle* pExec, SMqD return 0; } +int32_t tqScanSnapshot(STQ* pTq, const STqExecHandle* pExec, SMqDataBlkRsp* pRsp, int32_t workerId) { + ASSERT(pExec->subType == TOPIC_SUB_TYPE__COLUMN); + qTaskInfo_t task = pExec->execCol.task[workerId]; + if (qStreamScanSnapshot(task) < 0) { + ASSERT(0); + } + // set version + while (1) { + SSDataBlock* pDataBlock = NULL; + uint64_t ts = 0; + if (qExecTask(task, &pDataBlock, &ts) < 0) { + ASSERT(0); + } + if (pDataBlock == NULL) break; + + ASSERT(pDataBlock->info.rows != 0); + ASSERT(taosArrayGetSize(pDataBlock->pDataBlock) != 0); + + tqAddBlockDataToRsp(pDataBlock, pRsp); + pRsp->blockNum++; + } + + return 0; +} + int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkRsp* pRsp, int32_t workerId) { if (pExec->subType == TOPIC_SUB_TYPE__COLUMN) { qTaskInfo_t task = pExec->execCol.task[workerId]; @@ -74,7 +99,6 @@ int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkR if (pDataBlock == NULL) break; ASSERT(pDataBlock->info.rows != 0); - ASSERT(pDataBlock->info.numOfCols != 0); tqAddBlockDataToRsp(pDataBlock, pRsp); if (pRsp->withTbName) { @@ -88,8 +112,7 @@ int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkR tqReadHandleSetMsg(pReader, pReq, 0); while (tqNextDataBlock(pReader)) { SSDataBlock block = {0}; - if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows, - &block.info.numOfCols) < 0) { + if (tqRetrieveDataBlock(&block, pReader, &block.info.groupId, &block.info.uid, &block.info.rows) < 0) { if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue; ASSERT(0); } @@ -106,8 +129,7 @@ int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkR tqReadHandleSetMsg(pReader, pReq, 0); while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) { SSDataBlock block = {0}; - if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows, - &block.info.numOfCols) < 0) { + if (tqRetrieveDataBlock(&block, pReader, &block.info.groupId, &block.info.uid, &block.info.rows) < 0) { if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue; ASSERT(0); } diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index e5475d7c30..e536e87032 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -44,6 +44,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) { } char* fname = buildFileName(pStore->pTq->path); TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ); + taosMemoryFree(fname); if (pFile != NULL) { STqOffsetHead head = {0}; int64_t code; @@ -77,7 +78,6 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) { } taosCloseFile(&pFile); - taosMemoryFree(fname); } return pStore; } @@ -102,6 +102,7 @@ int32_t tqOffsetSnapshot(STqOffsetStore* pStore) { // TODO file name should be with a version char* fname = buildFileName(pStore->pTq->path); TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); + taosMemoryFree(fname); if (pFile == NULL) { ASSERT(0); return -1; @@ -140,6 +141,5 @@ int32_t tqOffsetSnapshot(STqOffsetStore* pStore) { } // close and rename file taosCloseFile(&pFile); - taosMemoryFree(fname); return 0; } diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 6f44eb4569..0243f2a9f0 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -142,15 +142,15 @@ bool tqNextDataBlockFilterOut(STqReadHandle* pHandle, SHashObj* filterOutUids) { return false; } -int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* pGroupId, uint64_t* pUid, - int32_t* pNumOfRows, int16_t* pNumOfCols) { +int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReadHandle* pHandle, uint64_t* pGroupId, uint64_t* pUid, + int32_t* pNumOfRows) { *pUid = 0; - // TODO set to real sversion - /*int32_t sversion = 1;*/ + // TODO: cache multiple schema int32_t sversion = htonl(pHandle->pBlock->sversion); if (pHandle->cachedSchemaSuid == 0 || pHandle->cachedSchemaVer != sversion || pHandle->cachedSchemaSuid != pHandle->msgIter.suid) { + if (pHandle->pSchema) taosMemoryFree(pHandle->pSchema); pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion); if (pHandle->pSchema == NULL) { tqWarn("cannot found tsschema for table: uid: %ld (suid: %ld), version %d, possibly dropped table", @@ -160,7 +160,7 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p return -1; } - // this interface use suid instead of uid + if (pHandle->pSchemaWrapper) tDeleteSSchemaWrapper(pHandle->pSchemaWrapper); pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion, true); if (pHandle->pSchemaWrapper == NULL) { tqWarn("cannot found schema wrapper for table: suid: %ld, version %d, possibly dropped table", @@ -180,23 +180,14 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList); if (colNumNeed == 0) { - *ppCols = taosArrayInit(pSchemaWrapper->nCols, sizeof(SColumnInfoData)); - if (*ppCols == NULL) { - return -1; - } - int32_t colMeta = 0; while (colMeta < pSchemaWrapper->nCols) { SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta]; - SColumnInfoData colInfo = {0}; - colInfo.info.bytes = pColSchema->bytes; - colInfo.info.colId = pColSchema->colId; - colInfo.info.type = pColSchema->type; - - if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) { + SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId); + int32_t code = blockDataAppendColInfo(pBlock, &colInfo); + if (code != TSDB_CODE_SUCCESS) { goto FAIL; } - taosArrayPush(*ppCols, &colInfo); colMeta++; } } else { @@ -204,11 +195,6 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p colNumNeed = pSchemaWrapper->nCols; } - *ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData)); - if (*ppCols == NULL) { - return -1; - } - int32_t colMeta = 0; int32_t colNeed = 0; while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) { @@ -220,23 +206,22 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p } else if (colIdSchema > colIdNeed) { colNeed++; } else { - SColumnInfoData colInfo = {0}; - colInfo.info.bytes = pColSchema->bytes; - colInfo.info.colId = pColSchema->colId; - colInfo.info.type = pColSchema->type; - - if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) { + SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId); + int32_t code = blockDataAppendColInfo(pBlock, &colInfo); + if (code != TSDB_CODE_SUCCESS) { goto FAIL; } - taosArrayPush(*ppCols, &colInfo); colMeta++; colNeed++; } } } - int32_t colActual = taosArrayGetSize(*ppCols); - *pNumOfCols = colActual; + if (blockDataEnsureCapacity(pBlock, *pNumOfRows) < 0) { + goto FAIL; + } + + int32_t colActual = blockDataGetNumOfCols(pBlock); // TODO in stream shuffle case, fetch groupId *pGroupId = 0; @@ -253,7 +238,7 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p tdSTSRowIterReset(&iter, row); // get all wanted col of that block for (int32_t i = 0; i < colActual; i++) { - SColumnInfoData* pColData = taosArrayGet(*ppCols, i); + SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i); SCellVal sVal = {0}; if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; @@ -265,8 +250,9 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p curRow++; } return 0; -FAIL: - if (*ppCols) taosArrayDestroy(*ppCols); + +FAIL: // todo refactor here + // if (*ppCols) taosArrayDestroy(*ppCols); return -1; } @@ -345,8 +331,8 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) { while (1) { pIter = taosHashIterate(pTq->pStreamTasks, pIter); if (pIter == NULL) break; - SStreamTask* pTask = (SStreamTask*)pIter; - if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { + SStreamTask* pTask = *(SStreamTask**)pIter; + if (pTask->isDataScan) { int32_t code = qUpdateQualifiedTableId(pTask->exec.executor, tbUidList, isAdd); ASSERT(code == 0); } diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index 83059e3646..ef3b205b3e 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -44,7 +44,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo createTbReq.ctb.suid = suid; STagVal tagVal = { - .cid = pDataBlock->info.numOfCols + 1, + .cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1, .type = TSDB_DATA_TYPE_UBIGINT, .i64 = (int64_t)pDataBlock->info.groupId, }; @@ -92,9 +92,8 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo blkHead->uid = 0; int32_t rows = pDataBlock->info.rows; - /*int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);*/ - /*blkHead->dataLen = htonl(rows * maxLen);*/ - blkHead->dataLen = 0; + + int32_t dataLen = 0; void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk)); @@ -108,7 +107,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo createTbReq.ctb.suid = suid; STagVal tagVal = { - .cid = pDataBlock->info.numOfCols + 1, + .cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1, .type = TSDB_DATA_TYPE_UBIGINT, .i64 = (int64_t)pDataBlock->info.groupId, }; @@ -167,9 +166,8 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo } int32_t rowLen = TD_ROW_LEN(rowData); rowData = POINTER_SHIFT(rowData, rowLen); - blkHead->dataLen += rowLen; + dataLen += rowLen; } - int32_t dataLen = blkHead->dataLen; blkHead->dataLen = htonl(dataLen); ret->length += sizeof(SSubmitBlk) + schemaLen + dataLen; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 19d7c2b03d..e16360a58b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -16,13 +16,11 @@ #include "tsdb.h" #include "vnode.h" -#define EXTRA_BYTES 2 #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) -#define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pColumns))) +#define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pResBlock->pDataBlock))) #define GET_FILE_DATA_BLOCK_INFO(_checkInfo, _block) \ ((SDataBlockInfo){.window = {.skey = (_block)->minKey.ts, .ekey = (_block)->maxKey.ts}, \ - .numOfCols = (_block)->numOfCols, \ .rows = (_block)->numOfRows, \ .uid = (_checkInfo)->tableId}) @@ -115,7 +113,8 @@ typedef struct STsdbReadHandle { // SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time // SColumnDataAgg** pstatis;// the ptr array list to return to caller int32_t numOfBlocks; - SArray* pColumns; // column list, SColumnInfoData array list + SSDataBlock* pResBlock; +// SArray* pColumns; // column list, SColumnInfoData array list bool locateStart; int32_t outputCapacity; int32_t realNumOfRows; @@ -177,7 +176,7 @@ static SArray* getColumnIdList(STsdbReadHandle* pTsdbReadHandle) { SArray* pIdList = taosArrayInit(numOfCols, sizeof(int16_t)); for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); taosArrayPush(pIdList, &pCol->info.colId); } @@ -425,23 +424,21 @@ static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond* } // todo: use list instead of array? - pReadHandle->pColumns = taosArrayInit(pCond->numOfCols, sizeof(SColumnInfoData)); - if (pReadHandle->pColumns == NULL) { + pReadHandle->pResBlock = createDataBlock(); + if (pReadHandle->pResBlock == NULL) { goto _end; } for (int32_t i = 0; i < pCond->numOfCols; ++i) { - SColumnInfoData colInfo = {{0}, 0}; - colInfo.info = pCond->colList[i]; - - int32_t code = colInfoDataEnsureCapacity(&colInfo, 0, pReadHandle->outputCapacity); - if (code != TSDB_CODE_SUCCESS) { + SColumnInfoData colInfo = {.info = pCond->colList[i], 0}; + int32_t code = blockDataAppendColInfo(pReadHandle->pResBlock, &colInfo); + if (code != TSDB_CODE_SUCCESS){ goto _end; } - - taosArrayPush(pReadHandle->pColumns, &colInfo); } + blockDataEnsureCapacity(pReadHandle->pResBlock, pReadHandle->outputCapacity); + pReadHandle->suppInfo.defaultLoadColumn = getDefaultLoadColumns(pReadHandle, true); size_t size = taosArrayGetSize(pReadHandle->suppInfo.defaultLoadColumn); @@ -1536,12 +1533,12 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t int32_t trueEnd = ascScan ? end : start; int32_t step = ascScan ? 1 : -1; - int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); + int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); // data in buffer has greater timestamp, copy data in file block int32_t i = 0, j = 0; while (i < requiredNumOfCols && j < pCols->numOfCols) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); SDataCol* src = &pCols->cols[j]; if (src->colId < pColInfo->info.colId) { @@ -1592,7 +1589,7 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t } while (i < requiredNumOfCols) { // the remain columns are all null data - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); colDataAppendNNULL(pColInfo, numOfRows, num); i++; } @@ -1674,7 +1671,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa int32_t i = 0, j = 0, k = 0; while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); int32_t colIdOfRow1; if (j >= numOfColsOfRow1) { @@ -1805,7 +1802,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa if (mergeOption == 1) { while (i < numOfCols) { // the remain columns are all null data - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); colDataAppend(pColInfo, *curRow, NULL, true); ++i; } @@ -1861,7 +1858,7 @@ static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle) { assert(cur->win.skey >= pTsdbReadHandle->window.ekey && cur->win.ekey <= pTsdbReadHandle->window.skey); } - SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, 0); + SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, 0); assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows - 1]); } else { @@ -2771,7 +2768,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int STsdbReadHandle* pTsdbReadHandle) { int numOfRows = 0; int curRows = 0; - int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); + int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb); win->skey = TSKEY_INITIAL_VAL; @@ -2845,7 +2842,7 @@ int32_t tsdbGetAllTableList(SMeta* pMeta, uint64_t uid, SArray* list) { break; } - STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id}; + STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id, .groupId = 0}; taosArrayPush(list, &info); } @@ -2901,7 +2898,7 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { if (exists) { tsdbRetrieveDataBlock((tsdbReaderT*)pTsdbReadHandle, NULL); if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, 0); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, 0); assert(*(int64_t*)pColInfo->pData == pTsdbReadHandle->window.skey); } @@ -3003,7 +3000,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // // int32_t i = 0, j = 0; // while(i < tgNumOfCols && j < numOfCols) { -// pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); +// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); // if (pTable->lastCols[j].colId < pColInfo->info.colId) { // j++; // continue; @@ -3066,7 +3063,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // continue; // } // -// pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, n); +// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, n); // pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;; // // if (pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { @@ -3091,7 +3088,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // // // leave the real ts column as the last row, because last function only (not stable) use the last row as res // if (priKey != TSKEY_INITIAL_VAL) { -// pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, priIdx); +// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, priIdx); // pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes; // // *(TSKEY *)pData = priKey; @@ -3101,7 +3098,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // continue; // } // -// pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, n); +// pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, n); // pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;; // // assert (pColInfo->info.colId != PRIMARYKEY_TIMESTAMP_COL_ID); @@ -3161,9 +3158,9 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { bool tsdbNextDataBlock(tsdbReaderT pHandle) { STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - size_t numOfCols = taosArrayGetSize(pTsdbReadHandle->pColumns); + size_t numOfCols = taosArrayGetSize(pTsdbReadHandle->pResBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); colInfoDataCleanup(pColInfo, pTsdbReadHandle->outputCapacity); } @@ -3250,7 +3247,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // SArray* row = (type == TSDB_PREV_ROW)? pTsdbReadHandle->prev : pTsdbReadHandle->next; // // for (int32_t i = 0; i < numOfCols; ++i) { -// SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pColumns, i); +// SColumnInfoData* pCol = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); // // SColumnInfoData colInfo = {{0}, 0}; // colInfo.info = pCol->info; @@ -3280,7 +3277,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // } // // for (int32_t i = 0; i < cond.numOfCols; ++i) { -// SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, i); +// SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); // memcpy(&cond.colList[i], &pColInfoData->info, sizeof(SColumnInfo)); // } // @@ -3342,7 +3339,7 @@ bool tsdbGetExternalRow(tsdbReaderT pHandle) { int32_t numOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, i); + SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); SColumnInfoData* first = taosArrayGet(pTsdbReadHandle->prev, i); memcpy(pColInfoData->pData, first->pData, pColInfoData->info.bytes); @@ -3617,13 +3614,13 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { */ STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; if (pHandle->cur.fid == INT32_MIN) { - return pHandle->pColumns; + return pHandle->pResBlock->pDataBlock; } else { STableBlockInfo* pBlockInfo = &pHandle->pDataBlockInfo[pHandle->cur.slot]; STableCheckInfo* pCheckInfo = pBlockInfo->pTableCheckInfo; if (pHandle->cur.mixBlock) { - return pHandle->pColumns; + return pHandle->pResBlock->pDataBlock; } else { SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlockInfo->compBlock); assert(pHandle->realNumOfRows <= binfo.rows); @@ -3633,7 +3630,7 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { if (pBlockLoadInfo->slot == pHandle->cur.slot && pBlockLoadInfo->fileGroup->fid == pHandle->cur.fid && pBlockLoadInfo->uid == pCheckInfo->tableId) { - return pHandle->pColumns; + return pHandle->pResBlock->pDataBlock; } else { // only load the file block SBlock* pBlock = pBlockInfo->compBlock; if (doLoadFileDataBlock(pHandle, pBlock, pCheckInfo, pHandle->cur.slot) != TSDB_CODE_SUCCESS) { @@ -3641,7 +3638,7 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { } int32_t numOfRows = doCopyRowsFromFileBlock(pHandle, pHandle->outputCapacity, 0, 0, pBlock->numOfRows - 1); - return pHandle->pColumns; + return pHandle->pResBlock->pDataBlock; } } } @@ -3692,7 +3689,7 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { return; } - pTsdbReadHandle->pColumns = doFreeColumnInfoData(pTsdbReadHandle->pColumns); + pTsdbReadHandle->pResBlock->pDataBlock = doFreeColumnInfoData(pTsdbReadHandle->pResBlock->pDataBlock); taosArrayDestroy(pTsdbReadHandle->suppInfo.defaultLoadColumn); taosMemoryFreeClear(pTsdbReadHandle->pDataBlockInfo); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index e764aba48e..88bdea3ae7 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -265,10 +265,14 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { return tqProcessTaskDispatchReq(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_RECOVER: return tqProcessTaskRecoverReq(pVnode->pTq, pMsg); + case TDMT_STREAM_RETRIEVE: + return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_DISPATCH_RSP: return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_RECOVER_RSP: return tqProcessTaskRecoverRsp(pVnode->pTq, pMsg); + case TDMT_STREAM_RETRIEVE_RSP: + return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg); default: vError("unknown msg type:%d in fetch queue", pMsg->msgType); return TSDB_CODE_VND_APP_ERROR; @@ -311,7 +315,7 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *p if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; int32_t t = ntohl(*(int32_t *)pReq); - vError("rec ttl time:%d", t); + vDebug("vgId:%d, recv ttl msg, time:%d", pVnode->config.vgId, t); int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids); if (ret != 0) { goto end; diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 2c1e6fbbbd..2a8c7a583c 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -435,7 +435,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); EXPECT_NE(pDataBlock, nullptr); pDataBlock->pBlockAgg = NULL; - pDataBlock->info.numOfCols = tSmaNumOfCols; + taosArrayGetSize(pDataBlock->pDataBlock) = tSmaNumOfCols; pDataBlock->info.rows = tSmaNumOfRows; pDataBlock->info.groupId = tSmaGroupId + g; diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 98a03aa39b..384c3f19e5 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -65,6 +65,7 @@ enum { typedef enum { CTG_TASK_GET_QNODE = 0, + CTG_TASK_GET_DNODE, CTG_TASK_GET_DB_VGROUP, CTG_TASK_GET_DB_CFG, CTG_TASK_GET_DB_INFO, @@ -216,6 +217,7 @@ typedef struct SCtgJob { int32_t dbVgNum; int32_t udfNum; int32_t qnodeNum; + int32_t dnodeNum; int32_t dbCfgNum; int32_t indexNum; int32_t userNum; @@ -565,6 +567,7 @@ int32_t ctgGetTbHashVgroupFromCache(SCatalog *pCtg, const SName *pTableName, SVg int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target); int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildUseDBInput *input, SUseDbOutput *out, SCtgTask* pTask); int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray *out, SCtgTask* pTask); +int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray **out, SCtgTask* pTask); int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *dbFName, SDbCfgInfo *out, SCtgTask* pTask); int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char *indexName, SIndexInfo *out, SCtgTask* pTask); int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *name, STableIndex* out, SCtgTask* pTask); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 44730cd3b5..931a944adf 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1099,8 +1099,19 @@ _return: CTG_API_LEAVE(TSDB_CODE_SUCCESS); } -int32_t catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray** pDnodeList) { - return TSDB_CODE_CTG_INVALID_INPUT; +int32_t catalogGetDnodeList(SCatalog* pCtg, SRequestConnInfo* pConn, SArray** pDnodeList) { + CTG_API_ENTER(); + + int32_t code = 0; + if (NULL == pCtg || NULL == pConn || NULL == pDnodeList) { + CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); + } + + CTG_ERR_JRET(ctgGetDnodeListFromMnode(pCtg, pConn, pDnodeList, NULL)); + +_return: + + CTG_API_LEAVE(TSDB_CODE_SUCCESS); } int32_t catalogGetExpiredSTables(SCatalog* pCtg, SSTableVersion **stables, uint32_t *num) { diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index df986fd4d6..8928a7e028 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -168,6 +168,21 @@ int32_t ctgInitGetQnodeTask(SCtgJob *pJob, int32_t taskIdx, void* param) { return TSDB_CODE_SUCCESS; } +int32_t ctgInitGetDnodeTask(SCtgJob *pJob, int32_t taskIdx, void* param) { + SCtgTask task = {0}; + + task.type = CTG_TASK_GET_DNODE; + task.taskId = taskIdx; + task.pJob = pJob; + task.taskCtx = NULL; + + taosArrayPush(pJob->pTasks, &task); + + qDebug("QID:0x%" PRIx64 " the %d task type %s initialized", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type)); + + return TSDB_CODE_SUCCESS; +} + int32_t ctgInitGetIndexTask(SCtgJob *pJob, int32_t taskIdx, void* param) { char *name = (char*)param; SCtgTask task = {0}; @@ -405,6 +420,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, uint6 int32_t tbHashNum = (int32_t)taosArrayGetSize(pReq->pTableHash); int32_t udfNum = (int32_t)taosArrayGetSize(pReq->pUdf); int32_t qnodeNum = pReq->qNodeRequired ? 1 : 0; + int32_t dnodeNum = pReq->dNodeRequired ? 1 : 0; int32_t dbCfgNum = (int32_t)taosArrayGetSize(pReq->pDbCfg); int32_t indexNum = (int32_t)taosArrayGetSize(pReq->pIndex); int32_t userNum = (int32_t)taosArrayGetSize(pReq->pUser); @@ -412,7 +428,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, uint6 int32_t tbIndexNum = (int32_t)taosArrayGetSize(pReq->pTableIndex); int32_t tbCfgNum = (int32_t)taosArrayGetSize(pReq->pTableCfg); - *taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dbCfgNum + indexNum + userNum + dbInfoNum + tbIndexNum + tbCfgNum; + *taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + dbCfgNum + indexNum + userNum + dbInfoNum + tbIndexNum + tbCfgNum; if (*taskNum <= 0) { ctgDebug("Empty input for job, no need to retrieve meta, reqId:0x%" PRIx64, reqId); return TSDB_CODE_SUCCESS; @@ -435,6 +451,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, uint6 pJob->tbMetaNum = tbMetaNum; pJob->tbHashNum = tbHashNum; pJob->qnodeNum = qnodeNum; + pJob->dnodeNum = dnodeNum; pJob->dbVgNum = dbVgNum; pJob->udfNum = udfNum; pJob->dbCfgNum = dbCfgNum; @@ -509,6 +526,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, uint6 CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_QNODE, NULL, NULL)); } + if (dnodeNum) { + CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_DNODE, NULL, NULL)); + } + pJob->refId = taosAddRef(gCtgMgmt.jobPool, pJob); if (pJob->refId < 0) { ctgError("add job to ref failed, error: %s", tstrerror(terrno)); @@ -631,6 +652,22 @@ int32_t ctgDumpQnodeRes(SCtgTask* pTask) { return TSDB_CODE_SUCCESS; } +int32_t ctgDumpDnodeRes(SCtgTask* pTask) { + SCtgJob* pJob = pTask->pJob; + if (NULL == pJob->jobRes.pDnodeList) { + pJob->jobRes.pDnodeList = taosArrayInit(1, sizeof(SMetaRes)); + if (NULL == pJob->jobRes.pDnodeList) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + } + + SMetaRes res = {.code = pTask->code, .pRes = pTask->res}; + taosArrayPush(pJob->jobRes.pDnodeList, &res); + + return TSDB_CODE_SUCCESS; +} + + int32_t ctgDumpDbCfgRes(SCtgTask* pTask) { SCtgJob* pJob = pTask->pJob; if (NULL == pJob->jobRes.pDbCfg) { @@ -1036,6 +1073,19 @@ _return: CTG_RET(code); } +int32_t ctgHandleGetDnodeRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *pMsg, int32_t rspCode) { + int32_t code = 0; + CTG_ERR_JRET(ctgProcessRspMsg(&pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target)); + + TSWAP(pTask->res, pTask->msgCtx.out); + +_return: + + ctgHandleTaskEnd(pTask, code); + + CTG_RET(code); +} + int32_t ctgHandleGetIndexRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; CTG_ERR_JRET(ctgProcessRspMsg(pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target)); @@ -1311,6 +1361,15 @@ int32_t ctgLaunchGetQnodeTask(SCtgTask *pTask) { return TSDB_CODE_SUCCESS; } +int32_t ctgLaunchGetDnodeTask(SCtgTask *pTask) { + SCatalog* pCtg = pTask->pJob->pCtg; + SRequestConnInfo* pConn = &pTask->pJob->conn; + + CTG_ERR_RET(ctgGetDnodeListFromMnode(pCtg, pConn, NULL, pTask)); + return TSDB_CODE_SUCCESS; +} + + int32_t ctgLaunchGetDbCfgTask(SCtgTask *pTask) { SCatalog* pCtg = pTask->pJob->pCtg; SRequestConnInfo* pConn = &pTask->pJob->conn; @@ -1462,6 +1521,7 @@ int32_t ctgCloneDbVg(SCtgTask* pTask, void** pRes) { SCtgAsyncFps gCtgAsyncFps[] = { {ctgInitGetQnodeTask, ctgLaunchGetQnodeTask, ctgHandleGetQnodeRsp, ctgDumpQnodeRes, NULL, NULL}, + {ctgInitGetDnodeTask, ctgLaunchGetDnodeTask, ctgHandleGetDnodeRsp, ctgDumpDnodeRes, NULL, NULL}, {ctgInitGetDbVgTask, ctgLaunchGetDbVgTask, ctgHandleGetDbVgRsp, ctgDumpDbVgRes, ctgCompDbVgTasks, ctgCloneDbVg}, {ctgInitGetDbCfgTask, ctgLaunchGetDbCfgTask, ctgHandleGetDbCfgRsp, ctgDumpDbCfgRes, NULL, NULL}, {ctgInitGetDbInfoTask, ctgLaunchGetDbInfoTask, ctgHandleGetDbInfoRsp, ctgDumpDbInfoRes, NULL, NULL}, diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 81dabffb4e..97edb1b837 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -40,6 +40,21 @@ int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, qDebug("Got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(out)); break; } + case TDMT_MND_DNODE_LIST: { + if (TSDB_CODE_SUCCESS != rspCode) { + qError("error rsp for dnode list, error:%s", tstrerror(rspCode)); + CTG_ERR_RET(rspCode); + } + + code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize); + if (code) { + qError("Process dnode list rsp failed, error:%s", tstrerror(rspCode)); + CTG_ERR_RET(code); + } + + qDebug("Got dnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(*(SArray**)out)); + break; + } case TDMT_MND_USE_DB: { if (TSDB_CODE_SUCCESS != rspCode) { qError("error rsp for use db, error:%s, dbFName:%s", tstrerror(rspCode), target); @@ -309,9 +324,6 @@ _return: CTG_RET(code); } - - - int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray *out, SCtgTask* pTask) { char *msg = NULL; int32_t msgLen = 0; @@ -349,6 +361,39 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray return TSDB_CODE_SUCCESS; } +int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray **out, SCtgTask* pTask) { + char *msg = NULL; + int32_t msgLen = 0; + int32_t reqType = TDMT_MND_DNODE_LIST; + void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont; + + ctgDebug("try to get dnode list from mnode, mgmtEpInUse:%d", pConn->mgmtEps.inUse); + + int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen, mallocFp); + if (code) { + ctgError("Build dnode list msg failed, error:%s", tstrerror(code)); + CTG_ERR_RET(code); + } + + if (pTask) { + CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, NULL)); + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + } + + SRpcMsg rpcMsg = { + .msgType = reqType, + .pCont = msg, + .contLen = msgLen, + }; + + SRpcMsg rpcRsp = {0}; + rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp); + + CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, NULL)); + + return TSDB_CODE_SUCCESS; +} + int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildUseDBInput *input, SUseDbOutput *out, SCtgTask* pTask) { char *msg = NULL; diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 8635457dfe..cc823adad0 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -23,6 +23,8 @@ char *ctgTaskTypeStr(CTG_TASK_TYPE type) { switch (type) { case CTG_TASK_GET_QNODE: return "[get qnode list]"; + case CTG_TASK_GET_DNODE: + return "[get dnode list]"; case CTG_TASK_GET_DB_VGROUP: return "[get db vgroup]"; case CTG_TASK_GET_DB_CFG: @@ -349,6 +351,11 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void **pRes) { *pRes = NULL; break; } + case CTG_TASK_GET_DNODE: { + taosArrayDestroy((SArray*)*pRes); + *pRes = NULL; + break; + } case CTG_TASK_GET_TB_META: { taosMemoryFreeClear(*pRes); break; @@ -413,6 +420,11 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void **pRes) { *pRes = NULL; break; } + case CTG_TASK_GET_DNODE: { + taosArrayDestroy((SArray*)*pRes); + *pRes = NULL; + break; + } case CTG_TASK_GET_TB_META: { taosMemoryFreeClear(*pRes); break; diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 778742b0fa..cb14b916af 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -18,6 +18,7 @@ #include "tdatablock.h" #include "tglobal.h" +extern SConfig *tsCfg; static int32_t getSchemaBytes(const SSchema* pSchema) { switch (pSchema->type) { case TSDB_DATA_TYPE_BINARY: @@ -31,31 +32,19 @@ static int32_t getSchemaBytes(const SSchema* pSchema) { } static SSDataBlock* buildDescResultDataBlock() { - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->info.numOfCols = DESCRIBE_RESULT_COLS; - pBlock->info.hasVarCol = true; + SSDataBlock* pBlock = createDataBlock(); - pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_FIELD_LEN, 1); + blockDataAppendColInfo(pBlock, &infoData); - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = DESCRIBE_RESULT_FIELD_LEN; + infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_TYPE_LEN, 2); + blockDataAppendColInfo(pBlock, &infoData); - taosArrayPush(pBlock->pDataBlock, &infoData); - - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = DESCRIBE_RESULT_TYPE_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); - - infoData.info.type = TSDB_DATA_TYPE_INT; - infoData.info.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; - - taosArrayPush(pBlock->pDataBlock, &infoData); - - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = DESCRIBE_RESULT_NOTE_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, tDataTypes[TSDB_DATA_TYPE_INT].bytes, 3); + blockDataAppendColInfo(pBlock, &infoData); + infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_NOTE_LEN, 4); + blockDataAppendColInfo(pBlock, &infoData); return pBlock; } @@ -126,22 +115,12 @@ static int32_t execResetQueryCache() { return catalogClearCache(); } static SSDataBlock* buildCreateDBResultDataBlock() { - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->info.numOfCols = SHOW_CREATE_DB_RESULT_COLS; - pBlock->info.hasVarCol = true; - - pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); - - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = SHOW_CREATE_DB_RESULT_FIELD1_LEN; - - taosArrayPush(pBlock->pDataBlock, &infoData); - - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = SHOW_CREATE_DB_RESULT_FIELD2_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + SSDataBlock* pBlock = createDataBlock(); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1); + blockDataAppendColInfo(pBlock, &infoData); + infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_FIELD2_LEN, 2); + blockDataAppendColInfo(pBlock, &infoData); return pBlock; } @@ -283,21 +262,13 @@ static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveT } static SSDataBlock* buildCreateTbResultDataBlock() { - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->info.numOfCols = SHOW_CREATE_TB_RESULT_COLS; - pBlock->info.hasVarCol = true; + SSDataBlock* pBlock = createDataBlock(); - pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD1_LEN, 1); + blockDataAppendColInfo(pBlock, &infoData); - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = SHOW_CREATE_TB_RESULT_FIELD1_LEN; - - taosArrayPush(pBlock->pDataBlock, &infoData); - - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = SHOW_CREATE_TB_RESULT_FIELD2_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD2_LEN, 2); + blockDataAppendColInfo(pBlock, &infoData); return pBlock; } @@ -549,9 +520,96 @@ static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableR return execShowCreateTable(pStmt, pRsp); } -static int32_t execAlterLocal(SAlterLocalStmt* pStmt) { return TSDB_CODE_FAILED; } +static int32_t execAlterLocal(SAlterLocalStmt* pStmt) { + if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CMD)) { + return terrno; + } -static int32_t execShowLocalVariables() { return TSDB_CODE_FAILED; } + if (taosSetCfg(tsCfg, pStmt->config)) { + return terrno; + } + + return TSDB_CODE_SUCCESS; +} + +static SSDataBlock* buildLocalVariablesResultDataBlock() { + SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + pBlock->info.hasVarCol = true; + + pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); + + SColumnInfoData infoData = {0}; + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN; + + taosArrayPush(pBlock->pDataBlock, &infoData); + + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN; + taosArrayPush(pBlock->pDataBlock, &infoData); + + return pBlock; +} + + +int32_t setLocalVariablesResultIntoDataBlock(SSDataBlock* pBlock) { + int32_t numOfCfg = taosArrayGetSize(tsCfg->array); + int32_t numOfRows = 0; + blockDataEnsureCapacity(pBlock, numOfCfg); + + for (int32_t i = 0, c = 0; i < numOfCfg; ++i, c = 0) { + SConfigItem *pItem = taosArrayGet(tsCfg->array, i); + + char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + colDataAppend(pColInfo, i, name, false); + + char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; + int32_t valueLen = 0; + cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen); + varDataSetLen(value, valueLen); + pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + colDataAppend(pColInfo, i, value, false); + + numOfRows++; + } + + + pBlock->info.rows = numOfRows; + + return TSDB_CODE_SUCCESS; +} + + +static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { + SSDataBlock* pBlock = buildLocalVariablesResultDataBlock(); + int32_t code = setLocalVariablesResultIntoDataBlock(pBlock); + if (code) { + return code; + } + + size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + *pRsp = taosMemoryCalloc(1, rspSize); + if (NULL == *pRsp) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + (*pRsp)->useconds = 0; + (*pRsp)->completed = 1; + (*pRsp)->precision = 0; + (*pRsp)->compressed = 0; + (*pRsp)->compLen = 0; + (*pRsp)->numOfRows = htonl(pBlock->info.rows); + (*pRsp)->numOfCols = htonl(SHOW_LOCAL_VARIABLES_RESULT_COLS); + + int32_t len = 0; + blockCompressEncode(pBlock, (*pRsp)->data, &len, SHOW_LOCAL_VARIABLES_RESULT_COLS, false); + ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); + + blockDataDestroy(pBlock); + return TSDB_CODE_SUCCESS; +} int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) { switch (nodeType(pStmt)) { @@ -568,7 +626,7 @@ int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp) { case QUERY_NODE_ALTER_LOCAL_STMT: return execAlterLocal((SAlterLocalStmt*)pStmt); case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: - return execShowLocalVariables(); + return execShowLocalVariables(pRsp); default: break; } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 2d55b06f06..ef4ac0b639 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -1190,17 +1190,12 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_VARCHAR; - infoData.info.bytes = TSDB_EXPLAIN_RESULT_ROW_SIZE; - - pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - taosArrayPush(pBlock->pDataBlock, &infoData); + SSDataBlock *pBlock = createDataBlock(); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, TSDB_EXPLAIN_RESULT_ROW_SIZE, 1); + blockDataAppendColInfo(pBlock, &infoData); + blockDataEnsureCapacity(pBlock, rowNum); SColumnInfoData* pInfoData = taosArrayGet(pBlock->pDataBlock, 0); - pInfoData->hasNull = false; - colInfoDataEnsureCapacity(pInfoData, 0, rowNum); char buf[1024] = {0}; for (int32_t i = 0; i < rowNum; ++i) { @@ -1210,9 +1205,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { colDataAppend(pInfoData, i, buf, false); } - pBlock->info.numOfCols = 1; pBlock->info.rows = rowNum; - pBlock->info.hasVarCol = true; int32_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); @@ -1226,7 +1219,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { rsp->numOfRows = htonl(rowNum); int32_t len = 0; - blockCompressEncode(pBlock, rsp->data, &len, pBlock->info.numOfCols, 0); + blockCompressEncode(pBlock, rsp->data, &len, taosArrayGetSize(pBlock->pDataBlock), 0); ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); rsp->compLen = htonl(len); diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index 4ecf2ee719..f3e1eb47e8 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -106,7 +106,8 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode); -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo, SNode* pTagCond); +EDealRes doTranslateTagExpr(SNode** pNode, void* pContext); +int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo); SArray* createSortInfo(SNodeList* pNodeList); SArray* extractPartitionColInfo(SNodeList* pNodeList); SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 27b00046bb..57a2c57b16 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -234,6 +234,7 @@ typedef struct SColMatchInfo { int32_t colId; int32_t targetSlotId; bool output; + bool reserved; int32_t matchType; // determinate the source according to col id or slot id } SColMatchInfo; @@ -253,7 +254,6 @@ typedef struct STableScanInfo { SFileBlockLoadRecorder readRecorder; int64_t numOfRows; -// int32_t prevGroupId; // previous table group id SScanInfo scanInfo; int32_t scanTimes; SNode* pFilterNode; // filter info, which is push down by optimizer @@ -282,7 +282,6 @@ typedef struct STagScanInfo { int32_t curPos; SReadHandle readHandle; STableListInfo *pTableList; - SNode* pFilterNode; // filter info, } STagScanInfo; typedef enum EStreamScanMode { @@ -337,11 +336,10 @@ typedef struct SStreamBlockScanInfo { int32_t numOfPseudoExpr; int32_t primaryTsIndex; // primary time stamp slot id - void* pDataReader; SReadHandle readHandle; uint64_t tableUid; // queried super table uid EStreamScanMode scanMode; - SOperatorInfo* pOperatorDumy; + SOperatorInfo* pSnapshotReadOp; SInterval interval; // if the upstream is an interval operator, the interval info is also kept here. SArray* childIds; SessionWindowSupporter sessionSup; @@ -838,14 +836,17 @@ int32_t finalizeResultRowIntoResultDataBlock(SDiskbasedBuf* pBuf, SResultRowPosi SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, int32_t numOfExprs, const int32_t* rowCellOffset, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); -int32_t createMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId, - uint64_t taskId, SNode* pTagCond); -SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SArray* dataReaders, - SReadHandle* readHandle, SExecTaskInfo* pTaskInfo); +int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId); +SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, + SExecTaskInfo* pTaskInfo); +SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo *pTableListInfo, + SReadHandle* readHandle, SExecTaskInfo* pTaskInfo, uint64_t queryId, uint64_t taskId); void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex); +int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SArray* groupKey); + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 363f379ee4..35bdd4ee55 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -50,6 +50,7 @@ typedef struct SMsortComparParam { void **pSources; int32_t numOfSources; SArray *orderInfo; // SArray + bool cmpGroupId; } SMsortComparParam; typedef struct SSortHandle SSortHandle; @@ -99,6 +100,11 @@ int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetc */ int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp); +/** + * + */ +int32_t tsortSetCompareGroupId(SSortHandle* pHandle, bool compareGroupId); + /** * * @param pHandle diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c index 33b7811e6c..8c220134f0 100644 --- a/source/libs/executor/src/dataDeleter.c +++ b/source/libs/executor/src/dataDeleter.c @@ -75,7 +75,7 @@ static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInp SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData; pEntry->compressed = 0; pEntry->numOfRows = pInput->pData->info.rows; - pEntry->numOfCols = pInput->pData->info.numOfCols; + pEntry->numOfCols = taosArrayGetSize(pInput->pData->pDataBlock); pEntry->dataLen = sizeof(SDeleterRes); ASSERT(1 == pEntry->numOfRows); @@ -86,7 +86,7 @@ static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInp SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pInput->pData->pDataBlock, 0); SDeleterRes* pRes = (SDeleterRes*)pEntry->data; - pRes->uid = pHandle->pDeleter->tableId; + pRes->suid = pHandle->pParam->suid; pRes->uidList = pHandle->pParam->pUidList; pRes->skey = pHandle->pDeleter->deleteTimeRange.skey; pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 27096fe7f9..8669c2c28c 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -183,71 +183,159 @@ SArray* createSortInfo(SNodeList* pNodeList) { SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { int32_t numOfCols = LIST_LENGTH(pNode->pSlots); - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); + SSDataBlock* pBlock = createDataBlock(); pBlock->info.blockId = pNode->dataBlockId; - pBlock->info.rowSize = pNode->totalRowSize; // todo ?? pBlock->info.type = STREAM_INVALID; for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData idata = {{0}}; SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i); // if (!pDescNode->output) { // todo disable it temporarily // continue; // } - idata.info.type = pDescNode->dataType.type; - idata.info.bytes = pDescNode->dataType.bytes; + SColumnInfoData idata = createColumnInfoData(pDescNode->dataType.type, pDescNode->dataType.bytes, pDescNode->slotId); idata.info.scale = pDescNode->dataType.scale; - idata.info.slotId = pDescNode->slotId; idata.info.precision = pDescNode->dataType.precision; - if (IS_VAR_DATA_TYPE(idata.info.type)) { - pBlock->info.hasVarCol = true; - } - - taosArrayPush(pBlock->pDataBlock, &idata); + blockDataAppendColInfo(pBlock, &idata); } - pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock); return pBlock; } -int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo, SNode* pTagCond) { +EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { + SMetaReader* mr = (SMetaReader*)pContext; + if(nodeType(*pNode) == QUERY_NODE_COLUMN){ + SColumnNode* pSColumnNode = *(SColumnNode**)pNode; + + SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == res) { + return DEAL_RES_ERROR; + } + + res->translate = true; + res->node.resType = pSColumnNode->node.resType; + + STagVal tagVal = {0}; + tagVal.cid = pSColumnNode->colId; + const char* p = metaGetTableTagVal(&mr->me, pSColumnNode->node.resType.type, &tagVal); + if (p == NULL) { + res->node.resType.type = TSDB_DATA_TYPE_NULL; + }else if (pSColumnNode->node.resType.type == TSDB_DATA_TYPE_JSON) { + int32_t len = ((const STag*)p) -> len; + res->datum.p = taosMemoryCalloc(len + 1, 1); + memcpy(res->datum.p, p, len); + } else if (IS_VAR_DATA_TYPE(pSColumnNode->node.resType.type)) { + res->datum.p = taosMemoryCalloc(tagVal.nData + VARSTR_HEADER_SIZE + 1, 1); + memcpy(varDataVal(res->datum.p), tagVal.pData, tagVal.nData); + varDataSetLen(res->datum.p, tagVal.nData); + } else { + nodesSetValueNodeValue(res, &(tagVal.i64)); + } + nodesDestroyNode(*pNode); + *pNode = (SNode*)res; + }else if (nodeType(*pNode) == QUERY_NODE_FUNCTION){ + SFunctionNode * pFuncNode = *(SFunctionNode**)pNode; + if(pFuncNode->funcType == FUNCTION_TYPE_TBNAME){ + SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == res) { + return DEAL_RES_ERROR; + } + + res->translate = true; + res->node.resType = pFuncNode->node.resType; + + int32_t len = strlen(mr->me.name); + res->datum.p = taosMemoryCalloc(len + VARSTR_HEADER_SIZE + 1, 1); + memcpy(varDataVal(res->datum.p), mr->me.name, len); + varDataSetLen(res->datum.p, len); + nodesDestroyNode(*pNode); + *pNode = (SNode*)res; + } + } + + return DEAL_RES_CONTINUE; +} + +static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){ + SMetaReader mr = {0}; + metaReaderInit(&mr, metaHandle, 0); + metaGetTableEntryByUid(&mr, info->uid); + + SNode *pTagCondTmp = nodesCloneNode(pTagCond); + + nodesRewriteExprPostOrder(&pTagCondTmp, doTranslateTagExpr, &mr); + metaReaderClear(&mr); + + SNode* pNew = NULL; + int32_t code = scalarCalculateConstants(pTagCondTmp, &pNew); + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pTagCondTmp); + return false; + } + + ASSERT(nodeType(pNew) == QUERY_NODE_VALUE); + SValueNode *pValue = (SValueNode *)pNew; + + ASSERT(pValue->node.resType.type == TSDB_DATA_TYPE_BOOL); + bool result = pValue->datum.b; + nodesDestroyNode(pNew); + return result; +} + +int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo)); uint64_t tableUid = pScanNode->uid; + pListInfo->suid = pScanNode->suid; + + SNode* pTagCond = (SNode*)pListInfo->pTagCond; + SNode* pTagIndexCond = (SNode*)pListInfo->pTagIndexCond; if (pScanNode->tableType == TSDB_SUPER_TABLE) { - if (pTagCond) { + if (pTagIndexCond) { SIndexMetaArg metaArg = { .metaEx = metaHandle, .idx = tsdbGetIdx(metaHandle), .ivtIdx = tsdbGetIvtIdx(metaHandle), .suid = tableUid}; SArray* res = taosArrayInit(8, sizeof(uint64_t)); - code = doFilterTag(pTagCond, &metaArg, res); - if (code == TSDB_CODE_INDEX_REBUILDING) { // todo - // doFilter(); + //code = doFilterTag(pTagIndexCond, &metaArg, res); + code = TSDB_CODE_INDEX_REBUILDING; + if (code == TSDB_CODE_INDEX_REBUILDING) { + code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } else if (code != TSDB_CODE_SUCCESS) { qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid); taosArrayDestroy(res); terrno = code; return code; } else { - qDebug("success to get tableIds, size: %d, suid: %" PRIu64 "", (int)taosArrayGetSize(res), tableUid); + qDebug("sucess to get tableIds, size: %d, suid: %" PRIu64 "", (int)taosArrayGetSize(res), tableUid); } for (int i = 0; i < taosArrayGetSize(res); i++) { - STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i)}; + STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0}; taosArrayPush(pListInfo->pTableList, &info); } taosArrayDestroy(res); } else { code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } - } else { // Create one table group. - STableKeyInfo info = {.lastKey = 0, .uid = tableUid}; + + if(pTagCond){ + int32_t i = 0; + while(i < taosArrayGetSize(pListInfo->pTableList)) { + STableKeyInfo* info = taosArrayGet(pListInfo->pTableList, i); + bool isOk = isTableOk(info, pTagCond, metaHandle); + if(!isOk){ + taosArrayRemove(pListInfo->pTableList, i); + continue; + } + i++; + } + } + }else { // Create one table group. + STableKeyInfo info = {.lastKey = 0, .uid = tableUid, .groupId = 0}; taosArrayPush(pListInfo->pTableList, &info); } @@ -300,7 +388,7 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod SColMatchInfo c = {0}; c.output = true; - c.colId = pColNode->colId; + c.colId = pColNode->colId; c.srcSlotId = pColNode->slotId; c.matchType = type; c.targetSlotId = pNode->slotId; @@ -600,7 +688,7 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray if (p->info.colId == pmInfo->colId) { SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, pmInfo->targetSlotId); - colDataAssign(pDst, p, pBlock->info.rows); + colDataAssign(pDst, p, pBlock->info.rows, &pBlock->info); i++; j++; } else if (p->info.colId < pmInfo->colId) { diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index cf72dfd796..ad400d720a 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -40,19 +40,9 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu SStreamBlockScanInfo* pInfo = pOperator->info; pInfo->assignBlockUid = assignUid; - // the block type can not be changed in the streamscan operators -#if 0 - if (pInfo->blockType == 0) { - pInfo->blockType = type; - } else if (pInfo->blockType != type) { - ASSERT(0); - return TSDB_CODE_QRY_APP_ERROR; - } -#endif - // rollup sma, the same qTaskInfo is used to insert data by SubmitReq and fetch result by SSDataBlock - if (pInfo->blockType != type) { - pInfo->blockType = type; - } + // TODO: if a block was set but not consumed, + // prevent setting a different type of block + pInfo->blockType = type; if (type == STREAM_DATA_TYPE_SUBMIT_BLOCK) { if (tqReadHandleSetMsg(pInfo->streamBlockReader, input, 0) < 0) { @@ -70,6 +60,9 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu taosArrayAddAll(p->pDataBlock, pDataBlock->pDataBlock); taosArrayPush(pInfo->pBlockLists, &p); } + } else if (type == STREAM_DATA_TYPE_FROM_SNAPSHOT) { + // do nothing + ASSERT(pInfo->blockType == STREAM_DATA_TYPE_FROM_SNAPSHOT); } else { ASSERT(0); } @@ -78,6 +71,14 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu } } +int32_t qStreamScanSnapshot(qTaskInfo_t tinfo) { + if (tinfo == NULL) { + return TSDB_CODE_QRY_APP_ERROR; + } + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + return doSetStreamBlock(pTaskInfo->pRoot, NULL, 0, STREAM_DATA_TYPE_FROM_SNAPSHOT, 0, NULL); +} + int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type, bool assignUid) { return qSetMultiStreamInput(tinfo, input, 1, type, assignUid); } @@ -109,14 +110,6 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) { return NULL; } - // print those info into log -#if 0 - pMsg->sId = pMsg->sId; - pMsg->queryId = pMsg->queryId; - pMsg->taskId = pMsg->taskId; - pMsg->contentLen = pMsg->contentLen; -#endif - /*qDebugL("stream task string %s", (const char*)msg);*/ struct SSubplan* plan = NULL; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 8db80142f4..6c416ae9c4 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -356,7 +356,7 @@ void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP; pColData->info.bytes = sizeof(int64_t); - colInfoDataEnsureCapacity(pColData, 0, 5); + colInfoDataEnsureCapacity(pColData, 5); colDataAppendInt64(pColData, 0, &pQueryWindow->skey); colDataAppendInt64(pColData, 1, &pQueryWindow->ekey); @@ -458,7 +458,7 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc pColInfo = pInput->pData[paramIndex]; } - colInfoDataEnsureCapacity(pColInfo, 0, numOfRows); + colInfoDataEnsureCapacity(pColInfo, numOfRows); int8_t type = pFuncParam->param.nType; if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) { @@ -579,7 +579,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pfCtx->input.pData[0], pfCtx->input.numOfRows); } else { - colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows); + colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows, &pResult->info); } numOfRows = pfCtx->input.numOfRows; @@ -609,7 +609,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc } int32_t startOffset = createNewColModel ? 0 : pResult->info.rows; - colInfoDataEnsureCapacity(pResColData, startOffset, pResult->info.capacity); + ASSERT(pResult->info.capacity > 0); colDataMergeCol(pResColData, startOffset, &pResult->info.capacity, &idata, dest.numOfRows); numOfRows = dest.numOfRows; @@ -649,7 +649,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc } int32_t startOffset = createNewColModel ? 0 : pResult->info.rows; - colInfoDataEnsureCapacity(pResColData, startOffset, pResult->info.capacity); + ASSERT(pResult->info.capacity > 0); colDataMergeCol(pResColData, startOffset, &pResult->info.capacity, &idata, dest.numOfRows); numOfRows = dest.numOfRows; @@ -1186,7 +1186,7 @@ int32_t loadDataBlockOnDemand(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableSc // } // if (pQueryAttr->pFilters != NULL) { -// filterSetColFieldData(pQueryAttr->pFilters, pBlock->info.numOfCols, pBlock->pDataBlock); +// filterSetColFieldData(pQueryAttr->pFilters, taosArrayGetSize(pBlock->pDataBlock), pBlock->pDataBlock); // } // if (pQueryAttr->pFilters != NULL || pRuntimeEnv->pTsBuf != NULL) { @@ -1321,7 +1321,8 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) { // todo move to the initialization function int32_t code = filterInitFromNode((SNode*)pFilterNode, &filter, 0); - SFilterColumnParam param1 = {.numOfCols = pBlock->info.numOfCols, .pDataBlock = pBlock->pDataBlock}; + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + SFilterColumnParam param1 = {.numOfCols = numOfCols, .pDataBlock = pBlock->pDataBlock}; code = filterSetDataFromSlotId(filter, ¶m1); int8_t* rowRes = NULL; @@ -1340,10 +1341,11 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR } if (rowRes != NULL) { + int32_t totalRows = pBlock->info.rows; SSDataBlock* px = createOneDataBlock(pBlock, true); - int32_t totalRows = pBlock->info.rows; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pSrc = taosArrayGet(px->pDataBlock, i); SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i); // it is a reserved column for scalar function, and no data in this column yet. @@ -2045,8 +2047,9 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList) { if (pColList == NULL) { // data from other sources + blockDataCleanup(pRes); + // blockDataEnsureCapacity(pRes, numOfRows); blockCompressDecode(pRes, numOfOutput, numOfRows, pData); - pRes->info.rows = numOfRows; } else { // extract data according to pColList ASSERT(numOfOutput == taosArrayGetSize(pColList)); char* pStart = pData; @@ -2064,32 +2067,19 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo pStart += sizeof(SSysTableSchema); } - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - pBlock->info.numOfCols = numOfCols; - + SSDataBlock* pBlock = createDataBlock(); for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData idata = {0}; - - idata.info.type = pSchema[i].type; - idata.info.bytes = pSchema[i].bytes; - idata.info.colId = pSchema[i].colId; - idata.hasNull = true; - - taosArrayPush(pBlock->pDataBlock, &idata); - if (IS_VAR_DATA_TYPE(idata.info.type)) { - pBlock->info.hasVarCol = true; - } + SColumnInfoData idata = createColumnInfoData(pSchema[i].type, pSchema[i].bytes, pSchema[i].colId); + blockDataAppendColInfo(pBlock, &idata); } blockCompressDecode(pBlock, numOfCols, numOfRows, pStart); + blockDataEnsureCapacity(pRes, numOfRows); // data from mnode pRes->info.rows = numOfRows; relocateColumnData(pRes, pColList, pBlock->pDataBlock, false); - taosArrayDestroy(pBlock->pDataBlock); - taosMemoryFree(pBlock); - // blockDataDestroy(pBlock); + blockDataDestroy(pBlock); } // todo move this to time window aggregator, since the primary timestamp may not be known by exchange operator. @@ -2420,7 +2410,7 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = pInfo->pResult->info.numOfCols; + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pResult->pDataBlock); pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, @@ -2542,9 +2532,6 @@ static void doMergeImpl(SOperatorInfo* pOperator, int32_t numOfExpr, SSDataBlock SSortedMergeOperatorInfo* pInfo = pOperator->info; SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - // pCtx[i].size = 1; - } for (int32_t i = 0; i < pBlock->info.rows; ++i) { if (!pInfo->hasGroupVal) { @@ -2653,7 +2640,7 @@ SSDataBlock* getSortedMergeBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlo SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); - colDataAssign(pDst, pSrc, p->info.rows); + colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info); } pDataBlock->info.rows = p->info.rows; @@ -3594,6 +3581,10 @@ static SArray* setRowTsColumnOutputInfo(SqlFunctionCtx* pCtx, int32_t numOfCols) return pList; } +static int64_t getLimit(SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; } + +static int64_t getOffset(SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; } + SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, SExecTaskInfo* pTaskInfo) { SProjectOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SProjectOperatorInfo)); @@ -3606,8 +3597,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys SExprInfo* pExprInfo = createExprInfo(pProjPhyNode->pProjections, NULL, &numOfCols); SSDataBlock* pResBlock = createResDataBlock(pProjPhyNode->node.pOutputDataBlockDesc); - SLimit limit = {.limit = pProjPhyNode->limit, .offset = pProjPhyNode->offset}; - SLimit slimit = {.limit = pProjPhyNode->slimit, .offset = pProjPhyNode->soffset}; + SLimit limit = {.limit = getLimit(pProjPhyNode->node.pLimit), .offset = getOffset(pProjPhyNode->node.pLimit)}; + SLimit slimit = {.limit = getLimit(pProjPhyNode->node.pSlimit), .offset = getOffset(pProjPhyNode->node.pSlimit)}; pInfo->limit = limit; pInfo->slimit = slimit; @@ -3872,8 +3863,7 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT } static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, - SNode* pTagCond); + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId); static SArray* extractColumnInfo(SNodeList* pNodeList); @@ -3968,14 +3958,16 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, } } } + int32_t len = (int32_t)(pStart - (char*)keyBuf); - int32_t len = (int32_t)(pStart - (char*)keyBuf); - uint64_t* groupId = taosHashGet(pTableListInfo->map, keyBuf, len); - if (groupId) { - taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), groupId, sizeof(uint64_t)); - } else { + uint64_t* pGroupId = taosHashGet(pTableListInfo->map, keyBuf, len); + + if (!pGroupId) { uint64_t tmpId = calcGroupId(keyBuf, len); + info->groupId = tmpId; taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &tmpId, sizeof(uint64_t)); + } else { + info->groupId = *pGroupId; } metaReaderClear(&mr); @@ -3985,15 +3977,14 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, } SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, - uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo, SNode* pTagCond) { + uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo) { int32_t type = nodeType(pPhyNode); if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) { if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) { STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; - tsdbReaderT pDataReader = - doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond); + tsdbReaderT pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId); if (pDataReader == NULL && terrno != 0) { pTaskInfo->code = terrno; return NULL; @@ -4019,21 +4010,20 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo STableScanInfo* pScanInfo = pOperator->info; pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder; return pOperator; + } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) { STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode; - - SArray* dataReaders = taosArrayInit(8, POINTER_BYTES); - createMultipleDataReaders(pTableScanNode, pHandle, pTableListInfo, dataReaders, queryId, taskId, pTagCond); + createScanTableListInfo(pTableScanNode, pHandle, pTableListInfo, queryId, taskId); extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo); - SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags); - generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json - taosArrayDestroy(groupKeys); - SOperatorInfo* pOperator = createTableMergeScanOperatorInfo(pTableScanNode, dataReaders, pHandle, pTaskInfo); + SOperatorInfo* pOperator = + createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo, queryId, taskId); STableScanInfo* pScanInfo = pOperator->info; pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder; return pOperator; + } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) { return createExchangeOperatorInfo(pHandle->pMsgCb->clientRpc, (SExchangePhysiNode*)pPhyNode, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) { SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table. STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; @@ -4045,22 +4035,25 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo tsdbReaderT pDataReader = NULL; if (pHandle) { - if (pHandle->vnode) { - // for stram - pDataReader = - doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond); + if (pHandle->initTsdbReader) { + // for stream + ASSERT(pHandle->vnode); + pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId); } else { // for tq - getTableList(pHandle->meta, pScanPhyNode, pTableListInfo, pTagCond); + ASSERT(pHandle->meta); + getTableList(pHandle->meta, pScanPhyNode, pTableListInfo); } } +#if 0 if (pDataReader == NULL && terrno != 0) { qDebug("%s pDataReader is NULL", GET_TASKID(pTaskInfo)); // return NULL; } else { qDebug("%s pDataReader is not NULL", GET_TASKID(pTaskInfo)); } +#endif SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags); int32_t code = generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json @@ -4073,19 +4066,22 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SOperatorInfo* pOperator = createStreamScanOperatorInfo(pDataReader, pHandle, pTableScanNode, pTaskInfo, &twSup); return pOperator; + } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) { SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode; return createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) { STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode; - int32_t code = getTableList(pHandle->meta, pScanPhyNode, pTableListInfo, pScanPhyNode->node.pConditions); + int32_t code = getTableList(pHandle->meta, pScanPhyNode, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = terrno; return NULL; } return createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) { SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode; pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); @@ -4097,7 +4093,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return NULL; } } else { // Create one table group. - STableKeyInfo info = {.lastKey = 0, .uid = pBlockNode->uid}; + STableKeyInfo info = {.lastKey = 0, .uid = pBlockNode->uid, .groupId = 0}; taosArrayPush(pTableListInfo->pTableList, &info); } @@ -4137,7 +4133,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES); for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i); - ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo, pTagCond); + ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, queryId, taskId, pTableListInfo); if (ops[i] == NULL) { return NULL; } @@ -4228,6 +4224,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children); } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) { pOptr = createSortOperatorInfo(ops[0], (SSortPhysiNode*)pPhyNode, pTaskInfo); + } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT == type) { + pOptr = createGroupSortOperatorInfo(ops[0], (SGroupSortPhysiNode*)pPhyNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) { SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode; @@ -4339,8 +4337,8 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { } tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, SNode* pTagCond) { - int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo, pTagCond); + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) { + int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -4357,7 +4355,7 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* goto _error; } - tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId); + tsdbReaderT pReader = tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId); cleanupQueryTableDataCond(&cond); return pReader; @@ -4367,6 +4365,62 @@ _error: return NULL; } +int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) { + if (pNode->pChildren == NULL || LIST_LENGTH(pNode->pChildren) == 0) { + if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == pNode->type) { + *ppNode = (STableScanPhysiNode*)pNode; + return 0; + } else { + ASSERT(0); + terrno = TSDB_CODE_QRY_APP_ERROR; + return -1; + } + } else { + if (LIST_LENGTH(pNode->pChildren) != 1) { + ASSERT(0); + terrno = TSDB_CODE_QRY_APP_ERROR; + return -1; + } + SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pNode->pChildren, 0); + return extractTableScanNode(pChildNode, ppNode); + } + return -1; +} + +int32_t doRebuildReader(SOperatorInfo* pOperator, SSubplan* plan, SReadHandle* pHandle) { + if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + if (pOperator->numOfDownstream == 0) { + qError("failed to find stream scan operator"); + return TSDB_CODE_QRY_APP_ERROR; + } + + if (pOperator->numOfDownstream > 1) { + qError("join not supported for stream block scan"); + return TSDB_CODE_QRY_APP_ERROR; + } + return doRebuildReader(pOperator->pDownstream[0], plan, pHandle); + } else { + SStreamBlockScanInfo* pInfo = pOperator->info; + ASSERT(pInfo->pSnapshotReadOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); + STableScanInfo* pTableScanInfo = pInfo->pSnapshotReadOp->info; + + tsdbCleanupReadHandle(pTableScanInfo->dataReader); + STableScanPhysiNode* pNode = NULL; + if (extractTableScanNode(plan->pNode, &pNode) < 0) { + ASSERT(0); + } + + STableListInfo info = {0}; + pTableScanInfo->dataReader = doCreateDataReader(pNode, pHandle, &info, 0, 0); + if (pTableScanInfo->dataReader == NULL) { + ASSERT(0); + qError("failed to create data reader"); + return TSDB_CODE_QRY_APP_ERROR; + } + } + return 0; +} + int32_t encodeOperator(SOperatorInfo* ops, char** result, int32_t* length) { int32_t code = TDB_CODE_SUCCESS; char* pCurrent = NULL; @@ -4466,6 +4520,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pT return TSDB_CODE_OUT_OF_MEMORY; } int32_t tbNum = taosArrayGetSize(pTask->tableqinfoList.pTableList); + pDeleterParam->suid = pTask->tableqinfoList.suid; pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t)); if (NULL == pDeleterParam->pUidList) { taosMemoryFree(pDeleterParam); @@ -4498,18 +4553,16 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead } (*pTaskInfo)->sql = sql; - (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, - &(*pTaskInfo)->tableqinfoList, pPlan->pTagCond); + (*pTaskInfo)->tableqinfoList.pTagCond = pPlan->pTagCond; + (*pTaskInfo)->tableqinfoList.pTagIndexCond = pPlan->pTagIndexCond; + (*pTaskInfo)->pRoot = + createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, queryId, taskId, &(*pTaskInfo)->tableqinfoList); + if (NULL == (*pTaskInfo)->pRoot) { code = (*pTaskInfo)->code; goto _complete; } - if ((*pTaskInfo)->pRoot == NULL) { - code = TSDB_CODE_QRY_OUT_OF_MEMORY; - goto _complete; - } - return code; _complete: diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 064a36df1c..4e4aaba7f4 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -559,8 +559,8 @@ uint64_t calcGroupId(char* pData, int32_t len) { } int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity) { - size_t numOfCols = pBlock->info.numOfCols; - int32_t* offset = taosMemoryCalloc(pBlock->info.numOfCols, sizeof(int32_t)); + size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + int32_t* offset = taosMemoryCalloc(numOfCols, sizeof(int32_t)); offset[0] = sizeof(int32_t) + sizeof(uint64_t); // the number of rows in current page, ref to SSDataBlock paged serialization format diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 734c6bfbfb..07212bc018 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -203,7 +203,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca pCost->skipBlocks += 1; // clear all data in pBlock that are set when handing the previous block - for (int32_t i = 0; i < pBlockInfo->numOfCols; ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* pcol = taosArrayGet(pBlock->pDataBlock, i); pcol->pData = NULL; } @@ -217,14 +217,14 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg, &allColumnsHaveAgg); if (allColumnsHaveAgg == true) { - int32_t numOfCols = pBlock->info.numOfCols; + int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); // todo create this buffer during creating operator if (pBlock->pBlockAgg == NULL) { pBlock->pBlockAgg = taosMemoryCalloc(numOfCols, POINTER_BYTES); } - for (int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->pColMatchInfo); ++i) { SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i); if (!pColMatchInfo->output) { continue; @@ -316,7 +316,7 @@ void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_ SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId); - colInfoDataEnsureCapacity(pColInfoData, 0, pBlock->info.rows); + colInfoDataEnsureCapacity(pColInfoData, pBlock->info.rows); colInfoDataCleanup(pColInfoData, pBlock->info.rows); int32_t functionId = pExpr->pExpr->_function.functionId; @@ -337,7 +337,8 @@ void addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_ } for (int32_t i = 0; i < pBlock->info.rows; ++i) { - colDataAppend(pColInfoData, i, data, (data == NULL)); + colDataAppend(pColInfoData, i, data, + (data == NULL) || (pColInfoData->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))); } if (data && (pColInfoData->info.type != TSDB_DATA_TYPE_JSON) && p != NULL && @@ -354,10 +355,8 @@ void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* p struct SScalarFuncExecFuncs fpSet = {0}; fmGetScalarFuncExecFuncs(functionId, &fpSet); - SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_BIGINT; - infoData.info.bytes = sizeof(uint64_t); - colInfoDataEnsureCapacity(&infoData, 0, 1); + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, sizeof(uint64_t), 1); + colInfoDataEnsureCapacity(&infoData, 1); colDataAppendInt64(&infoData, 0, (int64_t*)&pBlock->info.uid); SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .param = pMeta, .columnData = &infoData}; @@ -384,7 +383,14 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { continue; } - tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &pBlock->info); + blockDataCleanup(pBlock); + + SDataBlockInfo binfo = pBlock->info; + tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &binfo); + + binfo.capacity = binfo.rows; + blockDataEnsureCapacity(pBlock, binfo.rows); + pBlock->info = binfo; uint32_t status = 0; int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status); @@ -530,8 +536,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, // taosSsleep(20); SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; - - int32_t numOfCols = 0; + int32_t numOfCols = 0; SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID); int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); @@ -591,12 +596,12 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pInfo->dataReader = pReadHandle; // pInfo->prevGroupId = -1; - pOperator->name = "TableSeqScanOperator"; + pOperator->name = "TableSeqScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL); return pOperator; @@ -610,7 +615,7 @@ static int32_t doGetTableRowSize(void* pMeta, uint64_t uid) { metaGetTableEntryByUid(&mr, uid); if (mr.me.type == TSDB_SUPER_TABLE) { int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; } } else if (mr.me.type == TSDB_CHILD_TABLE) { @@ -618,12 +623,12 @@ static int32_t doGetTableRowSize(void* pMeta, uint64_t uid) { metaGetTableEntryByUid(&mr, suid); int32_t numOfCols = mr.me.stbEntry.schemaRow.nCols; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { rowLen += mr.me.stbEntry.schemaRow.pSchema[i].bytes; } } else if (mr.me.type == TSDB_NORMAL_TABLE) { int32_t numOfCols = mr.me.ntbEntry.schemaRow.nCols; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { rowLen += mr.me.ntbEntry.schemaRow.pSchema[i].bytes; } } @@ -647,7 +652,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { SSDataBlock* pBlock = pBlockScanInfo->pResBlock; - int32_t slotId = pOperator->exprSupp.pExprInfo->base.resSchema.slotId; + int32_t slotId = pOperator->exprSupp.pExprInfo->base.resSchema.slotId; SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, slotId); int32_t len = tSerializeBlockDistInfo(NULL, 0, &blockDistInfo); @@ -679,23 +684,23 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re goto _error; } - pInfo->pHandle = dataReader; + pInfo->pHandle = dataReader; pInfo->readHandle = *readHandle; - pInfo->uid = uid; - pInfo->pResBlock = createResDataBlock(pBlockScanNode->node.pOutputDataBlockDesc); + pInfo->uid = uid; + pInfo->pResBlock = createResDataBlock(pBlockScanNode->node.pOutputDataBlockDesc); - int32_t numOfCols = 0; + int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pBlockScanNode->pScanPseudoCols, NULL, &numOfCols); - int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfCols); + int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfCols); if (code != TSDB_CODE_SUCCESS) { goto _error; } - pOperator->name = "DataBlockDistScanOperator"; + pOperator->name = "DataBlockDistScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL, @@ -770,7 +775,7 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) { if (!needRead) { return false; } - STableScanInfo* pTableScanInfo = pInfo->pOperatorDumy->info; + STableScanInfo* pTableScanInfo = pInfo->pSnapshotReadOp->info; pTableScanInfo->cond.twindows[0] = win; pTableScanInfo->curTWinIdx = 0; tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond, 0); @@ -779,7 +784,7 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo) { } static void copyOneRow(SSDataBlock* dest, SSDataBlock* source, int32_t sourceRowId) { - for (int32_t j = 0; j < source->info.numOfCols; j++) { + for (int32_t j = 0; j < taosArrayGetSize(source->pDataBlock); j++) { SColumnInfoData* pDestCol = (SColumnInfoData*)taosArrayGet(dest->pDataBlock, j); SColumnInfoData* pSourceCol = (SColumnInfoData*)taosArrayGet(source->pDataBlock, j); if (colDataIsNull_s(pSourceCol, sourceRowId)) { @@ -815,11 +820,11 @@ static uint64_t getGroupId(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo) { while (1) { SSDataBlock* pResult = NULL; - pResult = doTableScan(pInfo->pOperatorDumy); + pResult = doTableScan(pInfo->pSnapshotReadOp); if (pResult == NULL) { if (prepareDataScan(pInfo)) { // scan next window data - pResult = doTableScan(pInfo->pOperatorDumy); + pResult = doTableScan(pInfo->pSnapshotReadOp); } } if (!pResult) { @@ -851,14 +856,13 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa SColumnInfoData* pCol = (SColumnInfoData*)taosArrayGet(pUpdateBlock->pDataBlock, pInfo->primaryTsIndex); ASSERT(pCol->info.type == TSDB_DATA_TYPE_TIMESTAMP); blockDataEnsureCapacity(pUpdateBlock, size); - ASSERT(pBlock->info.numOfCols == pUpdateBlock->info.numOfCols); int32_t rowId = *(int32_t*)taosArrayGet(pInfo->tsArray, pInfo->tsArrayIndex); - pInfo->groupId = getGroupId(pInfo->pOperatorDumy, pBlock, rowId); + pInfo->groupId = getGroupId(pInfo->pSnapshotReadOp, pBlock, rowId); int32_t i = 0; for (; i < size; i++) { rowId = *(int32_t*)taosArrayGet(pInfo->tsArray, i + pInfo->tsArrayIndex); - uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock, rowId); + uint64_t id = getGroupId(pInfo->pSnapshotReadOp, pBlock, rowId); if (pInfo->groupId != id) { break; } @@ -910,6 +914,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { } size_t total = taosArrayGetSize(pInfo->pBlockLists); + // TODO: refactor if (pInfo->blockType == STREAM_DATA_TYPE_SSDATA_BLOCK) { if (pInfo->validBlockIndex >= total) { /*doClearBufferedBlocks(pInfo);*/ @@ -921,7 +926,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { SSDataBlock* pBlock = taosArrayGetP(pInfo->pBlockLists, current); blockDataUpdateTsWindow(pBlock, 0); return pBlock; - } else { + } else if (pInfo->blockType == STREAM_DATA_TYPE_SUBMIT_BLOCK) { if (pInfo->scanMode == STREAM_SCAN_FROM_RES) { blockDataDestroy(pInfo->pUpdateRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; @@ -961,13 +966,13 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { blockDataCleanup(pInfo->pRes); while (tqNextDataBlock(pInfo->streamBlockReader)) { - SArray* pCols = NULL; - uint64_t groupId = 0; - uint64_t uid = 0; - int32_t numOfRows = 0; - int16_t outputCol = 0; + SSDataBlock block = {0}; + uint64_t groupId = 0; + uint64_t uid = 0; + int32_t numOfRows = 0; - int32_t code = tqRetrieveDataBlock(&pCols, pInfo->streamBlockReader, &groupId, &uid, &numOfRows, &outputCol); + // todo refactor + int32_t code = tqRetrieveDataBlock(&block, pInfo->streamBlockReader, &groupId, &uid, &numOfRows); if (code != TSDB_CODE_SUCCESS || numOfRows == 0) { pTaskInfo->code = code; @@ -978,6 +983,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { pInfo->pRes->info.rows = numOfRows; pInfo->pRes->info.uid = uid; pInfo->pRes->info.type = STREAM_NORMAL; + pInfo->pRes->info.capacity = numOfRows; // for generating rollup SMA result, each time is an independent time serie. // TODO temporarily used, when the statement of "partition by tbname" is ready, remove this @@ -992,6 +998,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { pInfo->pRes->info.groupId = *groupIdPre; } + // todo extract method for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) { SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); if (!pColMatchInfo->output) { @@ -999,8 +1006,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { } bool colExists = false; - for (int32_t j = 0; j < taosArrayGetSize(pCols); ++j) { - SColumnInfoData* pResCol = taosArrayGet(pCols, j); + for (int32_t j = 0; j < blockDataGetNumOfCols(&block); ++j) { + SColumnInfoData* pResCol = bdGetColumnInfoData(&block, j); if (pResCol->info.colId == pColMatchInfo->colId) { taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol); colExists = true; @@ -1011,11 +1018,13 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { // the required column does not exists in submit block, let's set it to be all null value if (!colExists) { SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId); - colInfoDataEnsureCapacity(pDst, 0, pBlockInfo->rows); colDataAppendNNULL(pDst, 0, pBlockInfo->rows); } } + // TODO refactor @liao + taosArrayDestroy(block.pDataBlock); + if (pInfo->pRes->pDataBlock == NULL) { // TODO add log pOperator->status = OP_EXEC_DONE; @@ -1055,6 +1064,14 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { } return (pBlockInfo->rows == 0) ? NULL : pInfo->pRes; + + } else if (pInfo->blockType == STREAM_DATA_TYPE_FROM_SNAPSHOT) { + SSDataBlock* pResult = doTableScan(pInfo->pSnapshotReadOp); + return pResult && pResult->info.rows > 0 ? pResult : NULL; + + } else { + ASSERT(0); + return NULL; } } @@ -1119,7 +1136,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan } else { pInfo->pUpdateInfo = NULL; } - pInfo->pOperatorDumy = pTableScanDummy; + pInfo->pSnapshotReadOp = pTableScanDummy; pInfo->interval = pSTInfo->interval; pInfo->readHandle = *pHandle; @@ -1146,7 +1163,6 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan pInfo->pRes = createResDataBlock(pDescNode); pInfo->pUpdateRes = createResDataBlock(pDescNode); pInfo->pCondition = pScanPhyNode->node.pConditions; - pInfo->pDataReader = pDataReader; pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; pInfo->sessionSup = (SessionWindowSupporter){.pStreamAggSup = NULL, .gap = -1}; pInfo->groupId = 0; @@ -1156,7 +1172,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = pInfo->pRes->info.numOfCols; + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = @@ -1284,7 +1300,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { SColumnInfoData* pSrc = taosArrayGet(pInfo->pRes->pDataBlock, i); if (keep) { - colDataAssign(pDest, pSrc, pInfo->pRes->info.rows); + colDataAssign(pDest, pSrc, pInfo->pRes->info.rows, &px->info); numOfRow = pInfo->pRes->info.rows; } else if (NULL != rowRes) { numOfRow = 0; @@ -1314,8 +1330,6 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { } static SSDataBlock* buildSysTableMetaBlock() { - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - size_t size = 0; const SSysTableMeta* pMeta = NULL; getInfosDbMeta(&pMeta, &size); @@ -1328,19 +1342,13 @@ static SSDataBlock* buildSysTableMetaBlock() { } } - pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); - + SSDataBlock* pBlock = createDataBlock(); for (int32_t i = 0; i < pMeta[index].colNum; ++i) { - SColumnInfoData colInfoData = {0}; - colInfoData.info.colId = i + 1; - colInfoData.info.type = pMeta[index].schema[i].type; - colInfoData.info.bytes = pMeta[index].schema[i].bytes; - taosArrayPush(pBlock->pDataBlock, &colInfoData); + SColumnInfoData colInfoData = + createColumnInfoData(pMeta[index].schema[i].type, pMeta[index].schema[i].bytes, i + 1); + blockDataAppendColInfo(pBlock, &colInfoData); } - pBlock->info.numOfCols = pMeta[index].colNum; - pBlock->info.hasVarCol = true; - return pBlock; } @@ -1371,7 +1379,6 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { } blockDataCleanup(pInfo->pRes); - int32_t numOfRows = 0; const char* db = NULL; @@ -1541,11 +1548,15 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { return NULL; } + int32_t msgType = (strcasecmp(name, TSDB_INS_TABLE_DNODE_VARIABLES) == 0) ? TDMT_DND_SYSTABLE_RETRIEVE + : TDMT_MND_SYSTABLE_RETRIEVE; + pMsgSendInfo->param = pOperator; pMsgSendInfo->msgInfo.pData = buf1; pMsgSendInfo->msgInfo.len = contLen; - pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE; + pMsgSendInfo->msgType = msgType; pMsgSendInfo->fp = loadSysTableCallback; + pMsgSendInfo->requestId = pTaskInfo->id.queryId; int64_t transporterId = 0; int32_t code = @@ -1563,7 +1574,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { if (pRsp->numOfRows == 0 || pRsp->completed) { pOperator->status = OP_EXEC_DONE; - qDebug("%s load meta data from mnode completed, rowsOfSource:%d, totalRows:%" PRIu64 " ", GET_TASKID(pTaskInfo), + qDebug("%s load meta data from mnode completed, rowsOfSource:%d, totalRows:%" PRIu64, GET_TASKID(pTaskInfo), pRsp->numOfRows, pInfo->loadInfo.totalRows); if (pRsp->numOfRows == 0) { @@ -1580,6 +1591,8 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { taosMemoryFree(pRsp); if (pInfo->pRes->info.rows > 0) { return pInfo->pRes; + } else if (pOperator->status == OP_EXEC_DONE) { + return NULL; } } } @@ -1688,7 +1701,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = pResBlock->info.numOfCols; + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pResBlock->pDataBlock); pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = @@ -1822,7 +1835,8 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { } else { data = (char*)p; } - colDataAppend(pDst, count, data, (data == NULL)); + colDataAppend(pDst, count, data, + (data == NULL) || (pDst->info.type == TSDB_DATA_TYPE_JSON && tTagIsJsonNull(data))); if (pDst->info.type != TSDB_DATA_TYPE_JSON && p != NULL && IS_VAR_DATA_TYPE(((const STagVal*)p)->type) && data != NULL) { @@ -1845,9 +1859,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { } pRes->info.rows = count; - doFilter(pInfo->pFilterNode, pRes); - - pOperator->resultInfo.totalRows += pRes->info.rows; + pOperator->resultInfo.totalRows += count; return (pRes->info.rows == 0) ? NULL : pInfo->pRes; } @@ -1872,26 +1884,23 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi SExprInfo* pExprInfo = createExprInfo(pPhyNode->pScanPseudoCols, NULL, &numOfExprs); SArray* colList = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID); - int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs); if (code != TSDB_CODE_SUCCESS) { goto _error; } - pInfo->pTableList = pTableListInfo; - pInfo->pColMatchInfo = colList; - pInfo->pRes = createResDataBlock(pDescNode); - pInfo->readHandle = *pReadHandle; - pInfo->curPos = 0; - pInfo->pFilterNode = pPhyNode->node.pConditions; - + pInfo->pTableList = pTableListInfo; + pInfo->pColMatchInfo = colList; + pInfo->pRes = createResDataBlock(pDescNode); + pInfo->readHandle = *pReadHandle; + pInfo->curPos = 0; pOperator->name = "TagScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(pOperator, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); @@ -1909,6 +1918,12 @@ _error: } typedef struct STableMergeScanInfo { + STableListInfo* tableListInfo; + int32_t tableStartIndex; + int32_t tableEndIndex; + bool hasGroupId; + uint64_t groupId; + SArray* dataReaders; // array of tsdbReaderT* SReadHandle readHandle; @@ -1921,11 +1936,9 @@ typedef struct STableMergeScanInfo { SSDataBlock* pSortInputBlock; int64_t startTs; // sort start time - bool hasGroupId; - uint64_t groupId; - STupleHandle* prefetchedTuple; - - SArray* sortSourceParams; + SArray* sortSourceParams; + uint64_t queryId; + uint64_t taskId; SFileBlockLoadRecorder readRecorder; int64_t numOfRows; @@ -1953,29 +1966,42 @@ typedef struct STableMergeScanInfo { // window to check if current data block needs to be loaded. SSampleExecInfo sample; // sample execution info - int32_t curTWinIdx; - } STableMergeScanInfo; -int32_t createMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, - STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId, - uint64_t taskId, SNode* pTagCond) { - int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo, pTagCond); +int32_t compareTableKeyInfoByGid(const void* p1, const void* p2) { + const STableKeyInfo* info1 = p1; + const STableKeyInfo* info2 = p2; + return info1->groupId - info2->groupId; +} + +int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId) { + int32_t code = getTableList(pHandle->meta, &pTableScanNode->scan, pTableListInfo); if (code != TSDB_CODE_SUCCESS) { - goto _error; + return code; } if (taosArrayGetSize(pTableListInfo->pTableList) == 0) { qDebug("no table qualified for query, TID:0x%" PRIx64 ", QID:0x%" PRIx64, taskId, queryId); - goto _error; + return TSDB_CODE_SUCCESS; } + SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionTags); + generateGroupIdMap(pTableListInfo, pHandle, groupKeys); // todo for json + if (groupKeys) { + taosArraySort(pTableListInfo->pTableList, compareTableKeyInfoByGid); + } + taosArrayDestroy(groupKeys); + return TSDB_CODE_SUCCESS; +} +int32_t doCreateMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, + STableListInfo* pTableListInfo, SArray* arrayReader, uint64_t queryId, + uint64_t taskId) { SQueryTableDataCond cond = {0}; - code = initQueryTableDataCond(&cond, pTableScanNode); + int32_t code = initQueryTableDataCond(&cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { goto _error; } - // TODO: free the sublist info and the table list in it for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); ++i) { STableListInfo* subListInfo = taosMemoryCalloc(1, sizeof(subListInfo)); subListInfo->pTableList = taosArrayInit(1, sizeof(STableKeyInfo)); @@ -1989,12 +2015,31 @@ int32_t createMultipleDataReaders(STableScanPhysiNode* pTableScanNode, SReadHand } cleanupQueryTableDataCond(&cond); - return 0; + return TSDB_CODE_SUCCESS; _error: return code; } +int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, STableListInfo* pTableListInfo, + int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, uint64_t queryId, + uint64_t taskId) { + for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) { + STableListInfo* subListInfo = taosMemoryCalloc(1, sizeof(subListInfo)); + subListInfo->pTableList = taosArrayInit(1, sizeof(STableKeyInfo)); + taosArrayPush(subListInfo->pTableList, taosArrayGet(pTableListInfo->pTableList, i)); + + tsdbReaderT* pReader = tsdbReaderOpen(pHandle->vnode, pQueryCond, subListInfo, queryId, taskId); + taosArrayPush(arrayReader, &pReader); + + taosArrayDestroy(subListInfo->pTableList); + taosMemoryFree(subListInfo); + } + + return TSDB_CODE_SUCCESS; +} + +// todo refactor static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeScanInfo* pTableScanInfo, int32_t readerIdx, SSDataBlock* pBlock, uint32_t* status) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -2025,7 +2070,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc pCost->skipBlocks += 1; // clear all data in pBlock that are set when handing the previous block - for (int32_t i = 0; i < pBlockInfo->numOfCols; ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* pcol = taosArrayGet(pBlock->pDataBlock, i); pcol->pData = NULL; } @@ -2040,7 +2085,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc tsdbRetrieveDataBlockStatisInfo(reader, &pColAgg, &allColumnsHaveAgg); if (allColumnsHaveAgg == true) { - int32_t numOfCols = pBlock->info.numOfCols; + int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); // todo create this buffer during creating operator if (pBlock->pBlockAgg == NULL) { @@ -2135,7 +2180,13 @@ static SSDataBlock* getTableDataBlock(void* param) { continue; } - tsdbRetrieveDataBlockInfo(reader, &pBlock->info); + blockDataCleanup(pBlock); + SDataBlockInfo binfo = pBlock->info; + tsdbRetrieveDataBlockInfo(reader, &binfo); + + binfo.capacity = binfo.rows; + blockDataEnsureCapacity(pBlock, binfo.capacity); + pBlock->info = binfo; uint32_t status = 0; int32_t code = loadDataBlockFromOneTable(pOperator, pTableScanInfo, readerIdx, pBlock, &status); @@ -2174,22 +2225,47 @@ SArray* generateSortByTsInfo(int32_t order) { return pList; } -int32_t doOpenTableMergeScanOperator(SOperatorInfo* pOperator) { +int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { STableMergeScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - if (OPTR_IS_OPENED(pOperator)) { - return TSDB_CODE_SUCCESS; + { + size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList); + int32_t i = pInfo->tableStartIndex + 1; + for (; i < tableListSize; ++i) { + STableKeyInfo* tableKeyInfo = taosArrayGet(pInfo->tableListInfo->pTableList, i); + if (tableKeyInfo->groupId != pInfo->groupId) { + break; + } + } + pInfo->tableEndIndex = i - 1; } - int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; + int32_t tableStartIdx = pInfo->tableStartIndex; + int32_t tableEndIdx = pInfo->tableEndIndex; + STableListInfo* tableListInfo = pInfo->tableListInfo; + createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableListInfo, tableStartIdx, tableEndIdx, + pInfo->dataReaders, pInfo->queryId, pInfo->taskId); + + // todo the total available buffer should be determined by total capacity of buffer of this task. + // the additional one is reserved for merge result + pInfo->sortBufSize = pInfo->bufPageSize * (tableEndIdx - tableStartIdx + 1 + 1); + int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, pInfo->pSortInputBlock, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlock, NULL, NULL); size_t numReaders = taosArrayGetSize(pInfo->dataReaders); + for (int32_t i = 0; i < numReaders; ++i) { + STableMergeScanSortSourceParam param = {0}; + param.readerIdx = i; + param.pOperator = pOperator; + param.inputBlock = createOneDataBlock(pInfo->pResBlock, false); + taosArrayPush(pInfo->sortSourceParams, ¶m); + } + for (int32_t i = 0; i < numReaders; ++i) { SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); STableMergeScanSortSourceParam* param = taosArrayGet(pInfo->sortSourceParams, i); @@ -2203,9 +2279,22 @@ int32_t doOpenTableMergeScanOperator(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, terrno); } - pOperator->status = OP_RES_TO_RETURN; + return TSDB_CODE_SUCCESS; +} + +int32_t stopGroupTableMergeScan(SOperatorInfo* pOperator) { + STableMergeScanInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + tsortDestroySortHandle(pInfo->pSortHandle); + taosArrayClear(pInfo->sortSourceParams); + + for (int32_t i = 0; i < taosArrayGetSize(pInfo->dataReaders); ++i) { + tsdbReaderT* reader = taosArrayGetP(pInfo->dataReaders, i); + tsdbCleanupReadHandle(reader); + } + taosArrayDestroy(pInfo->dataReaders); - OPTR_SET_OPENED(pOperator); return TSDB_CODE_SUCCESS; } @@ -2248,14 +2337,38 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, code); } + size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList); + if (!pInfo->hasGroupId) { + pInfo->hasGroupId = true; - SSDataBlock* pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator); - - if (pBlock != NULL) { - pOperator->resultInfo.totalRows += pBlock->info.rows; - } else { - doSetOperatorCompleted(pOperator); + if (tableListSize == 0) { + doSetOperatorCompleted(pOperator); + return NULL; + } + pInfo->tableStartIndex = 0; + pInfo->groupId = ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId; + startGroupTableMergeScan(pOperator); } + SSDataBlock* pBlock = NULL; + while (pInfo->tableStartIndex < tableListSize) { + pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pOperator->resultInfo.capacity, pOperator); + if (pBlock != NULL) { + pBlock->info.groupId = pInfo->groupId; + pOperator->resultInfo.totalRows += pBlock->info.rows; + return pBlock; + } else { + stopGroupTableMergeScan(pOperator); + if (pInfo->tableEndIndex >= tableListSize - 1) { + doSetOperatorCompleted(pOperator); + break; + } + pInfo->tableStartIndex = pInfo->tableEndIndex + 1; + pInfo->groupId = + ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId; + startGroupTableMergeScan(pOperator); + } + } + return pBlock; } @@ -2263,17 +2376,10 @@ void destroyTableMergeScanOperatorInfo(void* param, int32_t numOfOutput) { STableMergeScanInfo* pTableScanInfo = (STableMergeScanInfo*)param; cleanupQueryTableDataCond(&pTableScanInfo->cond); - for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->dataReaders); ++i) { - tsdbReaderT* reader = taosArrayGetP(pTableScanInfo->dataReaders, i); - tsdbCleanupReadHandle(reader); - } - taosArrayDestroy(pTableScanInfo->dataReaders); - if (pTableScanInfo->pColMatchInfo != NULL) { taosArrayDestroy(pTableScanInfo->pColMatchInfo); } - taosArrayDestroy(pTableScanInfo->sortSourceParams); pTableScanInfo->pResBlock = blockDataDestroy(pTableScanInfo->pResBlock); pTableScanInfo->pSortInputBlock = blockDataDestroy(pTableScanInfo->pSortInputBlock); @@ -2299,8 +2405,9 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla return TSDB_CODE_SUCCESS; } -SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SArray* dataReaders, - SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo* pTableListInfo, + SReadHandle* readHandle, SExecTaskInfo* pTaskInfo, uint64_t queryId, + uint64_t taskId) { STableMergeScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableMergeScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -2330,22 +2437,16 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pInfo->sample.seed = taosGetTimestampSec(); pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; - pInfo->dataReaders = dataReaders; + pInfo->tableListInfo = pTableListInfo; pInfo->scanFlag = MAIN_SCAN; pInfo->pColMatchInfo = pColList; - pInfo->curTWinIdx = 0; pInfo->pResBlock = createResDataBlock(pDescNode); + pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES); + pInfo->queryId = queryId; + pInfo->taskId = taskId; - pInfo->sortSourceParams = taosArrayInit(taosArrayGetSize(dataReaders), sizeof(STableMergeScanSortSourceParam)); - for (int32_t i = 0; i < taosArrayGetSize(dataReaders); ++i) { - STableMergeScanSortSourceParam* param = taosMemoryCalloc(1, sizeof(STableMergeScanSortSourceParam)); - param->readerIdx = i; - param->pOperator = pOperator; - param->inputBlock = createOneDataBlock(pInfo->pResBlock, false); - taosArrayPush(pInfo->sortSourceParams, param); - taosMemoryFree(param); - } + pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam)); pInfo->pSortInfo = generateSortByTsInfo(pInfo->cond.order); pInfo->pSortInputBlock = createOneDataBlock(pInfo->pResBlock, false); @@ -2353,14 +2454,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN int32_t rowSize = pInfo->pResBlock->info.rowSize; pInfo->bufPageSize = getProperSortPageSize(rowSize); - // todo the total available buffer should be determined by total capacity of buffer of this task. - // the additional one is reserved for merge result - pInfo->sortBufSize = pInfo->bufPageSize * (taosArrayGetSize(dataReaders) + 1); - pInfo->hasGroupId = false; - pInfo->prefetchedTuple = NULL; - pOperator->name = "TableMergeScanOperator"; - // TODO : change it pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN; pOperator->blocking = false; pOperator->status = OP_NOT_OPENED; @@ -2370,8 +2464,8 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN initResultSizeInfo(pOperator, 1024); pOperator->fpSet = - createOperatorFpSet(doOpenTableMergeScanOperator, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, - NULL, NULL, getTableMergeScanExplainExecInfo); + createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, NULL, + NULL, getTableMergeScanExplainExecInfo); pOperator->cost.openCost = 0; return pOperator; diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 8970d84560..09cc4e47be 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -22,10 +22,11 @@ static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput); -SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortPhyNode, + SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL/* || rowSize > 100 * 1024 * 1024*/) { + if (pInfo == NULL || pOperator == NULL /* || rowSize > 100 * 1024 * 1024*/) { goto _error; } @@ -44,16 +45,17 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* initResultSizeInfo(pOperator, 1024); - pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys);; - pInfo->pColMatchInfo = pColMatchColInfo; - pOperator->name = "SortOperator"; + pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); + ; + pInfo->pColMatchInfo = pColMatchColInfo; + pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->exprSupp.pExprInfo = pExprInfo; + pOperator->exprSupp.numOfExprs = numOfCols; + pOperator->pTaskInfo = pTaskInfo; // lazy evaluation for the following parameter since the input datablock is not known till now. // pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; @@ -78,7 +80,7 @@ _error: } void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) { - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); bool isNull = tsortIsNullVal(pTupleHandle, i); if (isNull) { @@ -118,6 +120,9 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i } if (p->info.rows > 0) { + blockDataEnsureCapacity(pDataBlock, capacity); + + // todo extract function to handle this int32_t numOfCols = taosArrayGetSize(pColMatchInfo); for (int32_t i = 0; i < numOfCols; ++i) { SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i); @@ -125,11 +130,10 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); - colDataAssign(pDst, pSrc, p->info.rows); + colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info); } pDataBlock->info.rows = p->info.rows; - pDataBlock->info.capacity = p->info.rows; } blockDataDestroy(p); @@ -146,8 +150,8 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) { SOperatorInfo* pOperator = param; SSortOperatorInfo* pSort = pOperator->info; if (pOperator->exprSupp.pExprInfo != NULL) { - int32_t code = - projectApplyFunctions(pOperator->exprSupp.pExprInfo, pBlock, pBlock, pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs, NULL); + int32_t code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pBlock, pBlock, pOperator->exprSupp.pCtx, + pOperator->exprSupp.numOfExprs, NULL); if (code != TSDB_CODE_SUCCESS) { longjmp(pOperator->pTaskInfo->env, code); } @@ -165,8 +169,7 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) { pInfo->startTs = taosGetTimestampUs(); // pInfo->binfo.pRes is not equalled to the input datablock. - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, - NULL, pTaskInfo->id.str); + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator); @@ -232,63 +235,31 @@ int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* return TSDB_CODE_SUCCESS; } -typedef struct SMultiwaySortMergeOperatorInfo { +//===================================================================================== +// Group Sort Operator +typedef enum EChildOperatorStatus { CHILD_OP_NEW_GROUP, CHILD_OP_SAME_GROUP, CHILD_OP_FINISHED } EChildOperatorStatus; + +typedef struct SGroupSortOperatorInfo { SOptrBasicInfo binfo; + SArray* pSortInfo; + SArray* pColMatchInfo; - int32_t bufPageSize; - uint32_t sortBufSize; // max buffer size for in-memory sort + int64_t startTs; + uint64_t sortElapsed; + bool hasGroupId; + uint64_t currGroupId; - SArray* pSortInfo; - SSortHandle* pSortHandle; - SArray* pColMatchInfo; // for index map from table scan output + SSDataBlock* prefetchedSortInput; + SSortHandle* pCurrSortHandle; + EChildOperatorStatus childOpStatus; - SSDataBlock* pInputBlock; - int64_t startTs; // sort start time - uint64_t groupId; -} SMultiwaySortMergeOperatorInfo; - -int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) { - SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - if (OPTR_IS_OPENED(pOperator)) { - return TSDB_CODE_SUCCESS; - } - - pInfo->startTs = taosGetTimestampUs(); - - int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, - pInfo->bufPageSize, numOfBufPage, pInfo->pInputBlock, pTaskInfo->id.str); - - tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL); - - for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { - SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); - ps->param = pOperator->pDownstream[i]; - tsortAddSource(pInfo->pSortHandle, ps); - } - - int32_t code = tsortOpen(pInfo->pSortHandle); - - if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, terrno); - } - - pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; - pOperator->status = OP_RES_TO_RETURN; - - OPTR_SET_OPENED(pOperator); - return TSDB_CODE_SUCCESS; -} - -SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, - SArray* pColMatchInfo, SOperatorInfo* pOperator) { - SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SSortExecInfo sortExecInfo; +} SGroupSortOperatorInfo; +SSDataBlock* getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, + SArray* pColMatchInfo, SGroupSortOperatorInfo* pInfo) { blockDataCleanup(pDataBlock); + blockDataEnsureCapacity(pDataBlock, capacity); SSDataBlock* p = tsortGetSortedDataBlock(pHandle); if (p == NULL) { @@ -317,11 +288,302 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); - colDataAssign(pDst, pSrc, p->info.rows); + colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info); } pDataBlock->info.rows = p->info.rows; pDataBlock->info.capacity = p->info.rows; + } + + blockDataDestroy(p); + return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; +} + +typedef struct SGroupSortSourceParam { + SOperatorInfo* childOpInfo; + SGroupSortOperatorInfo* grpSortOpInfo; +} SGroupSortSourceParam; + +SSDataBlock* fetchNextGroupSortDataBlock(void* param) { + SGroupSortSourceParam* source = param; + SGroupSortOperatorInfo* grpSortOpInfo = source->grpSortOpInfo; + if (grpSortOpInfo->prefetchedSortInput) { + SSDataBlock* block = grpSortOpInfo->prefetchedSortInput; + grpSortOpInfo->prefetchedSortInput = NULL; + return block; + } else { + SOperatorInfo* childOp = source->childOpInfo; + SSDataBlock* block = childOp->fpSet.getNextFn(childOp); + if (block != NULL) { + if (block->info.groupId == grpSortOpInfo->currGroupId) { + grpSortOpInfo->childOpStatus = CHILD_OP_SAME_GROUP; + return block; + } else { + grpSortOpInfo->childOpStatus = CHILD_OP_NEW_GROUP; + grpSortOpInfo->prefetchedSortInput = block; + return NULL; + } + } else { + grpSortOpInfo->childOpStatus = CHILD_OP_FINISHED; + return NULL; + } + } +} + +int32_t beginSortGroup(SOperatorInfo* pOperator) { + SGroupSortOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + // pInfo->binfo.pRes is not equalled to the input datablock. + pInfo->pCurrSortHandle = + tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str); + + tsortSetFetchRawDataFp(pInfo->pCurrSortHandle, fetchNextGroupSortDataBlock, applyScalarFunction, pOperator); + + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); + SGroupSortSourceParam* param = taosMemoryCalloc(1, sizeof(SGroupSortSourceParam)); + param->childOpInfo = pOperator->pDownstream[0]; + param->grpSortOpInfo = pInfo; + ps->param = param; + tsortAddSource(pInfo->pCurrSortHandle, ps); + + int32_t code = tsortOpen(pInfo->pCurrSortHandle); + taosMemoryFreeClear(ps); + + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, terrno); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t finishSortGroup(SOperatorInfo* pOperator) { + SGroupSortOperatorInfo* pInfo = pOperator->info; + + SSortExecInfo sortExecInfo = tsortGetSortExecInfo(pInfo->pCurrSortHandle); + pInfo->sortExecInfo.sortMethod = sortExecInfo.sortMethod; + pInfo->sortExecInfo.sortBuffer = sortExecInfo.sortBuffer; + pInfo->sortExecInfo.loops += sortExecInfo.loops; + pInfo->sortExecInfo.readBytes += sortExecInfo.readBytes; + pInfo->sortExecInfo.writeBytes += sortExecInfo.writeBytes; + if (pInfo->pCurrSortHandle != NULL) { + tsortDestroySortHandle(pInfo->pCurrSortHandle); + } + pInfo->pCurrSortHandle = NULL; + return TSDB_CODE_SUCCESS; +} + +SSDataBlock* doGroupSort(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SGroupSortOperatorInfo* pInfo = pOperator->info; + + int32_t code = pOperator->fpSet._openFn(pOperator); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + if (!pInfo->hasGroupId) { + pInfo->hasGroupId = true; + + pInfo->prefetchedSortInput = pOperator->pDownstream[0]->fpSet.getNextFn(pOperator->pDownstream[0]); + if (pInfo->prefetchedSortInput == NULL) { + doSetOperatorCompleted(pOperator); + return NULL; + } + pInfo->currGroupId = pInfo->prefetchedSortInput->info.groupId; + pInfo->childOpStatus = CHILD_OP_NEW_GROUP; + beginSortGroup(pOperator); + } + + SSDataBlock* pBlock = NULL; + while (pInfo->pCurrSortHandle != NULL) { + // beginSortGroup would fetch all child blocks of pInfo->currGroupId; + ASSERT(pInfo->childOpStatus != CHILD_OP_SAME_GROUP); + pBlock = getGroupSortedBlockData(pInfo->pCurrSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, + pInfo->pColMatchInfo, pInfo); + if (pBlock != NULL) { + pBlock->info.groupId = pInfo->currGroupId; + pOperator->resultInfo.totalRows += pBlock->info.rows; + return pBlock; + } else { + if (pInfo->childOpStatus == CHILD_OP_NEW_GROUP) { + finishSortGroup(pOperator); + pInfo->currGroupId = pInfo->prefetchedSortInput->info.groupId; + beginSortGroup(pOperator); + } else if (pInfo->childOpStatus == CHILD_OP_FINISHED) { + finishSortGroup(pOperator); + doSetOperatorCompleted(pOperator); + return NULL; + } + } + } + return NULL; +} + +int32_t getGroupSortExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { + SGroupSortOperatorInfo* pInfo = (SGroupSortOperatorInfo*)pOptr->info; + *pOptrExplain = &pInfo->sortExecInfo; + *len = sizeof(SSortExecInfo); + return TSDB_CODE_SUCCESS; +} + +void destroyGroupSortOperatorInfo(void* param, int32_t numOfOutput) { + SGroupSortOperatorInfo* pInfo = (SGroupSortOperatorInfo*)param; + pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes); + + taosArrayDestroy(pInfo->pSortInfo); + taosArrayDestroy(pInfo->pColMatchInfo); +} + +SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, + SExecTaskInfo* pTaskInfo) { + SGroupSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupSortOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL /* || rowSize > 100 * 1024 * 1024*/) { + goto _error; + } + + SDataBlockDescNode* pDescNode = pSortPhyNode->node.pOutputDataBlockDesc; + + int32_t numOfCols = 0; + SSDataBlock* pResBlock = createResDataBlock(pDescNode); + SExprInfo* pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols); + + int32_t numOfOutputCols = 0; + SArray* pColMatchColInfo = + extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); + + pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); + pInfo->binfo.pRes = pResBlock; + + initResultSizeInfo(pOperator, 1024); + + pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); + ; + pInfo->pColMatchInfo = pColMatchColInfo; + pOperator->name = "GroupSortOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->exprSupp.pExprInfo = pExprInfo; + pOperator->exprSupp.numOfExprs = numOfCols; + pOperator->pTaskInfo = pTaskInfo; + + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doGroupSort, NULL, NULL, destroyGroupSortOperatorInfo, NULL, + NULL, getGroupSortExplainExecInfo); + + int32_t code = appendDownstream(pOperator, &downstream, 1); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + return pOperator; + +_error: + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + return NULL; +} + +//===================================================================================== +// Multiway Sort Merge operator +typedef struct SMultiwaySortMergeOperatorInfo { + SOptrBasicInfo binfo; + + int32_t bufPageSize; + uint32_t sortBufSize; // max buffer size for in-memory sort + + SArray* pSortInfo; + SSortHandle* pSortHandle; + SArray* pColMatchInfo; // for index map from table scan output + + SSDataBlock* pInputBlock; + int64_t startTs; // sort start time + uint64_t groupId; +} SMultiwaySortMergeOperatorInfo; + +int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) { + SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + if (OPTR_IS_OPENED(pOperator)) { + return TSDB_CODE_SUCCESS; + } + + pInfo->startTs = taosGetTimestampUs(); + + int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; + + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, + pInfo->pInputBlock, pTaskInfo->id.str); + + tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL); + tsortSetCompareGroupId(pInfo->pSortHandle, true); + + for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); + ps->param = pOperator->pDownstream[i]; + tsortAddSource(pInfo->pSortHandle, ps); + } + + int32_t code = tsortOpen(pInfo->pSortHandle); + + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, terrno); + } + + pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; + pOperator->status = OP_RES_TO_RETURN; + + OPTR_SET_OPENED(pOperator); + return TSDB_CODE_SUCCESS; +} + +SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, + SArray* pColMatchInfo, SOperatorInfo* pOperator) { + SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + blockDataCleanup(pDataBlock); + + SSDataBlock* p = tsortGetSortedDataBlock(pHandle); + if (p == NULL) { + return NULL; + } + + blockDataEnsureCapacity(p, capacity); + + while (1) { + STupleHandle* pTupleHandle = tsortNextTuple(pHandle); + if (pTupleHandle == NULL) { + break; + } + + appendOneRowToDataBlock(p, pTupleHandle); + if (p->info.rows >= capacity) { + break; + } + } + + if (p->info.rows > 0) {// todo extract method + blockDataEnsureCapacity(pDataBlock, p->info.rows); + int32_t numOfCols = taosArrayGetSize(pColMatchInfo); + for (int32_t i = 0; i < numOfCols; ++i) { + SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i); + ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); + + SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); + SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId); + colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info); + } + + pDataBlock->info.rows = p->info.rows; pDataBlock->info.groupId = pInfo->groupId; } @@ -387,24 +649,23 @@ SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams, goto _error; } - initResultSizeInfo(pOperator, 1024); - pInfo->binfo.pRes = pResBlock; - pInfo->pSortInfo = pSortInfo; + pInfo->binfo.pRes = pResBlock; + pInfo->pSortInfo = pSortInfo; pInfo->pColMatchInfo = pColMatchColInfo; - pInfo->pInputBlock = pInputBlock; - pOperator->name = "MultiwaySortMerge"; + pInfo->pInputBlock = pInputBlock; + pOperator->name = "MultiwaySortMerge"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - pInfo->bufPageSize = getProperSortPageSize(rowSize); + pInfo->bufPageSize = getProperSortPageSize(rowSize); // one additional is reserved for merged result. - pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); + pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); pOperator->fpSet = createOperatorFpSet(doOpenMultiwaySortMergeOperator, doMultiwaySortMerge, NULL, NULL, diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 110c2d6a8f..1d82d6a644 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -50,7 +50,7 @@ static void setTagsValue(SFillInfo* pFillInfo, void** data, int32_t genRows) { static void setNullRow(SSDataBlock* pBlock, int32_t numOfCol, int32_t rowIndex) { // the first are always the timestamp column, so start from the second column. - for (int32_t i = 1; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 1; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* p = taosArrayGet(pBlock->pDataBlock, i); colDataAppendNULL(p, rowIndex); } diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index f0358b6d7b..21c265e03d 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -684,6 +684,7 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num } void printDataBlock(SSDataBlock* pBlock, const char* flag) { + if (pBlock == NULL) return; SArray* blocks = taosArrayInit(1, sizeof(SSDataBlock)); taosArrayPush(blocks, pBlock); blockDebugShowData(blocks, flag); @@ -1655,10 +1656,9 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { doBuildResultDatablock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); if (pBInfo->pRes->info.rows == 0 || !hasDataInGroupInfo(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); - return NULL; } - return pBInfo->pRes; + return pBInfo->pRes->info.rows > 0 ? pBInfo->pRes : NULL; } int64_t st = taosGetTimestampUs(); @@ -1814,7 +1814,7 @@ static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB return TSDB_CODE_OUT_OF_MEMORY; } - int32_t numOfCols = pBlock->info.numOfCols; + int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); @@ -2231,23 +2231,23 @@ static void clearStreamIntervalOperator(SStreamFinalIntervalOperatorInfo* pInfo) } static void clearUpdateDataBlock(SSDataBlock* pBlock) { - if (pBlock->info.rows <= 0) { - return; - } blockDataCleanup(pBlock); } void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex) { - ASSERT(pDest->info.capacity >= pSource->info.rows); + // ASSERT(pDest->info.capacity >= pSource->info.rows); + blockDataEnsureCapacity(pDest, pSource->info.rows); clearUpdateDataBlock(pDest); SColumnInfoData* pDestCol = taosArrayGet(pDest->pDataBlock, 0); SColumnInfoData* pSourceCol = taosArrayGet(pSource->pDataBlock, tsColIndex); + // copy timestamp column - colDataAssign(pDestCol, pSourceCol, pSource->info.rows); - for (int32_t i = 1; i < pDest->info.numOfCols; i++) { + colDataAssign(pDestCol, pSourceCol, pSource->info.rows, &pDest->info); + for (int32_t i = 1; i < taosArrayGetSize(pDest->pDataBlock); i++) { SColumnInfoData* pCol = taosArrayGet(pDest->pDataBlock, i); colDataAppendNNULL(pCol, 0, pSource->info.rows); } + pDest->info.rows = pSource->info.rows; pDest->info.groupId = pSource->info.groupId; pDest->info.type = pSource->info.type; @@ -2917,7 +2917,7 @@ void doBuildDeleteDataBlock(SHashObj* pStDeleted, SSDataBlock* pBlock, void** It while (((*Ite) = taosHashIterate(pStDeleted, *Ite)) != NULL) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); colDataAppend(pColInfoData, pBlock->info.rows, *Ite, false); - for (int32_t i = 1; i < pBlock->info.numOfCols; i++) { + for (int32_t i = 1; i < taosArrayGetSize(pBlock->pDataBlock); i++) { pColInfoData = taosArrayGet(pBlock->pDataBlock, i); colDataAppendNULL(pColInfoData, pBlock->info.rows); } @@ -3027,12 +3027,14 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { } else if (pOperator->status == OP_RES_TO_RETURN) { doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); if (pInfo->pDelRes->info.rows > 0) { + /*printDataBlock(pInfo->pDelRes, "session del");*/ return pInfo->pDelRes; } doBuildResultDatablock(pOperator, pBInfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf); if (pBInfo->pRes->info.rows == 0 || !hasDataInGroupInfo(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } + /*printDataBlock(pBInfo->pRes, "session insert");*/ return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } @@ -3100,9 +3102,11 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); if (pInfo->pDelRes->info.rows > 0) { + /*printDataBlock(pInfo->pDelRes, "session del");*/ return pInfo->pDelRes; } doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->streamAggSup.pResultBuf); + /*printDataBlock(pBInfo->pRes, "session insert");*/ return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } @@ -4113,6 +4117,8 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SExprI goto _error; } + miaInfo->groupIntervalHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK); + SIntervalAggOperatorInfo* iaInfo = &miaInfo->intervalAggOperatorInfo; iaInfo->win = pTaskInfo->window; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 581935514e..50474ff62e 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -86,6 +86,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t page pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); pSortHandle->cmpParam.orderInfo = pSortInfo; + pSortHandle->cmpParam.cmpGroupId = false; tsortSetComparFp(pSortHandle, msortComparFn); @@ -146,7 +147,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSource int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation - int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock->info.numOfCols))/rowSize; + int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)))/rowSize; ASSERT(numOfRows > 0); return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -177,7 +178,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { return terrno; } - int32_t size = blockDataGetSize(p) + sizeof(int32_t) + p->info.numOfCols * sizeof(int32_t); + int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); blockDataToBuf(pPage, p); @@ -251,7 +252,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int } static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSource, int32_t* rowIndex) { - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); SColumnInfoData* pSrcColInfo = taosArrayGet(pSource->pDataBlock, i); @@ -374,6 +375,12 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { SSDataBlock* pLeftBlock = pLeftSource->src.pBlock; SSDataBlock* pRightBlock = pRightSource->src.pBlock; + if (pParam->cmpGroupId) { + if (pLeftBlock->info.groupId != pRightBlock->info.groupId) { + return pLeftBlock->info.groupId < pRightBlock->info.groupId ? -1 : 1; + } + } + for(int32_t i = 0; i < pInfo->size; ++i) { SBlockOrderInfo* pOrder = TARRAY_GET_ELEM(pInfo, i); SColumnInfoData* pLeftColInfoData = TARRAY_GET_ELEM(pLeftBlock->pDataBlock, pOrder->slotId); @@ -493,7 +500,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { return terrno; } - int32_t size = blockDataGetSize(pDataBlock) + sizeof(int32_t) + pDataBlock->info.numOfCols * sizeof(int32_t); + int32_t size = blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); blockDataToBuf(pPage, pDataBlock); @@ -680,6 +687,11 @@ int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp) { return TSDB_CODE_SUCCESS; } +int32_t tsortSetCompareGroupId(SSortHandle* pHandle, bool compareGroupId) { + pHandle->cmpParam.cmpGroupId = compareGroupId; + return TSDB_CODE_SUCCESS; +} + STupleHandle* tsortNextTuple(SSortHandle* pHandle) { if (pHandle->cmpParam.numOfSources == pHandle->numOfCompletedSources) { return NULL; diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp index dba2fb897a..3c12889aca 100644 --- a/source/libs/executor/test/executorTests.cpp +++ b/source/libs/executor/test/executorTests.cpp @@ -62,18 +62,11 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator) { } if (pInfo->pBlock == NULL) { - pInfo->pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); + pInfo->pBlock = createDataBlock(); - pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); - - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_INT; - colInfo.info.bytes = sizeof(int32_t); - colInfo.info.colId = 1; - colInfo.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); - colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); - - taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo); + SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1); + blockDataAppendColInfo(pInfo->pBlock, &colInfo); + blockDataEnsureCapacity(pInfo->pBlock, pInfo->numOfRowsPerPage); // SColumnInfoData colInfo1 = {0}; // colInfo1.info.type = TSDB_DATA_TYPE_BINARY; @@ -115,7 +108,6 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator) { } pBlock->info.rows = pInfo->numOfRowsPerPage; - pBlock->info.numOfCols = 1; pInfo->current += 1; return pBlock; @@ -128,28 +120,15 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator) { } if (pInfo->pBlock == NULL) { - pInfo->pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); + pInfo->pBlock = createDataBlock(); - pInfo->pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 1); + blockDataAppendColInfo(pInfo->pBlock, &colInfo); - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_TIMESTAMP; - colInfo.info.bytes = sizeof(int64_t); - colInfo.info.colId = 1; - colInfo.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int64_t))); - // colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); + SColumnInfoData colInfo1 = createColumnInfoData(TSDB_DATA_TYPE_INT, 4, 2); + blockDataAppendColInfo(pInfo->pBlock, &colInfo1); - taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo); - - SColumnInfoData colInfo1 = {0}; - colInfo1.info.type = TSDB_DATA_TYPE_INT; - colInfo1.info.bytes = 4; - colInfo1.info.colId = 2; - - colInfo1.pData = static_cast(taosMemoryCalloc(pInfo->numOfRowsPerPage, sizeof(int32_t))); - colInfo1.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->numOfRowsPerPage + 7) / 8)); - - taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1); + blockDataEnsureCapacity(pInfo->pBlock, pInfo->numOfRowsPerPage); } else { blockDataCleanup(pInfo->pBlock); } @@ -185,7 +164,6 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator) { } pBlock->info.rows = pInfo->numOfRowsPerPage; - pBlock->info.numOfCols = 1; pInfo->current += 1; diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 66ed078bbe..70def78263 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -62,25 +62,21 @@ SSDataBlock* getSingleColDummyBlock(void* param) { return NULL; } - SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); - pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + SSDataBlock* pBlock = createDataBlock(); SColumnInfoData colInfo = {0}; colInfo.info.type = pInfo->type; if (pInfo->type == TSDB_DATA_TYPE_NCHAR){ colInfo.info.bytes = TSDB_NCHAR_SIZE * VARCOUNT + VARSTR_HEADER_SIZE; - colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); } else if(pInfo->type == TSDB_DATA_TYPE_BINARY) { colInfo.info.bytes = VARCOUNT + VARSTR_HEADER_SIZE; - colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); } else{ colInfo.info.bytes = tDataTypes[pInfo->type].bytes; - colInfo.pData = static_cast(taosMemoryCalloc(pInfo->pageRows, colInfo.info.bytes)); - colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->pageRows + 7) / 8)); } colInfo.info.colId = 1; - taosArrayPush(pBlock->pDataBlock, &colInfo); + blockDataAppendColInfo(pBlock, &colInfo); + blockDataEnsureCapacity(pBlock, pInfo->pageRows); for (int32_t i = 0; i < pInfo->pageRows; ++i) { SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); @@ -128,7 +124,6 @@ SSDataBlock* getSingleColDummyBlock(void* param) { } pBlock->info.rows = pInfo->pageRows; - pBlock->info.numOfCols = 1; return pBlock; } @@ -354,15 +349,10 @@ TEST(testCase, ordered_merge_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); - pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - pBlock->info.numOfCols = 1; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_INT; - colInfo.info.bytes = sizeof(int32_t); - colInfo.info.colId = 1; - taosArrayPush(pBlock->pDataBlock, &colInfo); + SSDataBlock* pBlock = createDataBlock(); + for (int32_t i = 0; i < 1; ++i) { + SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1); + blockDataAppendColInfo(pBlock, &colInfo); } SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_MULTISOURCE_MERGE, 1024, 5, pBlock,"test_abc"); diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index e691d562c6..4d2f926c12 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -101,6 +101,11 @@ bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool derivativeFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); int32_t derivativeFunction(SqlFunctionCtx *pCtx); +bool getIrateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); +bool irateFuncSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo); +int32_t irateFunction(SqlFunctionCtx *pCtx); +int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); + bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t firstFunction(SqlFunctionCtx *pCtx); int32_t firstFunctionMerge(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/inc/taggfunction.h b/source/libs/function/inc/taggfunction.h index c3d61d426d..669c2635b5 100644 --- a/source/libs/function/inc/taggfunction.h +++ b/source/libs/function/inc/taggfunction.h @@ -28,19 +28,6 @@ extern "C" { #include "function.h" #include "tudf.h" - -extern SAggFunctionInfo aggFunc[35]; - -#define FUNCSTATE_SO 0x0u -#define FUNCSTATE_MO 0x1u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM -#define FUNCSTATE_STREAM 0x2u // function avail for stream -#define FUNCSTATE_STABLE 0x4u // function avail for super table -#define FUNCSTATE_NEED_TS 0x8u // timestamp is required during query processing -#define FUNCSTATE_SELECTIVITY 0x10u // selectivity functions, can exists along with tag columns - -#define BASIC_FUNC_SO FUNCSTATE_SO | FUNCSTATE_STREAM | FUNCSTATE_STABLE -#define BASIC_FUNC_MO FUNCSTATE_MO | FUNCSTATE_STREAM | FUNCSTATE_STABLE - #define AVG_FUNCTION_INTER_BUFFER_SIZE 50 #define DATA_SET_FLAG ',' // to denote the output area has data, not null value diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index cfad00f458..6516a10795 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -79,7 +79,8 @@ static int32_t translateIn2NumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_ uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_NUMERIC_TYPE(para1Type) || !IS_NUMERIC_TYPE(para2Type)) { + if ((!IS_NUMERIC_TYPE(para1Type) && !IS_NULL_TYPE(para1Type)) || + (!IS_NUMERIC_TYPE(para2Type) && !IS_NULL_TYPE(para2Type))) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } @@ -109,13 +110,13 @@ static int32_t translateLogarithm(SFunctionNode* pFunc, char* pErrBuf, int32_t l } uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; - if (!IS_NUMERIC_TYPE(para1Type)) { + if (!IS_NUMERIC_TYPE(para1Type) && !IS_NULL_TYPE(para1Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } if (2 == numOfParams) { uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; - if (!IS_NUMERIC_TYPE(para2Type)) { + if (!IS_NUMERIC_TYPE(para2Type) && !IS_NULL_TYPE(para2Type)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } } @@ -978,6 +979,21 @@ static int32_t translateDerivative(SFunctionNode* pFunc, char* pErrBuf, int32_t return TSDB_CODE_SUCCESS; } +static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + + if (!IS_NUMERIC_TYPE(colType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; + return TSDB_CODE_SUCCESS; +} + static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // first(col_list) will be rewritten as first(col) if (1 != LIST_LENGTH(pFunc->pParameterList)) { @@ -1252,6 +1268,29 @@ static bool validateMinuteRange(int8_t hour, int8_t minute, char sign) { return false; } +static bool validateTimestampDigits(const SValueNode* pVal) { + if (!IS_INTEGER_TYPE(pVal->node.resType.type)) { + return false; + } + + int64_t tsVal = pVal->datum.i; + char fraction[20] = {0}; + NUM_TO_STRING(pVal->node.resType.type, &tsVal, sizeof(fraction), fraction); + int32_t tsDigits = (int32_t)strlen(fraction); + + if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) { + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS || + tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS || + tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + return true; + } else { + return false; + } + } + + return true; +} + static bool validateTimezoneFormat(const SValueNode* pVal) { if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) { return false; @@ -1364,6 +1403,15 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } + if (QUERY_NODE_VALUE == nodeType(nodesListGetNode(pFunc->pParameterList, 0))) { + SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0); + + if (!validateTimestampDigits(pValue)) { + pFunc->node.resType = (SDataType){.bytes = 0, .type = TSDB_DATA_TYPE_BINARY}; + return TSDB_CODE_SUCCESS; + } + } + // param1 if (numOfParams == 2) { SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1); @@ -1796,10 +1844,20 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = derivativeFunction, .finalizeFunc = functionFinalize }, + { + .name = "irate", + .type = FUNCTION_TYPE_IRATE, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC, + .translateFunc = translateIrate, + .getEnvFunc = getIrateFuncEnv, + .initFunc = irateFuncSetup, + .processFunc = irateFunction, + .finalizeFunc = irateFinalize + }, { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, - .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_TIMELINE_FUNC, .translateFunc = translateLastRow, .getEnvFunc = getMinmaxFuncEnv, .initFunc = minmaxFunctionSetup, @@ -1966,7 +2024,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "diff", .type = FUNCTION_TYPE_DIFF, - .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_WINDOW_FUNC, .translateFunc = translateDiff, .getEnvFunc = getDiffFuncEnv, .initFunc = diffFunctionSetup, @@ -1976,7 +2034,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "statecount", .type = FUNCTION_TYPE_STATE_COUNT, - .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_WINDOW_FUNC, .translateFunc = translateStateCount, .getEnvFunc = getStateFuncEnv, .initFunc = functionSetup, @@ -1986,7 +2044,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "stateduration", .type = FUNCTION_TYPE_STATE_DURATION, - .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_WINDOW_FUNC, .translateFunc = translateStateDuration, .getEnvFunc = getStateFuncEnv, .initFunc = functionSetup, @@ -1996,7 +2054,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "csum", .type = FUNCTION_TYPE_CSUM, - .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_WINDOW_FUNC, .translateFunc = translateCsum, .getEnvFunc = getCsumFuncEnv, .initFunc = functionSetup, @@ -2006,7 +2064,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "mavg", .type = FUNCTION_TYPE_MAVG, - .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC, + .classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC | FUNC_MGT_FORBID_WINDOW_FUNC, .translateFunc = translateMavg, .getEnvFunc = getMavgFuncEnv, .initFunc = mavgFunctionSetup, diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 1164b96262..4ec6432fc8 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -59,6 +59,12 @@ typedef struct STuplePos { int32_t offset; } STuplePos; +typedef struct SMinmaxResInfo { + bool assign; // assign the first value or not + int64_t v; + STuplePos tuplePos; +} SMinmaxResInfo; + typedef struct STopBotResItem { SVariant v; uint64_t uid; // it is a table uid, used to extract tag data during building of the final result for the tag data @@ -148,6 +154,12 @@ typedef struct SElapsedInfo { int64_t timeUnit; } SElapsedInfo; +typedef struct STwaInfo { + double dOutput; + SPoint1 p; + STimeWindow win; +} STwaInfo; + typedef struct SHistoFuncBin { double lower; double upper; @@ -234,6 +246,22 @@ typedef struct SUniqueInfo { char pItems[]; } SUniqueInfo; +typedef struct SDerivInfo { + double prevValue; // previous value + TSKEY prevTs; // previous timestamp + bool ignoreNegative; // ignore the negative value + int64_t tsWindow; // time window for derivative + bool valueSet; // the value has been set already +} SDerivInfo; + +typedef struct SRateInfo { + double firstValue; + TSKEY firstKey; + double lastValue; + TSKEY lastKey; + int8_t hasResult; // flag to denote has value +} SRateInfo; + #define SET_VAL(_info, numOfElem, res) \ do { \ if ((numOfElem) <= 0) { \ @@ -533,7 +561,7 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { // check for overflow if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { - GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElem = 0; } _sum_over: @@ -899,7 +927,7 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { // check for overflow if (isinf(pAvgRes->result) || isnan(pAvgRes->result)) { - GET_RES_INFO(pCtx)->isNullRes = 1; + GET_RES_INFO(pCtx)->numOfRes = 0; } return functionFinalize(pCtx, pBlock); @@ -927,12 +955,6 @@ EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin return FUNC_DATA_REQUIRED_STATIS_LOAD; } -typedef struct SMinmaxResInfo { - bool assign; // assign the first value or not - int64_t v; - STuplePos tuplePos; -} SMinmaxResInfo; - bool minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { if (!functionSetup(pCtx, pResultInfo)) { return false; // not initialized since it has been initialized @@ -1427,11 +1449,13 @@ void setNullSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuplePos* pTuplePos, int32_t rowIndex) { int32_t pageId = pTuplePos->pageId; int32_t offset = pTuplePos->offset; + if (pTuplePos->pageId != -1) { + int32_t numOfCols = taosArrayGetSize(pCtx->pSrcBlock->pDataBlock); SFilePage* pPage = getBufPage(pCtx->pBuf, pageId); bool* nullList = (bool*)((char*)pPage + offset); - char* pStart = (char*)(nullList + pCtx->pSrcBlock->info.numOfCols * sizeof(bool)); + char* pStart = (char*)(nullList + numOfCols * sizeof(bool)); // todo set the offset value to optimize the performance. for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) { @@ -1752,6 +1776,11 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { pStddevRes->result = sqrt(fabs(pStddevRes->quadraticDSum / ((double)pStddevRes->count) - avg * avg)); } + // check for overflow + if (isinf(pStddevRes->result) || isnan(pStddevRes->result)) { + GET_RES_INFO(pCtx)->numOfRes = 0; + } + return functionFinalize(pCtx, pBlock); } @@ -3016,7 +3045,7 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos) { SFilePage* pPage = NULL; - int32_t completeRowSize = pSrcBlock->info.rowSize + pSrcBlock->info.numOfCols * sizeof(bool); + int32_t completeRowSize = pSrcBlock->info.rowSize + (int32_t) taosArrayGetSize(pSrcBlock->pDataBlock) * sizeof(bool); if (pCtx->curBufPage == -1) { pPage = getNewBufPage(pCtx->pBuf, 0, &pCtx->curBufPage); @@ -3034,8 +3063,8 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS // keep the current row data, extract method int32_t offset = 0; bool* nullList = (bool*)((char*)pPage + pPage->num); - char* pStart = (char*)(nullList + sizeof(bool) * pSrcBlock->info.numOfCols); - for (int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) { + char* pStart = (char*)(nullList + sizeof(bool) * (int32_t) taosArrayGetSize(pSrcBlock->pDataBlock)); + for (int32_t i = 0; i < (int32_t) taosArrayGetSize(pSrcBlock->pDataBlock); ++i) { SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i); bool isNull = colDataIsNull_s(pCol, rowIndex); if (isNull) { @@ -3064,11 +3093,13 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos) { SFilePage* pPage = getBufPage(pCtx->pBuf, pPos->pageId); + int32_t numOfCols = taosArrayGetSize(pSrcBlock->pDataBlock); + bool* nullList = (bool*)((char*)pPage + pPos->offset); - char* pStart = (char*)(nullList + pSrcBlock->info.numOfCols * sizeof(bool)); + char* pStart = (char*)(nullList + numOfCols * sizeof(bool)); int32_t offset = 0; - for (int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i); if ((nullList[i] = colDataIsNull_s(pCol, rowIndex)) == true) { offset += pCol->info.bytes; @@ -4665,12 +4696,6 @@ int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return pResInfo->numOfRes; } -typedef struct STwaInfo { - double dOutput; - SPoint1 p; - STimeWindow win; -} STwaInfo; - bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(STwaInfo); return true; @@ -5119,14 +5144,6 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return TSDB_CODE_SUCCESS; } -typedef struct SDerivInfo { - double prevValue; // previous value - TSKEY prevTs; // previous timestamp - bool ignoreNegative; // ignore the negative value - int64_t tsWindow; // time window for derivative - bool valueSet; // the value has been set already -} SDerivInfo; - bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(SDerivInfo); return true; @@ -5221,6 +5238,117 @@ int32_t derivativeFunction(SqlFunctionCtx* pCtx) { return numOfElems; } +bool getIrateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) { + pEnv->calcMemSize = sizeof(SRateInfo); + return true; +} + +bool irateFuncSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { + if (!functionSetup(pCtx, pResInfo)) { + return false; // not initialized since it has been initialized + } + + SRateInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); + + pInfo->firstKey = INT64_MIN; + pInfo->lastKey = INT64_MIN; + pInfo->firstValue = (double)INT64_MIN; + pInfo->lastValue = (double)INT64_MIN; + + pInfo->hasResult = 0; + return true; +} + +int32_t irateFunction(SqlFunctionCtx* pCtx) { + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + SRateInfo* pRateInfo = GET_ROWCELL_INTERBUF(pResInfo); + + SInputColumnInfoData* pInput = &pCtx->input; + SColumnInfoData* pInputCol = pInput->pData[0]; + + SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput; + + TSKEY* tsList = (int64_t*)pInput->pPTS->pData; + + int32_t numOfElems = 0; + int32_t type = pInputCol->info.type; + + for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; i += 1) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + continue; + } + + numOfElems++; + + char* data = colDataGetData(pInputCol, i); + double v = 0; + GET_TYPED_DATA(v, double, type, data); + + if (INT64_MIN == pRateInfo->lastKey) { + pRateInfo->lastValue = v; + pRateInfo->lastKey = tsList[i]; + continue; + } + + if (tsList[i] > pRateInfo->lastKey) { + if ((INT64_MIN == pRateInfo->firstKey) || pRateInfo->lastKey > pRateInfo->firstKey) { + pRateInfo->firstValue = pRateInfo->lastValue; + pRateInfo->firstKey = pRateInfo->lastKey; + } + + pRateInfo->lastValue = v; + pRateInfo->lastKey = tsList[i]; + + continue; + } + + if ((INT64_MIN == pRateInfo->firstKey) || tsList[i] > pRateInfo->firstKey) { + pRateInfo->firstValue = v; + pRateInfo->firstKey = tsList[i]; + } + + } + + SET_VAL(pResInfo, numOfElems, 1); + return TSDB_CODE_SUCCESS; +} + +static double doCalcRate(const SRateInfo* pRateInfo, double tickPerSec) { + if ((INT64_MIN == pRateInfo->lastKey) || (INT64_MIN == pRateInfo->firstKey) || + (pRateInfo->firstKey >= pRateInfo->lastKey)) { + return 0.0; + } + + double diff = 0; + // If the previous value of the last is greater than the last value, only keep the last point instead of the delta + // value between two values. + diff = pRateInfo->lastValue; + if (diff >= pRateInfo->firstValue) { + diff -= pRateInfo->firstValue; + } + + int64_t duration = pRateInfo->lastKey - pRateInfo->firstKey; + if (duration == 0) { + return 0; + } + + return (duration > 0)? ((double)diff) / (duration/tickPerSec):0.0; +} + +int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { + int32_t slotId = pCtx->pExpr->base.resSchema.slotId; + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); + + SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); + pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; + + SRateInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo); + double result = doCalcRate(pInfo, 1000); + colDataAppend(pCol, pBlock->info.rows, (const char*)&result, pResInfo->isNullRes); + + return pResInfo->numOfRes; +} + int32_t interpFunction(SqlFunctionCtx* pCtx) { #if 0 int32_t fillType = (int32_t) pCtx->param[2].i64; diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 710b01ce59..5fcf5e239c 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -186,6 +186,13 @@ bool fmIsInterpFunc(int32_t funcId) { return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type; } +bool fmIsLastRowFunc(int32_t funcId) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNCTION_TYPE_LAST_ROW == funcMgtBuiltins[funcId].type; +} + void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index f6370be6f4..da9474ede0 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -763,8 +763,8 @@ void freeUdfInterBuf(SUdfInterBuf *buf) { int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock) { udfBlock->numOfRows = block->info.rows; - udfBlock->numOfCols = block->info.numOfCols; - udfBlock->udfCols = taosMemoryCalloc(udfBlock->numOfCols, sizeof(SUdfColumn*)); + udfBlock->numOfCols = taosArrayGetSize(block->pDataBlock); + udfBlock->udfCols = taosMemoryCalloc(taosArrayGetSize(block->pDataBlock), sizeof(SUdfColumn*)); for (int32_t i = 0; i < udfBlock->numOfCols; ++i) { udfBlock->udfCols[i] = taosMemoryCalloc(1, sizeof(SUdfColumn)); SColumnInfoData *col= (SColumnInfoData*)taosArrayGet(block->pDataBlock, i); @@ -799,7 +799,6 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo } int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { - block->info.numOfCols = 1; block->info.rows = udfCol->colData.numOfRows; block->info.hasVarCol = IS_VAR_DATA_TYPE(udfCol->colMeta.type); @@ -830,25 +829,19 @@ int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SSDataBlock *output) { output->info.rows = input->numOfRows; - output->info.numOfCols = numOfCols; - bool hasVarCol = false; - for (int32_t i = 0; i < numOfCols; ++i) { - if (IS_VAR_DATA_TYPE((input+i)->columnData->info.type)) { - hasVarCol = true; - break; - } - } - output->info.hasVarCol = hasVarCol; - output->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); for (int32_t i = 0; i < numOfCols; ++i) { taosArrayPush(output->pDataBlock, (input + i)->columnData); + + if (IS_VAR_DATA_TYPE((input+i)->columnData->info.type)) { + output->info.hasVarCol = true; + } } return 0; } int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) { - if (input->info.numOfCols != 1) { + if (taosArrayGetSize(input->pDataBlock) != 1) { fnError("scalar function only support one column"); return -1; } @@ -1089,24 +1082,14 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - - SSDataBlock tempBlock = {0}; - tempBlock.info.numOfCols = numOfCols; - tempBlock.info.rows = pInput->totalRows; - tempBlock.info.uid = pInput->uid; - bool hasVarCol = false; - tempBlock.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - + SSDataBlock* pTempBlock = createDataBlock(); + pTempBlock->info.rows = pInput->totalRows; + pTempBlock->info.uid = pInput->uid; for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData *col = pInput->pData[i]; - if (IS_VAR_DATA_TYPE(col->info.type)) { - hasVarCol = true; - } - taosArrayPush(tempBlock.pDataBlock, col); + blockDataAppendColInfo(pTempBlock, pInput->pData[i]); } - tempBlock.info.hasVarCol = hasVarCol; - SSDataBlock *inputBlock = blockDataExtractBlock(&tempBlock, start, numOfRows); + SSDataBlock *inputBlock = blockDataExtractBlock(pTempBlock, start, numOfRows); SUdfInterBuf state = {.buf = udfRes->interResBuf, .bufLen = session->bufSize, @@ -1131,7 +1114,9 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { } blockDataDestroy(inputBlock); - taosArrayDestroy(tempBlock.pDataBlock); + + taosArrayDestroy(pTempBlock->pDataBlock); + taosMemoryFree(pTempBlock); releaseUdfFuncHandle(pCtx->udfName); freeUdfInterBuf(&newState); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 7fffa84e0b..838071dbf1 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -613,7 +613,9 @@ int32_t udfdOpenClientRpc() { } int32_t udfdCloseClientRpc() { + fnInfo("udfd begin closing rpc"); rpcClose(global.clientRpc); + fnInfo("udfd finish closing rpc"); return 0; } @@ -937,9 +939,8 @@ int main(int argc, char *argv[]) { uv_thread_create(&mnodeConnectThread, udfdConnectMnodeThreadFunc, NULL); udfdRun(); - + removeListeningPipe(); - uv_thread_join(&mnodeConnectThread); udfdCloseClientRpc(); return 0; diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 15109db220..7395f1e14c 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -45,27 +45,27 @@ int scalarFuncTest() { for (int k = 0; k < 1; ++k) { SSDataBlock block = {0}; SSDataBlock *pBlock = █ - pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - pBlock->info.numOfCols = 1; + for (int32_t i = 0; i < 1; ++i) { + SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1); + blockDataAppendColInfo(pBlock, &colInfo); + } + + blockDataEnsureCapacity(pBlock, 1024); pBlock->info.rows = 1024; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_INT; - colInfo.info.bytes = sizeof(int32_t); - colInfo.info.colId = 1; - colInfoDataEnsureCapacity(&colInfo, 0, pBlock->info.rows); - for (int32_t j = 0; j < pBlock->info.rows; ++j) { - colDataAppendInt32(&colInfo, j, &j); - } - taosArrayPush(pBlock->pDataBlock, &colInfo); + + SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, 0); + for (int32_t j = 0; j < pBlock->info.rows; ++j) { + colDataAppendInt32(pCol, j, &j); } SScalarParam input = {0}; input.numOfRows = pBlock->info.rows; input.columnData = taosArrayGet(pBlock->pDataBlock, 0); + SScalarParam output = {0}; doCallUdfScalarFunc(handle, &input, 1, &output); taosArrayDestroy(pBlock->pDataBlock); + SColumnInfoData *col = output.columnData; for (int32_t i = 0; i < output.numOfRows; ++i) { if (i % 100 == 0) @@ -89,21 +89,18 @@ int aggregateFuncTest() { return -1; } - SSDataBlock block = {0}; - SSDataBlock *pBlock = █ - pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); - pBlock->info.numOfCols = 1; + SSDataBlock *pBlock = createDataBlock(); + for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); ++i) { + SColumnInfoData colInfo = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1); + blockDataAppendColInfo(pBlock, &colInfo); + } + + blockDataEnsureCapacity(pBlock, 1024); pBlock->info.rows = 1024; - for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_INT; - colInfo.info.bytes = sizeof(int32_t); - colInfo.info.colId = 1; - colInfoDataEnsureCapacity(&colInfo, 0, pBlock->info.rows); - for (int32_t j = 0; j < pBlock->info.rows; ++j) { - colDataAppendInt32(&colInfo, j, &j); - } - taosArrayPush(pBlock->pDataBlock, &colInfo); + + SColumnInfoData* pColInfo = bdGetColumnInfoData(pBlock, 0); + for (int32_t j = 0; j < pBlock->info.rows; ++j) { + colDataAppendInt32(pColInfo, j, &j); } SUdfInterBuf buf = {0}; @@ -121,6 +118,7 @@ int aggregateFuncTest() { freeUdfInterBuf(&resultBuf); doTeardownUdf(handle); + blockDataDestroy(pBlock); return 0; } diff --git a/source/libs/index/test/index_executor_tests.cpp b/source/libs/index/test/index_executor_tests.cpp index b88ffe5b8b..a0ac79a297 100644 --- a/source/libs/index/test/index_executor_tests.cpp +++ b/source/libs/index/test/index_executor_tests.cpp @@ -86,7 +86,7 @@ void sifAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *sl SColumnInfoData idata = {0}; idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, 0, rows); + colInfoDataEnsureCapacity(&idata, rows); taosArrayPush(res->pDataBlock, &idata); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index bf857ad718..d387a432e1 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -201,6 +201,9 @@ static void monGenClusterJson(SMonInfo *pMonitor) { tjsonAddStringToObject(pJson, "version", pInfo->version); tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime); tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval); + tjsonAddDoubleToObject(pJson, "dbs_total", pInfo->dbs_total); + tjsonAddDoubleToObject(pJson, "tbs_total", pInfo->tbs_total); + tjsonAddDoubleToObject(pJson, "stbs_total", pInfo->stbs_total); tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total); tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive); tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total); @@ -277,6 +280,27 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { } } +static void monGenStbJson(SMonInfo *pMonitor) { + SMonStbInfo *pInfo = &pMonitor->mmInfo.stb; + if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; + + SJson *pJson = tjsonAddArrayToObject(pMonitor->pJson, "stb_infos"); + if (pJson == NULL) return; + + for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) { + SJson *pStbJson = tjsonCreateObject(); + if (pStbJson == NULL) continue; + if (tjsonAddItemToArray(pJson, pStbJson) != 0) { + tjsonDelete(pStbJson); + continue; + } + + SMonStbDesc *pStbDesc = taosArrayGet(pInfo->stbs, i); + tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name); + tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name); + } +} + static void monGenGrantJson(SMonInfo *pMonitor) { SMonGrantInfo *pInfo = &pMonitor->mmInfo.grant; if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; @@ -524,6 +548,7 @@ void monSendReport() { monGenBasicJson(pMonitor); monGenClusterJson(pMonitor); monGenVgroupJson(pMonitor); + monGenStbJson(pMonitor); monGenGrantJson(pMonitor); monGenDnodeJson(pMonitor); monGenDiskJson(pMonitor); diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index a041b582a9..8fa7e88605 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -102,6 +102,9 @@ int32_t tEncodeSMonClusterInfo(SEncoder *encoder, const SMonClusterInfo *pInfo) if (tEncodeCStr(encoder, pInfo->version) < 0) return -1; if (tEncodeFloat(encoder, pInfo->master_uptime) < 0) return -1; if (tEncodeI32(encoder, pInfo->monitor_interval) < 0) return -1; + if (tEncodeI32(encoder, pInfo->dbs_total) < 0) return -1; + if (tEncodeI32(encoder, pInfo->stbs_total) < 0) return -1; + if (tEncodeI64(encoder, pInfo->tbs_total) < 0) return -1; if (tEncodeI32(encoder, pInfo->vgroups_total) < 0) return -1; if (tEncodeI32(encoder, pInfo->vgroups_alive) < 0) return -1; if (tEncodeI32(encoder, pInfo->vnodes_total) < 0) return -1; @@ -130,6 +133,9 @@ int32_t tDecodeSMonClusterInfo(SDecoder *decoder, SMonClusterInfo *pInfo) { if (tDecodeCStrTo(decoder, pInfo->version) < 0) return -1; if (tDecodeFloat(decoder, &pInfo->master_uptime) < 0) return -1; if (tDecodeI32(decoder, &pInfo->monitor_interval) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->dbs_total) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->stbs_total) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->tbs_total) < 0) return -1; if (tDecodeI32(decoder, &pInfo->vgroups_total) < 0) return -1; if (tDecodeI32(decoder, &pInfo->vgroups_alive) < 0) return -1; if (tDecodeI32(decoder, &pInfo->vnodes_total) < 0) return -1; @@ -203,6 +209,32 @@ int32_t tDecodeSMonVgroupInfo(SDecoder *decoder, SMonVgroupInfo *pInfo) { return 0; } +int32_t tEncodeSMonStbInfo(SEncoder *encoder, const SMonStbInfo *pInfo) { + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->stbs)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->stbs); ++i) { + SMonStbDesc *pDesc = taosArrayGet(pInfo->stbs, i); + if (tEncodeCStr(encoder, pDesc->stb_name) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; + } + return 0; +} + +int32_t tDecodeSMonStbInfo(SDecoder *decoder, SMonStbInfo *pInfo) { + int32_t arraySize = 0; + if (tDecodeI32(decoder, &arraySize) < 0) return -1; + + pInfo->stbs = taosArrayInit(arraySize, sizeof(SMonStbDesc)); + if (pInfo->stbs == NULL) return -1; + + for (int32_t i = 0; i < arraySize; ++i) { + SMonStbDesc desc = {0}; + if (tDecodeCStrTo(decoder, desc.stb_name) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; + taosArrayPush(pInfo->stbs, &desc); + } + return 0; +} + int32_t tEncodeSMonGrantInfo(SEncoder *encoder, const SMonGrantInfo *pInfo) { if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1; if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1; @@ -224,6 +256,7 @@ int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1; if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1; + if (tEncodeSMonStbInfo(&encoder, &pInfo->stb) < 0) return -1; if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; @@ -241,6 +274,7 @@ int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1; if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1; + if (tDecodeSMonStbInfo(&decoder, &pInfo->stb) < 0) return -1; if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; @@ -255,9 +289,11 @@ void tFreeSMonMmInfo(SMonMmInfo *pInfo) { taosArrayDestroy(pInfo->cluster.mnodes); taosArrayDestroy(pInfo->cluster.dnodes); taosArrayDestroy(pInfo->vgroup.vgroups); + taosArrayDestroy(pInfo->stb.stbs); pInfo->cluster.mnodes = NULL; pInfo->cluster.dnodes = NULL; pInfo->vgroup.vgroups = NULL; + pInfo->stb.stbs = NULL; pInfo->log.logs = NULL; } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 0bde0d0581..ac197912cf 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -41,8 +41,7 @@ } \ (pDst)->fldname = strdup((pSrc)->fldname); \ if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ + return TSDB_CODE_OUT_OF_MEMORY; \ } \ } while (0) @@ -53,8 +52,7 @@ } \ (pDst)->fldname = nodesCloneNode((pSrc)->fldname); \ if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ + return TSDB_CODE_OUT_OF_MEMORY; \ } \ } while (0) @@ -65,8 +63,7 @@ } \ (pDst)->fldname = (nodePtrType)nodesCloneNode((SNode*)(pSrc)->fldname); \ if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ + return TSDB_CODE_OUT_OF_MEMORY; \ } \ } while (0) @@ -77,8 +74,7 @@ } \ (pDst)->fldname = nodesCloneList((pSrc)->fldname); \ if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ + return TSDB_CODE_OUT_OF_MEMORY; \ } \ } while (0) @@ -89,27 +85,25 @@ } \ (pDst)->fldname = cloneFunc((pSrc)->fldname); \ if (NULL == (pDst)->fldname) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ + return TSDB_CODE_OUT_OF_MEMORY; \ } \ } while (0) -#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ - do { \ - if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \ - nodesDestroyNode((SNode*)pDst); \ - return NULL; \ - } \ +#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \ + do { \ + if (TSDB_CODE_SUCCESS != copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \ + return TSDB_CODE_OUT_OF_MEMORY; \ + } \ } while (0) -static SNode* exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { +static int32_t exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { COPY_OBJECT_FIELD(resType, sizeof(SDataType)); COPY_CHAR_ARRAY_FIELD(aliasName); COPY_CHAR_ARRAY_FIELD(userAlias); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { +static int32_t columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_SCALAR_FIELD(tableId); COPY_SCALAR_FIELD(tableType); @@ -122,10 +116,10 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { COPY_CHAR_ARRAY_FIELD(colName); COPY_SCALAR_FIELD(dataBlockId); COPY_SCALAR_FIELD(slotId); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { +static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_CHAR_POINT_FIELD(literal); COPY_SCALAR_FIELD(isDuration); @@ -135,7 +129,7 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { COPY_SCALAR_FIELD(typeData); COPY_SCALAR_FIELD(unit); if (!pSrc->translate) { - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } switch (pSrc->node.resType.type) { case TSDB_DATA_TYPE_BOOL: @@ -164,8 +158,7 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { int32_t len = varDataTLen(pSrc->datum.p) + 1; pDst->datum.p = taosMemoryCalloc(1, len); if (NULL == pDst->datum.p) { - nodesDestroyNode((SNode*)pDst); - return NULL; + return TSDB_CODE_OUT_OF_MEMORY; } memcpy(pDst->datum.p, pSrc->datum.p, len); break; @@ -177,42 +170,42 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { default: break; } - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) { +static int32_t operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_SCALAR_FIELD(opType); CLONE_NODE_FIELD(pLeft); CLONE_NODE_FIELD(pRight); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) { +static int32_t logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_SCALAR_FIELD(condType); CLONE_NODE_LIST_FIELD(pParameterList); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) { +static int32_t functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_CHAR_ARRAY_FIELD(functionName); COPY_SCALAR_FIELD(funcId); COPY_SCALAR_FIELD(funcType); CLONE_NODE_LIST_FIELD(pParameterList); COPY_SCALAR_FIELD(udfBufSize); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* tableNodeCopy(const STableNode* pSrc, STableNode* pDst) { +static int32_t tableNodeCopy(const STableNode* pSrc, STableNode* pDst) { COPY_BASE_OBJECT_FIELD(node, exprNodeCopy); COPY_CHAR_ARRAY_FIELD(dbName); COPY_CHAR_ARRAY_FIELD(tableName); COPY_CHAR_ARRAY_FIELD(tableAlias); COPY_SCALAR_FIELD(precision); COPY_SCALAR_FIELD(singleTable); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } static STableMeta* tableMetaClone(const STableMeta* pSrc) { @@ -235,101 +228,103 @@ static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { return pDst; } -static SNode* realTableNodeCopy(const SRealTableNode* pSrc, SRealTableNode* pDst) { +static int32_t realTableNodeCopy(const SRealTableNode* pSrc, SRealTableNode* pDst) { COPY_BASE_OBJECT_FIELD(table, tableNodeCopy); CLONE_OBJECT_FIELD(pMeta, tableMetaClone); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); COPY_CHAR_ARRAY_FIELD(qualDbName); COPY_SCALAR_FIELD(ratio); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* tempTableNodeCopy(const STempTableNode* pSrc, STempTableNode* pDst) { +static int32_t tempTableNodeCopy(const STempTableNode* pSrc, STempTableNode* pDst) { COPY_BASE_OBJECT_FIELD(table, tableNodeCopy); CLONE_NODE_FIELD(pSubquery); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* joinTableNodeCopy(const SJoinTableNode* pSrc, SJoinTableNode* pDst) { +static int32_t joinTableNodeCopy(const SJoinTableNode* pSrc, SJoinTableNode* pDst) { COPY_BASE_OBJECT_FIELD(table, tableNodeCopy); COPY_SCALAR_FIELD(joinType); CLONE_NODE_FIELD(pLeft); CLONE_NODE_FIELD(pRight); CLONE_NODE_FIELD(pOnCond); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) { +static int32_t targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) { COPY_SCALAR_FIELD(dataBlockId); COPY_SCALAR_FIELD(slotId); CLONE_NODE_FIELD(pExpr); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) { +static int32_t groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) { COPY_SCALAR_FIELD(groupingSetType); CLONE_NODE_LIST_FIELD(pParameterList); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode* pDst) { +static int32_t orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode* pDst) { CLONE_NODE_FIELD(pExpr); COPY_SCALAR_FIELD(order); COPY_SCALAR_FIELD(nullOrder); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* limitNodeCopy(const SLimitNode* pSrc, SLimitNode* pDst) { +static int32_t limitNodeCopy(const SLimitNode* pSrc, SLimitNode* pDst) { COPY_SCALAR_FIELD(limit); COPY_SCALAR_FIELD(offset); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* stateWindowNodeCopy(const SStateWindowNode* pSrc, SStateWindowNode* pDst) { +static int32_t stateWindowNodeCopy(const SStateWindowNode* pSrc, SStateWindowNode* pDst) { CLONE_NODE_FIELD(pCol); CLONE_NODE_FIELD(pExpr); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* sessionWindowNodeCopy(const SSessionWindowNode* pSrc, SSessionWindowNode* pDst) { +static int32_t sessionWindowNodeCopy(const SSessionWindowNode* pSrc, SSessionWindowNode* pDst) { CLONE_NODE_FIELD_EX(pCol, SColumnNode*); CLONE_NODE_FIELD_EX(pGap, SValueNode*); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* intervalWindowNodeCopy(const SIntervalWindowNode* pSrc, SIntervalWindowNode* pDst) { +static int32_t intervalWindowNodeCopy(const SIntervalWindowNode* pSrc, SIntervalWindowNode* pDst) { CLONE_NODE_FIELD(pCol); CLONE_NODE_FIELD(pInterval); CLONE_NODE_FIELD(pOffset); CLONE_NODE_FIELD(pSliding); CLONE_NODE_FIELD(pFill); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* nodeListNodeCopy(const SNodeListNode* pSrc, SNodeListNode* pDst) { +static int32_t nodeListNodeCopy(const SNodeListNode* pSrc, SNodeListNode* pDst) { COPY_OBJECT_FIELD(dataType, sizeof(SDataType)); CLONE_NODE_LIST_FIELD(pNodeList); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) { +static int32_t fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) { COPY_SCALAR_FIELD(mode); CLONE_NODE_FIELD(pValues); CLONE_NODE_FIELD(pWStartTs); COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow)); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { +static int32_t logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) { CLONE_NODE_LIST_FIELD(pTargets); CLONE_NODE_FIELD(pConditions); CLONE_NODE_LIST_FIELD(pChildren); COPY_SCALAR_FIELD(optimizedFlag); COPY_SCALAR_FIELD(precision); - return (SNode*)pDst; + CLONE_NODE_FIELD(pLimit); + CLONE_NODE_FIELD(pSlimit); + return TSDB_CODE_SUCCESS; } -static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { +static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pScanCols); CLONE_NODE_LIST_FIELD(pScanPseudoCols); @@ -351,41 +346,38 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { COPY_SCALAR_FIELD(intervalUnit); COPY_SCALAR_FIELD(slidingUnit); CLONE_NODE_FIELD(pTagCond); + CLONE_NODE_FIELD(pTagIndexCond); COPY_SCALAR_FIELD(triggerType); COPY_SCALAR_FIELD(watermark); COPY_SCALAR_FIELD(tsColId); COPY_SCALAR_FIELD(filesFactor); CLONE_NODE_LIST_FIELD(pPartTags); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) { +static int32_t logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(joinType); CLONE_NODE_FIELD(pOnConditions); COPY_SCALAR_FIELD(isSingleTableJoin); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) { +static int32_t logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pGroupKeys); CLONE_NODE_LIST_FIELD(pAggFuncs); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) { +static int32_t logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pProjections); COPY_CHAR_ARRAY_FIELD(stmtName); - COPY_SCALAR_FIELD(limit); - COPY_SCALAR_FIELD(offset); - COPY_SCALAR_FIELD(slimit); - COPY_SCALAR_FIELD(soffset); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModifyLogicNode* pDst) { +static int32_t logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModifyLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(modifyType); COPY_SCALAR_FIELD(msgType); @@ -394,25 +386,25 @@ static SNode* logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModif COPY_SCALAR_FIELD(tableType); COPY_CHAR_ARRAY_FIELD(tableFName); COPY_OBJECT_FIELD(deleteTimeRange, sizeof(STimeWindow)); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) { +static int32_t logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(srcGroupId); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) { +static int32_t logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pMergeKeys); CLONE_NODE_LIST_FIELD(pInputs); COPY_SCALAR_FIELD(numOfChannels); COPY_SCALAR_FIELD(srcGroupId); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) { +static int32_t logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(winType); CLONE_NODE_LIST_FIELD(pFuncs); @@ -429,37 +421,37 @@ static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pD COPY_SCALAR_FIELD(watermark); COPY_SCALAR_FIELD(filesFactor); COPY_SCALAR_FIELD(windowAlgo); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicFillCopy(const SFillLogicNode* pSrc, SFillLogicNode* pDst) { +static int32_t logicFillCopy(const SFillLogicNode* pSrc, SFillLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); COPY_SCALAR_FIELD(mode); CLONE_NODE_FIELD(pWStartTs); CLONE_NODE_FIELD(pValues); COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow)); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicSortCopy(const SSortLogicNode* pSrc, SSortLogicNode* pDst) { +static int32_t logicSortCopy(const SSortLogicNode* pSrc, SSortLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pSortKeys); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogicNode* pDst) { +static int32_t logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pPartitionKeys); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) { +static int32_t logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pFuncs); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncLogicNode* pDst) { +static int32_t logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncLogicNode* pDst) { COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pFuncs); COPY_OBJECT_FIELD(timeRange, sizeof(STimeWindow)); @@ -467,26 +459,26 @@ static SNode* logicInterpFuncCopy(const SInterpFuncLogicNode* pSrc, SInterpFuncL COPY_SCALAR_FIELD(fillMode); CLONE_NODE_FIELD(pFillValues); CLONE_NODE_FIELD(pTimeSeries); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) { +static int32_t logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) { COPY_OBJECT_FIELD(id, sizeof(SSubplanId)); CLONE_NODE_FIELD_EX(pNode, SLogicNode*); COPY_SCALAR_FIELD(subplanType); COPY_SCALAR_FIELD(level); COPY_SCALAR_FIELD(splitFlag); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiNodeCopy(const SPhysiNode* pSrc, SPhysiNode* pDst) { +static int32_t physiNodeCopy(const SPhysiNode* pSrc, SPhysiNode* pDst) { CLONE_NODE_FIELD_EX(pOutputDataBlockDesc, SDataBlockDescNode*); CLONE_NODE_FIELD(pConditions); CLONE_NODE_LIST_FIELD(pChildren); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) { +static int32_t physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(node, physiNodeCopy); CLONE_NODE_LIST_FIELD(pScanCols); CLONE_NODE_LIST_FIELD(pScanPseudoCols); @@ -494,14 +486,14 @@ static SNode* physiScanCopy(const SScanPhysiNode* pSrc, SScanPhysiNode* pDst) { COPY_SCALAR_FIELD(suid); COPY_SCALAR_FIELD(tableType); COPY_OBJECT_FIELD(tableName, sizeof(SName)); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiTagScanCopy(const STagScanPhysiNode* pSrc, STagScanPhysiNode* pDst) { +static int32_t physiTagScanCopy(const STagScanPhysiNode* pSrc, STagScanPhysiNode* pDst) { return physiScanCopy(pSrc, pDst); } -static SNode* physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhysiNode* pDst) { +static int32_t physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(scan, physiScanCopy); COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2); COPY_OBJECT_FIELD(scanRange, sizeof(STimeWindow)); @@ -518,18 +510,18 @@ static SNode* physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhys COPY_SCALAR_FIELD(watermark); COPY_SCALAR_FIELD(tsColId); COPY_SCALAR_FIELD(filesFactor); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiSysTableScanCopy(const SSystemTableScanPhysiNode* pSrc, SSystemTableScanPhysiNode* pDst) { +static int32_t physiSysTableScanCopy(const SSystemTableScanPhysiNode* pSrc, SSystemTableScanPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(scan, physiScanCopy); COPY_OBJECT_FIELD(mgmtEpSet, sizeof(SEpSet)); COPY_SCALAR_FIELD(showRewrite); COPY_SCALAR_FIELD(accountId); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pDst) { +static int32_t physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(node, physiNodeCopy); CLONE_NODE_LIST_FIELD(pExprs); CLONE_NODE_LIST_FIELD(pFuncs); @@ -538,59 +530,59 @@ static SNode* physiWindowCopy(const SWinodwPhysiNode* pSrc, SWinodwPhysiNode* pD COPY_SCALAR_FIELD(triggerType); COPY_SCALAR_FIELD(watermark); COPY_SCALAR_FIELD(filesFactor); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiIntervalCopy(const SIntervalPhysiNode* pSrc, SIntervalPhysiNode* pDst) { +static int32_t physiIntervalCopy(const SIntervalPhysiNode* pSrc, SIntervalPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(window, physiWindowCopy); COPY_SCALAR_FIELD(interval); COPY_SCALAR_FIELD(offset); COPY_SCALAR_FIELD(sliding); COPY_SCALAR_FIELD(intervalUnit); COPY_SCALAR_FIELD(slidingUnit); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiSessionCopy(const SSessionWinodwPhysiNode* pSrc, SSessionWinodwPhysiNode* pDst) { +static int32_t physiSessionCopy(const SSessionWinodwPhysiNode* pSrc, SSessionWinodwPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(window, physiWindowCopy); COPY_SCALAR_FIELD(gap); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* physiPartitionCopy(const SPartitionPhysiNode* pSrc, SPartitionPhysiNode* pDst) { +static int32_t physiPartitionCopy(const SPartitionPhysiNode* pSrc, SPartitionPhysiNode* pDst) { COPY_BASE_OBJECT_FIELD(node, physiNodeCopy); CLONE_NODE_LIST_FIELD(pExprs); CLONE_NODE_LIST_FIELD(pPartitionKeys); CLONE_NODE_LIST_FIELD(pTargets); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) { +static int32_t dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) { COPY_SCALAR_FIELD(dataBlockId); CLONE_NODE_LIST_FIELD(pSlots); COPY_SCALAR_FIELD(totalRowSize); COPY_SCALAR_FIELD(outputRowSize); COPY_SCALAR_FIELD(precision); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) { +static int32_t slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) { COPY_SCALAR_FIELD(slotId); COPY_OBJECT_FIELD(dataType, sizeof(SDataType)); COPY_SCALAR_FIELD(reserve); COPY_SCALAR_FIELD(output); COPY_SCALAR_FIELD(tag); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) { +static int32_t downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) { COPY_OBJECT_FIELD(addr, sizeof(SQueryNodeAddr)); COPY_SCALAR_FIELD(taskId); COPY_SCALAR_FIELD(schedId); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } -static SNode* selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) { +static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) { COPY_SCALAR_FIELD(isDistinct); CLONE_NODE_LIST_FIELD(pProjectionList); CLONE_NODE_FIELD(pFromTable); @@ -608,116 +600,166 @@ static SNode* selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) { COPY_SCALAR_FIELD(isTimeOrderQuery); COPY_SCALAR_FIELD(hasAggFuncs); COPY_SCALAR_FIELD(hasRepeatScanFuncs); - return (SNode*)pDst; + return TSDB_CODE_SUCCESS; } SNode* nodesCloneNode(const SNode* pNode) { if (NULL == pNode) { return NULL; } + SNode* pDst = nodesMakeNode(nodeType(pNode)); if (NULL == pDst) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + + int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { case QUERY_NODE_COLUMN: - return columnNodeCopy((const SColumnNode*)pNode, (SColumnNode*)pDst); + code = columnNodeCopy((const SColumnNode*)pNode, (SColumnNode*)pDst); + break; case QUERY_NODE_VALUE: - return valueNodeCopy((const SValueNode*)pNode, (SValueNode*)pDst); + code = valueNodeCopy((const SValueNode*)pNode, (SValueNode*)pDst); + break; case QUERY_NODE_OPERATOR: - return operatorNodeCopy((const SOperatorNode*)pNode, (SOperatorNode*)pDst); + code = operatorNodeCopy((const SOperatorNode*)pNode, (SOperatorNode*)pDst); + break; case QUERY_NODE_LOGIC_CONDITION: - return logicConditionNodeCopy((const SLogicConditionNode*)pNode, (SLogicConditionNode*)pDst); + code = logicConditionNodeCopy((const SLogicConditionNode*)pNode, (SLogicConditionNode*)pDst); + break; case QUERY_NODE_FUNCTION: - return functionNodeCopy((const SFunctionNode*)pNode, (SFunctionNode*)pDst); + code = functionNodeCopy((const SFunctionNode*)pNode, (SFunctionNode*)pDst); + break; case QUERY_NODE_REAL_TABLE: - return realTableNodeCopy((const SRealTableNode*)pNode, (SRealTableNode*)pDst); + code = realTableNodeCopy((const SRealTableNode*)pNode, (SRealTableNode*)pDst); + break; case QUERY_NODE_TEMP_TABLE: - return tempTableNodeCopy((const STempTableNode*)pNode, (STempTableNode*)pDst); + code = tempTableNodeCopy((const STempTableNode*)pNode, (STempTableNode*)pDst); + break; case QUERY_NODE_JOIN_TABLE: - return joinTableNodeCopy((const SJoinTableNode*)pNode, (SJoinTableNode*)pDst); + code = joinTableNodeCopy((const SJoinTableNode*)pNode, (SJoinTableNode*)pDst); + break; case QUERY_NODE_GROUPING_SET: - return groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst); + code = groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst); + break; case QUERY_NODE_ORDER_BY_EXPR: - return orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst); + code = orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst); + break; case QUERY_NODE_LIMIT: - return limitNodeCopy((const SLimitNode*)pNode, (SLimitNode*)pDst); + code = limitNodeCopy((const SLimitNode*)pNode, (SLimitNode*)pDst); + break; case QUERY_NODE_STATE_WINDOW: - return stateWindowNodeCopy((const SStateWindowNode*)pNode, (SStateWindowNode*)pDst); + code = stateWindowNodeCopy((const SStateWindowNode*)pNode, (SStateWindowNode*)pDst); + break; case QUERY_NODE_SESSION_WINDOW: - return sessionWindowNodeCopy((const SSessionWindowNode*)pNode, (SSessionWindowNode*)pDst); + code = sessionWindowNodeCopy((const SSessionWindowNode*)pNode, (SSessionWindowNode*)pDst); + break; case QUERY_NODE_INTERVAL_WINDOW: - return intervalWindowNodeCopy((const SIntervalWindowNode*)pNode, (SIntervalWindowNode*)pDst); + code = intervalWindowNodeCopy((const SIntervalWindowNode*)pNode, (SIntervalWindowNode*)pDst); + break; case QUERY_NODE_NODE_LIST: - return nodeListNodeCopy((const SNodeListNode*)pNode, (SNodeListNode*)pDst); + code = nodeListNodeCopy((const SNodeListNode*)pNode, (SNodeListNode*)pDst); + break; case QUERY_NODE_FILL: - return fillNodeCopy((const SFillNode*)pNode, (SFillNode*)pDst); + code = fillNodeCopy((const SFillNode*)pNode, (SFillNode*)pDst); + break; case QUERY_NODE_TARGET: - return targetNodeCopy((const STargetNode*)pNode, (STargetNode*)pDst); + code = targetNodeCopy((const STargetNode*)pNode, (STargetNode*)pDst); + break; case QUERY_NODE_DATABLOCK_DESC: - return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst); + code = dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst); + break; case QUERY_NODE_SLOT_DESC: - return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst); + code = slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst); + break; case QUERY_NODE_DOWNSTREAM_SOURCE: - return downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst); + code = downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst); + break; case QUERY_NODE_LEFT_VALUE: - return pDst; + code = TSDB_CODE_SUCCESS; + break; case QUERY_NODE_SELECT_STMT: - return selectStmtCopy((const SSelectStmt*)pNode, (SSelectStmt*)pDst); + code = selectStmtCopy((const SSelectStmt*)pNode, (SSelectStmt*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_SCAN: - return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst); + code = logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_JOIN: - return logicJoinCopy((const SJoinLogicNode*)pNode, (SJoinLogicNode*)pDst); + code = logicJoinCopy((const SJoinLogicNode*)pNode, (SJoinLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_AGG: - return logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst); + code = logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_PROJECT: - return logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst); + code = logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY: - return logicVnodeModifCopy((const SVnodeModifyLogicNode*)pNode, (SVnodeModifyLogicNode*)pDst); + code = logicVnodeModifCopy((const SVnodeModifyLogicNode*)pNode, (SVnodeModifyLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_EXCHANGE: - return logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst); + code = logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_MERGE: - return logicMergeCopy((const SMergeLogicNode*)pNode, (SMergeLogicNode*)pDst); + code = logicMergeCopy((const SMergeLogicNode*)pNode, (SMergeLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_WINDOW: - return logicWindowCopy((const SWindowLogicNode*)pNode, (SWindowLogicNode*)pDst); + code = logicWindowCopy((const SWindowLogicNode*)pNode, (SWindowLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_FILL: - return logicFillCopy((const SFillLogicNode*)pNode, (SFillLogicNode*)pDst); + code = logicFillCopy((const SFillLogicNode*)pNode, (SFillLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_SORT: - return logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst); + code = logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_PARTITION: - return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst); + code = logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC: - return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst); + code = logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_PLAN_INTERP_FUNC: - return logicInterpFuncCopy((const SInterpFuncLogicNode*)pNode, (SInterpFuncLogicNode*)pDst); + code = logicInterpFuncCopy((const SInterpFuncLogicNode*)pNode, (SInterpFuncLogicNode*)pDst); + break; case QUERY_NODE_LOGIC_SUBPLAN: - return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst); + code = logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: - return physiTagScanCopy((const STagScanPhysiNode*)pNode, (STagScanPhysiNode*)pDst); + code = physiTagScanCopy((const STagScanPhysiNode*)pNode, (STagScanPhysiNode*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: - return physiTableScanCopy((const STableScanPhysiNode*)pNode, (STableScanPhysiNode*)pDst); + code = physiTableScanCopy((const STableScanPhysiNode*)pNode, (STableScanPhysiNode*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: - return physiSysTableScanCopy((const SSystemTableScanPhysiNode*)pNode, (SSystemTableScanPhysiNode*)pDst); + code = physiSysTableScanCopy((const SSystemTableScanPhysiNode*)pNode, (SSystemTableScanPhysiNode*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL: case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL: - return physiIntervalCopy((const SIntervalPhysiNode*)pNode, (SIntervalPhysiNode*)pDst); + code = physiIntervalCopy((const SIntervalPhysiNode*)pNode, (SIntervalPhysiNode*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION: case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION: - return physiSessionCopy((const SSessionWinodwPhysiNode*)pNode, (SSessionWinodwPhysiNode*)pDst); + code = physiSessionCopy((const SSessionWinodwPhysiNode*)pNode, (SSessionWinodwPhysiNode*)pDst); + break; case QUERY_NODE_PHYSICAL_PLAN_PARTITION: - return physiPartitionCopy((const SPartitionPhysiNode*)pNode, (SPartitionPhysiNode*)pDst); + code = physiPartitionCopy((const SPartitionPhysiNode*)pNode, (SPartitionPhysiNode*)pDst); + break; default: break; } - nodesDestroyNode(pDst); - nodesError("nodesCloneNode unknown node = %s", nodesNodeName(nodeType(pNode))); - return NULL; + + if (TSDB_CODE_SUCCESS != code) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + nodesDestroyNode(pDst); + nodesError("nodesCloneNode failed node = %s", nodesNodeName(nodeType(pNode))); + return NULL; + } + return pDst; } SNodeList* nodesCloneList(const SNodeList* pList) { @@ -725,19 +767,15 @@ SNodeList* nodesCloneList(const SNodeList* pList) { return NULL; } - SNodeList* pDst = nodesMakeList(); - if (NULL == pDst) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - SNode* pNode; + SNodeList* pDst = NULL; + SNode* pNode; FOREACH(pNode, pList) { - SNode* pNewNode = nodesCloneNode(pNode); - if (NULL == pNewNode) { + int32_t code = nodesListMakeStrictAppend(&pDst, nodesCloneNode(pNode)); + if (TSDB_CODE_SUCCESS != code) { + terrno = TSDB_CODE_OUT_OF_MEMORY; nodesDestroyList(pDst); return NULL; } - nodesListAppend(pDst, pNewNode); } return pDst; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index d31376cd13..1858918e4a 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -220,6 +220,8 @@ const char* nodesNodeName(ENodeType type) { return "PhysiSystemTableScan"; case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: return "PhysiBlockDistScan"; + case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: + return "PhysiLastRowScan"; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return "PhysiProject"; case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: @@ -489,6 +491,8 @@ static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) { static const char* jkLogicPlanTargets = "Targets"; static const char* jkLogicPlanConditions = "Conditions"; static const char* jkLogicPlanChildren = "Children"; +static const char* jkLogicPlanLimit = "Limit"; +static const char* jkLogicPlanSlimit = "SLimit"; static int32_t logicPlanNodeToJson(const void* pObj, SJson* pJson) { const SLogicNode* pNode = (const SLogicNode*)pObj; @@ -500,6 +504,12 @@ static int32_t logicPlanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkLogicPlanChildren, pNode->pChildren); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkLogicPlanLimit, nodeToJson, pNode->pLimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkLogicPlanSlimit, nodeToJson, pNode->pSlimit); + } return code; } @@ -514,6 +524,12 @@ static int32_t jsonToLogicPlanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkLogicPlanChildren, &pNode->pChildren); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkLogicPlanLimit, &pNode->pLimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkLogicPlanSlimit, &pNode->pSlimit); + } return code; } @@ -579,10 +595,6 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) { } static const char* jkProjectLogicPlanProjections = "Projections"; -static const char* jkProjectLogicPlanLimit = "Limit"; -static const char* jkProjectLogicPlanOffset = "Offset"; -static const char* jkProjectLogicPlanSlimit = "SLimit"; -static const char* jkProjectLogicPlanSoffset = "SOffset"; static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) { const SProjectLogicNode* pNode = (const SProjectLogicNode*)pObj; @@ -591,18 +603,6 @@ static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkProjectLogicPlanProjections, pNode->pProjections); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanLimit, pNode->limit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanOffset, pNode->offset); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanSlimit, pNode->slimit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanSoffset, pNode->soffset); - } return code; } @@ -614,18 +614,6 @@ static int32_t jsonToLogicProjectNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkProjectLogicPlanProjections, &pNode->pProjections); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanLimit, &pNode->limit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanOffset, &pNode->offset); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanSlimit, &pNode->slimit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectLogicPlanSoffset, &pNode->soffset); - } return code; } @@ -1281,6 +1269,8 @@ static int32_t logicJoinNodeToJson(const void* pObj, SJson* pJson) { static const char* jkPhysiPlanOutputDataBlockDesc = "OutputDataBlockDesc"; static const char* jkPhysiPlanConditions = "Conditions"; static const char* jkPhysiPlanChildren = "Children"; +static const char* jkPhysiPlanLimit = "Limit"; +static const char* jkPhysiPlanSlimit = "SLimit"; static int32_t physicPlanNodeToJson(const void* pObj, SJson* pJson) { const SPhysiNode* pNode = (const SPhysiNode*)pObj; @@ -1292,6 +1282,12 @@ static int32_t physicPlanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkPhysiPlanChildren, pNode->pChildren); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkPhysiPlanLimit, nodeToJson, pNode->pLimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkPhysiPlanSlimit, nodeToJson, pNode->pSlimit); + } return code; } @@ -1306,6 +1302,12 @@ static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkPhysiPlanChildren, &pNode->pChildren); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkPhysiPlanLimit, &pNode->pLimit); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkPhysiPlanSlimit, &pNode->pSlimit); + } return code; } @@ -1588,10 +1590,6 @@ static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) { } static const char* jkProjectPhysiPlanProjections = "Projections"; -static const char* jkProjectPhysiPlanLimit = "Limit"; -static const char* jkProjectPhysiPlanOffset = "Offset"; -static const char* jkProjectPhysiPlanSlimit = "SLimit"; -static const char* jkProjectPhysiPlanSoffset = "SOffset"; static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) { const SProjectPhysiNode* pNode = (const SProjectPhysiNode*)pObj; @@ -1600,18 +1598,6 @@ static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkProjectPhysiPlanProjections, pNode->pProjections); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanLimit, pNode->limit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanOffset, pNode->offset); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanSlimit, pNode->slimit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectPhysiPlanSoffset, pNode->soffset); - } return code; } @@ -1623,18 +1609,6 @@ static int32_t jsonToPhysiProjectNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkProjectPhysiPlanProjections, &pNode->pProjections); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanLimit, &pNode->limit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanOffset, &pNode->offset); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanSlimit, &pNode->slimit); - } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBigIntValue(pJson, jkProjectPhysiPlanSoffset, &pNode->soffset); - } return code; } @@ -2324,6 +2298,7 @@ static const char* jkSubplanNodeAddr = "NodeAddr"; static const char* jkSubplanRootNode = "RootNode"; static const char* jkSubplanDataSink = "DataSink"; static const char* jkSubplanTagCond = "TagCond"; +static const char* jkSubplanTagIndexCond = "TagIndexCond"; static int32_t subplanToJson(const void* pObj, SJson* pJson) { const SSubplan* pNode = (const SSubplan*)pObj; @@ -2353,6 +2328,9 @@ static int32_t subplanToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkSubplanTagCond, nodeToJson, pNode->pTagCond); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkSubplanTagIndexCond, nodeToJson, pNode->pTagIndexCond); + } return code; } @@ -2386,6 +2364,9 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkSubplanTagCond, (SNode**)&pNode->pTagCond); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkSubplanTagIndexCond, (SNode**)&pNode->pTagIndexCond); + } return code; } @@ -3156,6 +3137,31 @@ static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkLimitLimit = "Limit"; +static const char* jkLimitOffset = "Offset"; + +static int32_t limitNodeToJson(const void* pObj, SJson* pJson) { + const SLimitNode* pNode = (const SLimitNode*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkLimitLimit, pNode->limit); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkLimitOffset, pNode->offset); + } + + return code; +} + +static int32_t jsonToLimitNode(const SJson* pJson, void* pObj) { + SLimitNode* pNode = (SLimitNode*)pObj; + + int32_t code = tjsonGetBigIntValue(pJson, jkLimitLimit, &pNode->limit); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBigIntValue(pJson, jkLimitOffset, &pNode->offset); + } + + return code; +} + static const char* jkStateWindowCol = "StateWindowCol"; static const char* jkStateWindowExpr = "StateWindowExpr"; @@ -3952,7 +3958,7 @@ static int32_t deleteStmtToJson(const void* pObj, SJson* pJson) { code = tjsonAddObject(pJson, jkDeleteStmtCountFunc, nodeToJson, pNode->pCountFunc); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddObject(pJson, jkDeleteStmtTagIndexCond, nodeToJson, pNode->pTagIndexCond); + code = tjsonAddObject(pJson, jkDeleteStmtTagIndexCond, nodeToJson, pNode->pTagCond); } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkDeleteStmtTimeRangeStartKey, pNode->timeRange.skey); @@ -3981,7 +3987,7 @@ static int32_t jsonToDeleteStmt(const SJson* pJson, void* pObj) { code = jsonToNodeObject(pJson, jkDeleteStmtCountFunc, &pNode->pCountFunc); } if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeObject(pJson, jkDeleteStmtTagIndexCond, &pNode->pTagIndexCond); + code = jsonToNodeObject(pJson, jkDeleteStmtTagIndexCond, &pNode->pTagCond); } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBigIntValue(pJson, jkDeleteStmtTimeRangeStartKey, &pNode->timeRange.skey); @@ -4022,7 +4028,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_ORDER_BY_EXPR: return orderByExprNodeToJson(pObj, pJson); case QUERY_NODE_LIMIT: - break; + return limitNodeToJson(pObj, pJson); case QUERY_NODE_STATE_WINDOW: return stateWindowNodeToJson(pObj, pJson); case QUERY_NODE_SESSION_WINDOW: @@ -4105,6 +4111,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { return logicPlanToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: return physiTagScanNodeToJson(pObj, pJson); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: @@ -4181,6 +4188,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToTempTableNode(pJson, pObj); case QUERY_NODE_ORDER_BY_EXPR: return jsonToOrderByExprNode(pJson, pObj); + case QUERY_NODE_LIMIT: + return jsonToLimitNode(pJson, pObj); case QUERY_NODE_STATE_WINDOW: return jsonToStateWindowNode(pJson, pObj); case QUERY_NODE_SESSION_WINDOW: @@ -4245,6 +4254,7 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToLogicPlan(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: return jsonToPhysiTagScanNode(pJson, pObj); case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 4721884391..1d8baf5373 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -210,6 +210,7 @@ SNode* nodesMakeNode(ENodeType type) { case QUERY_NODE_SHOW_VARIABLES_STMT: case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: case QUERY_NODE_SHOW_TRANSACTIONS_STMT: + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: return makeNode(type, sizeof(SShowDnodeVariablesStmt)); @@ -273,6 +274,8 @@ SNode* nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SSystemTableScanPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: return makeNode(type, sizeof(SBlockDistScanPhysiNode)); + case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: + return makeNode(type, sizeof(SLastRowScanPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_PROJECT: return makeNode(type, sizeof(SProjectPhysiNode)); case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: @@ -369,6 +372,8 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) { static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode((SNode*)pNode->pInputDataBlockDesc); } +static void destroyExprNode(SExprNode* pExpr) { taosArrayDestroy(pExpr->pAssociation); } + void nodesDestroyNode(SNode* pNode) { if (NULL == pNode) { return; @@ -376,9 +381,11 @@ void nodesDestroyNode(SNode* pNode) { switch (nodeType(pNode)) { case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release + destroyExprNode((SExprNode*)pNode); break; case QUERY_NODE_VALUE: { SValueNode* pValue = (SValueNode*)pNode; + destroyExprNode((SExprNode*)pNode); taosMemoryFreeClear(pValue->literal); if (IS_VAR_DATA_TYPE(pValue->node.resType.type)) { taosMemoryFreeClear(pValue->datum.p); @@ -387,14 +394,17 @@ void nodesDestroyNode(SNode* pNode) { } case QUERY_NODE_OPERATOR: { SOperatorNode* pOp = (SOperatorNode*)pNode; + destroyExprNode((SExprNode*)pNode); nodesDestroyNode(pOp->pLeft); nodesDestroyNode(pOp->pRight); break; } case QUERY_NODE_LOGIC_CONDITION: + destroyExprNode((SExprNode*)pNode); nodesDestroyList(((SLogicConditionNode*)pNode)->pParameterList); break; case QUERY_NODE_FUNCTION: + destroyExprNode((SExprNode*)pNode); nodesDestroyList(((SFunctionNode*)pNode)->pParameterList); break; case QUERY_NODE_REAL_TABLE: { @@ -642,7 +652,8 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_SHOW_SCORES_STMT: case QUERY_NODE_SHOW_VARIABLES_STMT: case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: - case QUERY_NODE_SHOW_TRANSACTIONS_STMT: { + case QUERY_NODE_SHOW_TRANSACTIONS_STMT: + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: { SShowStmt* pStmt = (SShowStmt*)pNode; nodesDestroyNode(pStmt->pDbName); nodesDestroyNode(pStmt->pTbName); @@ -667,7 +678,7 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode(pStmt->pFromTable); nodesDestroyNode(pStmt->pWhere); nodesDestroyNode(pStmt->pCountFunc); - nodesDestroyNode(pStmt->pTagIndexCond); + nodesDestroyNode(pStmt->pTagCond); break; } case QUERY_NODE_QUERY: { @@ -686,7 +697,13 @@ void nodesDestroyNode(SNode* pNode) { SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode; destroyLogicNode((SLogicNode*)pLogicNode); nodesDestroyList(pLogicNode->pScanCols); + nodesDestroyList(pLogicNode->pScanPseudoCols); taosMemoryFreeClear(pLogicNode->pVgroupList); + nodesDestroyList(pLogicNode->pDynamicScanFuncs); + nodesDestroyNode(pLogicNode->pTagCond); + nodesDestroyNode(pLogicNode->pTagIndexCond); + taosArrayDestroy(pLogicNode->pSmaIndexes); + nodesDestroyList(pLogicNode->pPartTags); break; } case QUERY_NODE_LOGIC_PLAN_JOIN: { @@ -781,6 +798,7 @@ void nodesDestroyNode(SNode* pNode) { case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: case QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN: + case QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN: destroyScanPhysiNode((SScanPhysiNode*)pNode); break; case QUERY_NODE_PHYSICAL_PLAN_PROJECT: { @@ -822,6 +840,7 @@ void nodesDestroyNode(SNode* pNode) { destroyPhysiNode((SPhysiNode*)pPhyNode); nodesDestroyList(pPhyNode->pExprs); nodesDestroyList(pPhyNode->pSortKeys); + nodesDestroyList(pPhyNode->pTargets); break; } case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: @@ -894,6 +913,8 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyList(pSubplan->pChildren); nodesDestroyNode((SNode*)pSubplan->pNode); nodesDestroyNode((SNode*)pSubplan->pDataSink); + nodesDestroyNode((SNode*)pSubplan->pTagCond); + nodesDestroyNode((SNode*)pSubplan->pTagIndexCond); nodesClearList(pSubplan->pParents); break; } @@ -1083,6 +1104,16 @@ SNode* nodesListGetNode(SNodeList* pList, int32_t index) { return NULL; } +SListCell* nodesListGetCell(SNodeList* pList, int32_t index) { + SNode* node; + FOREACH(node, pList) { + if (0 == index--) { + return cell; + } + } + return NULL; +} + void nodesDestroyList(SNodeList* pList) { if (NULL == pList) { return; @@ -1127,6 +1158,7 @@ void* nodesGetValueFromNode(SValueNode* pNode) { case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: + case TSDB_DATA_TYPE_JSON: return (void*)pNode->datum.p; default: break; @@ -1354,6 +1386,17 @@ bool nodesIsRegularOp(const SOperatorNode* pOp) { return false; } +bool nodesIsBitwiseOp(const SOperatorNode* pOp) { + switch (pOp->opType) { + case OP_TYPE_BIT_AND: + case OP_TYPE_BIT_OR: + return true; + default: + break; + } + return false; +} + typedef struct SCollectColumnsCxt { int32_t errCode; const char* pTableAlias; @@ -1645,6 +1688,7 @@ int32_t nodesMergeConds(SNode** pDst, SNodeList** pSrc) { typedef struct SClassifyConditionCxt { bool hasPrimaryKey; bool hasTagIndexCol; + bool hasTagCol; bool hasOtherCol; } SClassifyConditionCxt; @@ -1656,6 +1700,9 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { pCxt->hasPrimaryKey = true; } else if (pCol->hasIndex) { pCxt->hasTagIndexCol = true; + pCxt->hasTagCol = true; + } else if (COLUMN_TYPE_TAG == pCol->colType) { + pCxt->hasTagCol = true; } else { pCxt->hasOtherCol = true; } @@ -1664,23 +1711,31 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } -typedef enum EConditionType { COND_TYPE_PRIMARY_KEY = 1, COND_TYPE_TAG_INDEX, COND_TYPE_NORMAL } EConditionType; +typedef enum EConditionType { + COND_TYPE_PRIMARY_KEY = 1, + COND_TYPE_TAG_INDEX, + COND_TYPE_TAG, + COND_TYPE_NORMAL +} EConditionType; static EConditionType classifyCondition(SNode* pNode) { SClassifyConditionCxt cxt = {.hasPrimaryKey = false, .hasTagIndexCol = false, .hasOtherCol = false}; nodesWalkExpr(pNode, classifyConditionImpl, &cxt); return cxt.hasOtherCol ? COND_TYPE_NORMAL - : (cxt.hasPrimaryKey && cxt.hasTagIndexCol + : (cxt.hasPrimaryKey && cxt.hasTagCol ? COND_TYPE_NORMAL - : (cxt.hasPrimaryKey ? COND_TYPE_PRIMARY_KEY : COND_TYPE_TAG_INDEX)); + : (cxt.hasPrimaryKey ? COND_TYPE_PRIMARY_KEY + : (cxt.hasTagIndexCol ? COND_TYPE_TAG_INDEX : COND_TYPE_TAG))); } -static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagCond, SNode** pOtherCond) { +static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, + SNode** pOtherCond) { SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(*pCondition); int32_t code = TSDB_CODE_SUCCESS; SNodeList* pPrimaryKeyConds = NULL; + SNodeList* pTagIndexConds = NULL; SNodeList* pTagConds = NULL; SNodeList* pOtherConds = NULL; SNode* pCond = NULL; @@ -1692,6 +1747,14 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S } break; case COND_TYPE_TAG_INDEX: + if (NULL != pTagIndexCond) { + code = nodesListMakeAppend(&pTagIndexConds, nodesCloneNode(pCond)); + } + if (NULL != pTagCond) { + code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); + } + break; + case COND_TYPE_TAG: if (NULL != pTagCond) { code = nodesListMakeAppend(&pTagConds, nodesCloneNode(pCond)); } @@ -1709,11 +1772,15 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S } SNode* pTempPrimaryKeyCond = NULL; + SNode* pTempTagIndexCond = NULL; SNode* pTempTagCond = NULL; SNode* pTempOtherCond = NULL; if (TSDB_CODE_SUCCESS == code) { code = nodesMergeConds(&pTempPrimaryKeyCond, &pPrimaryKeyConds); } + if (TSDB_CODE_SUCCESS == code) { + code = nodesMergeConds(&pTempTagIndexCond, &pTagIndexConds); + } if (TSDB_CODE_SUCCESS == code) { code = nodesMergeConds(&pTempTagCond, &pTagConds); } @@ -1725,6 +1792,9 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S if (NULL != pPrimaryKeyCond) { *pPrimaryKeyCond = pTempPrimaryKeyCond; } + if (NULL != pTagIndexCond) { + *pTagIndexCond = pTempTagIndexCond; + } if (NULL != pTagCond) { *pTagCond = pTempTagCond; } @@ -1735,9 +1805,11 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S *pCondition = NULL; } else { nodesDestroyList(pPrimaryKeyConds); + nodesDestroyList(pTagIndexConds); nodesDestroyList(pTagConds); nodesDestroyList(pOtherConds); nodesDestroyNode(pTempPrimaryKeyCond); + nodesDestroyNode(pTempTagIndexCond); nodesDestroyNode(pTempTagCond); nodesDestroyNode(pTempOtherCond); } @@ -1745,10 +1817,11 @@ static int32_t partitionLogicCond(SNode** pCondition, SNode** pPrimaryKeyCond, S return code; } -int32_t nodesPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagCond, SNode** pOtherCond) { +int32_t nodesPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** pTagIndexCond, SNode** pTagCond, + SNode** pOtherCond) { if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCondition) && LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pCondition)->condType) { - return partitionLogicCond(pCondition, pPrimaryKeyCond, pTagCond, pOtherCond); + return partitionLogicCond(pCondition, pPrimaryKeyCond, pTagIndexCond, pTagCond, pOtherCond); } switch (classifyCondition(*pCondition)) { @@ -1758,6 +1831,21 @@ int32_t nodesPartitionCond(SNode** pCondition, SNode** pPrimaryKeyCond, SNode** } break; case COND_TYPE_TAG_INDEX: + if (NULL != pTagIndexCond) { + *pTagIndexCond = *pCondition; + } + if (NULL != pTagCond) { + SNode* pTempCond = *pCondition; + if (NULL != pTagIndexCond) { + pTempCond = nodesCloneNode(*pCondition); + if (NULL == pTempCond) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + *pTagCond = pTempCond; + } + break; + case COND_TYPE_TAG: if (NULL != pTagCond) { *pTagCond = *pCondition; } diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 2d9bb49762..4585a59612 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -162,7 +162,7 @@ SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName); SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable); SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable); SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId); -SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword); +SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo); SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort); @@ -170,13 +170,17 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue); SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions); -SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding); -SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName); +SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pStreamOptions); +SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName); SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId); -SNode* createTopicOptions(SAstCreateContext* pCxt); -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, - const SToken* pSubDbName, SNode* pRealTable); +SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + SNode* pQuery); +SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + const SToken* pSubDbName, bool withMeta); +SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + SNode* pRealTable, bool withMeta); SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName); SNode* createDropCGroupStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pCGroupId, const SToken* pTopicName); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 54c46ecb5d..a27d0e9164 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -80,11 +80,18 @@ alter_account_option ::= CONNS literal. alter_account_option ::= STATE literal. { } /************************************************ create/alter/drop user **********************************************/ -cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); } +cmd ::= CREATE USER user_name(A) PASS NK_STRING(B) sysinfo_opt(C). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B, C); } cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); } -cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); } +//cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); } +cmd ::= ALTER USER user_name(A) ENABLE NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_ENABLE, &B); } +cmd ::= ALTER USER user_name(A) SYSINFO NK_INTEGER(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_SYSINFO, &B); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } +%type sysinfo_opt { int8_t } +%destructor sysinfo_opt { } +sysinfo_opt(A) ::= . { A = 1; } +sysinfo_opt(A) ::= SYSINFO NK_INTEGER(B). { A = taosStr2Int8(B.z, NULL, 10); } + /************************************************ grant/revoke ********************************************************/ cmd ::= GRANT privileges(A) ON priv_level(B) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C); } cmd ::= REVOKE privileges(A) ON priv_level(B) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C); } @@ -381,6 +388,8 @@ cmd ::= SHOW SNODES. cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); } +cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } +cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } db_name_cond_opt(A) ::= . { A = createDefaultDatabaseCondValue(pCxt); } db_name_cond_opt(A) ::= db_name(B) NK_DOT. { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } @@ -396,15 +405,15 @@ from_db_opt(A) ::= FROM db_name(B). /************************************************ create index ********************************************************/ cmd ::= CREATE SMA INDEX not_exists_opt(D) index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, D, &A, &B, NULL, C); } -cmd ::= CREATE FULLTEXT INDEX not_exists_opt(D) - index_name(A) ON table_name(B) NK_LP col_name_list(C) NK_RP. { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, D, &A, &B, C, NULL); } -cmd ::= DROP INDEX exists_opt(C) index_name(A) ON table_name(B). { pCxt->pRootNode = createDropIndexStmt(pCxt, C, &A, &B); } +//cmd ::= CREATE FULLTEXT INDEX not_exists_opt(D) +// index_name(A) ON table_name(B) NK_LP col_name_list(C) NK_RP. { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, D, &A, &B, C, NULL); } +cmd ::= DROP INDEX exists_opt(B) index_name(A). { pCxt->pRootNode = createDropIndexStmt(pCxt, B, &A); } -index_options(A) ::= . { A = NULL; } index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL - NK_LP duration_literal(C) NK_RP sliding_opt(D). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), NULL, D); } + NK_LP duration_literal(C) NK_RP sliding_opt(D) sma_stream_opt(E). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), NULL, D, E); } index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL - NK_LP duration_literal(C) NK_COMMA duration_literal(D) NK_RP sliding_opt(E). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D), E); } + NK_LP duration_literal(C) NK_COMMA duration_literal(D) NK_RP sliding_opt(E) + sma_stream_opt(F). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D), E, F); } %type func_list { SNodeList* } %destructor func_list { nodesDestroyList($$); } @@ -413,11 +422,19 @@ func_list(A) ::= func_list(B) NK_COMMA func(C). func(A) ::= function_name(B) NK_LP expression_list(C) NK_RP. { A = createFunctionNode(pCxt, &B, C); } +sma_stream_opt(A) ::= . { A = createStreamOptions(pCxt); } +sma_stream_opt(A) ::= stream_options(B) WATERMARK duration_literal(C). { ((SStreamOptions*)B)->pWatermark = releaseRawExprNode(pCxt, C); A = B; } +sma_stream_opt(A) ::= stream_options(B) MAX_DELAY duration_literal(C). { ((SStreamOptions*)B)->pDelay = releaseRawExprNode(pCxt, C); A = B; } + /************************************************ create/drop topic ***************************************************/ -cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, C, NULL, NULL); } -cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS DATABASE db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C, NULL); } -cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) - AS STABLE full_table_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, NULL, C); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, A, &B, C); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS DATABASE db_name(C). { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, A, &B, &C, false); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) + WITH META AS DATABASE db_name(C). { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, A, &B, &C, true); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) + AS STABLE full_table_name(C). { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, A, &B, C, false); } +cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) + WITH META AS STABLE full_table_name(C). { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, A, &B, C, true); } cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); } cmd ::= DROP CONSUMER GROUP exists_opt(A) cgroup_name(B) ON topic_name(C). { pCxt->pRootNode = createDropCGroupStmt(pCxt, A, &B, &C); } @@ -627,6 +644,16 @@ expression(A) ::= column_reference(B) NK_ARROW NK_STRING(C). SToken s = getTokenFromRawExprNode(pCxt, B); A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, B), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C))); } +expression(A) ::= expression(B) NK_BITAND expression(C). { + SToken s = getTokenFromRawExprNode(pCxt, B); + SToken e = getTokenFromRawExprNode(pCxt, C); + A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C))); + } +expression(A) ::= expression(B) NK_BITOR expression(C). { + SToken s = getTokenFromRawExprNode(pCxt, B); + SToken e = getTokenFromRawExprNode(pCxt, C); + A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C))); + } %type expression_list { SNodeList* } %destructor expression_list { nodesDestroyList($$); } @@ -757,8 +784,9 @@ boolean_primary(A) ::= NK_LP(C) boolean_value_expression(B) NK_RP(D). common_expression(A) ::= expression(B). { A = B; } common_expression(A) ::= boolean_value_expression(B). { A = B; } -/************************************************ from_clause *********************************************************/ -from_clause(A) ::= FROM table_reference_list(B). { A = B; } +/************************************************ from_clause_opt *********************************************************/ +from_clause_opt(A) ::= . { A = NULL; } +from_clause_opt(A) ::= FROM table_reference_list(B). { A = B; } table_reference_list(A) ::= table_reference(B). { A = B; } table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { A = createJoinTableNode(pCxt, JOIN_TYPE_INNER, B, C, NULL); } @@ -792,9 +820,9 @@ join_type(A) ::= INNER. /************************************************ query_specification *************************************************/ query_specification(A) ::= - SELECT set_quantifier_opt(B) select_list(C) from_clause(D) where_clause_opt(E) - partition_by_clause_opt(F) range_opt(J) every_opt(K) fill_opt(L) twindow_clause_opt(G) - group_by_clause_opt(H) having_clause_opt(I). { + SELECT set_quantifier_opt(B) select_list(C) from_clause_opt(D) + where_clause_opt(E) partition_by_clause_opt(F) range_opt(J) every_opt(K) + fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I). { A = createSelectStmt(pCxt, B, C, D); A = addWhereClause(pCxt, A, E); A = addPartitionByClause(pCxt, A, F); diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4fc5cf96e5..9709a8b1ea 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1205,7 +1205,7 @@ SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId) { return (SNode*)pStmt; } -SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) { +SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo) { CHECK_PARSER_STATUS(pCxt); char password[TSDB_USET_PASSWORD_LEN] = {0}; if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { @@ -1215,6 +1215,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST CHECK_OUT_OF_MEM(pStmt); COPY_STRING_FORM_ID_TOKEN(pStmt->useName, pUserName); strcpy(pStmt->password, password); + pStmt->sysinfo = sysinfo; return (SNode*)pStmt; } @@ -1226,15 +1227,26 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al SAlterUserStmt* pStmt = (SAlterUserStmt*)nodesMakeNode(QUERY_NODE_ALTER_USER_STMT); CHECK_OUT_OF_MEM(pStmt); COPY_STRING_FORM_ID_TOKEN(pStmt->useName, pUserName); - if (TSDB_ALTER_USER_PASSWD == alterType) { - char password[TSDB_USET_PASSWORD_LEN] = {0}; - if (!checkPassword(pCxt, pVal, password)) { - nodesDestroyNode((SNode*)pStmt); - return NULL; - } - strcpy(pStmt->password, password); - } pStmt->alterType = alterType; + switch (alterType) { + case TSDB_ALTER_USER_PASSWD: { + char password[TSDB_USET_PASSWORD_LEN] = {0}; + if (!checkPassword(pCxt, pVal, password)) { + nodesDestroyNode((SNode*)pStmt); + return NULL; + } + strcpy(pStmt->password, password); + break; + } + case TSDB_ALTER_USER_ENABLE: + pStmt->enable = taosStr2Int8(pVal->z, NULL, 10); + break; + case TSDB_ALTER_USER_SYSINFO: + pStmt->sysinfo = taosStr2Int8(pVal->z, NULL, 10); + break; + default: + break; + } return (SNode*)pStmt; } @@ -1305,8 +1317,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno return (SNode*)pStmt; } -SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, - SNode* pSliding) { +SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding, + SNode* pStreamOptions) { CHECK_PARSER_STATUS(pCxt); SIndexOptions* pOptions = (SIndexOptions*)nodesMakeNode(QUERY_NODE_INDEX_OPTIONS); CHECK_OUT_OF_MEM(pOptions); @@ -1314,19 +1326,19 @@ SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInt pOptions->pInterval = pInterval; pOptions->pOffset = pOffset; pOptions->pSliding = pSliding; + pOptions->pStreamOptions = pStreamOptions; return (SNode*)pOptions; } -SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName) { +SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName) { CHECK_PARSER_STATUS(pCxt); - if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) { + if (!checkDbName(pCxt, NULL, true) || !checkIndexName(pCxt, pIndexName)) { return NULL; } SDropIndexStmt* pStmt = (SDropIndexStmt*)nodesMakeNode(QUERY_NODE_DROP_INDEX_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->ignoreNotExists = ignoreNotExists; COPY_STRING_FORM_ID_TOKEN(pStmt->indexName, pIndexName); - COPY_STRING_FORM_ID_TOKEN(pStmt->tableName, pTableName); return (SNode*)pStmt; } @@ -1346,22 +1358,40 @@ SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, cons return (SNode*)pStmt; } -SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, - const SToken* pSubDbName, SNode* pRealTable) { +SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + SNode* pQuery) { CHECK_PARSER_STATUS(pCxt); SCreateTopicStmt* pStmt = (SCreateTopicStmt*)nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); CHECK_OUT_OF_MEM(pStmt); COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName); pStmt->ignoreExists = ignoreExists; - if (NULL != pRealTable) { - strcpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName); - strcpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName); - nodesDestroyNode(pRealTable); - } else if (NULL != pSubDbName) { - COPY_STRING_FORM_ID_TOKEN(pStmt->subDbName, pSubDbName); - } else { - pStmt->pQuery = pQuery; - } + pStmt->pQuery = pQuery; + return (SNode*)pStmt; +} + +SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + const SToken* pSubDbName, bool withMeta) { + CHECK_PARSER_STATUS(pCxt); + SCreateTopicStmt* pStmt = (SCreateTopicStmt*)nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); + CHECK_OUT_OF_MEM(pStmt); + COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName); + pStmt->ignoreExists = ignoreExists; + COPY_STRING_FORM_ID_TOKEN(pStmt->subDbName, pSubDbName); + pStmt->withMeta = withMeta; + return (SNode*)pStmt; +} + +SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, + SNode* pRealTable, bool withMeta) { + CHECK_PARSER_STATUS(pCxt); + SCreateTopicStmt* pStmt = (SCreateTopicStmt*)nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT); + CHECK_OUT_OF_MEM(pStmt); + COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName); + pStmt->ignoreExists = ignoreExists; + pStmt->withMeta = withMeta; + strcpy(pStmt->subDbName, ((SRealTableNode*)pRealTable)->table.dbName); + strcpy(pStmt->subSTbName, ((SRealTableNode*)pRealTable)->table.tableName); + nodesDestroyNode(pRealTable); return (SNode*)pStmt; } diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 46d2ae8383..80ca411e0e 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -137,6 +137,9 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, SRealTa code = reserveTableIndexInCache(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, pCxt->pMetaCache); } + if (TSDB_CODE_SUCCESS == code && (0 == strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_DNODE_VARIABLES))) { + code = reserveDnodeRequiredInCache(pCxt->pMetaCache); + } return code; } @@ -377,6 +380,11 @@ static int32_t collectMetaKeyFromShowTopics(SCollectMetaKeyCxt* pCxt, SShowStmt* pCxt->pMetaCache); } +static int32_t collectMetaKeyFromShowConsumers(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { + return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, + pCxt->pMetaCache); +} + static int32_t collectMetaKeyFromShowConnections(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONNECTIONS, pCxt->pMetaCache); @@ -453,6 +461,11 @@ static int32_t collectMetaKeyFromShowBlockDist(SCollectMetaKeyCxt* pCxt, SShowTa return code; } +static int32_t collectMetaKeyFromShowSubscriptions(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { + return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_SUBSCRIPTIONS, + pCxt->pMetaCache); +} + static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { pCxt->pStmt = pStmt; switch (nodeType(pStmt)) { @@ -514,6 +527,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromShowVgroups(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_SHOW_TOPICS_STMT: return collectMetaKeyFromShowTopics(pCxt, (SShowStmt*)pStmt); + case QUERY_NODE_SHOW_CONSUMERS_STMT: + return collectMetaKeyFromShowConsumers(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_SHOW_CONNECTIONS_STMT: return collectMetaKeyFromShowConnections(pCxt, (SShowStmt*)pStmt); case QUERY_NODE_SHOW_QUERIES_STMT: @@ -535,6 +550,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) { return collectMetaKeyFromDelete(pCxt, (SDeleteStmt*)pStmt); case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: return collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt); + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: + return collectMetaKeyFromShowSubscriptions(pCxt, (SShowStmt*)pStmt); default: break; } diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 22d7afd642..dcdf73630f 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -175,17 +175,23 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) { } } + char aliasName[TSDB_COL_NAME_LEN] = {0}; + strcpy(aliasName, ((SExprNode*)pProject)->aliasName); int32_t code = scalarCalculateConstants(pProject, pNew); if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(*pNew) && NULL != pAssociation) { + strcpy(((SExprNode*)*pNew)->aliasName, aliasName); int32_t size = taosArrayGetSize(pAssociation); for (int32_t i = 0; i < size; ++i) { SNode** pCol = taosArrayGetP(pAssociation, i); + nodesDestroyNode(*pCol); *pCol = nodesCloneNode(*pNew); if (NULL == *pCol) { - return TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + break; } } } + taosArrayDestroy(pAssociation); return code; } @@ -196,6 +202,19 @@ static bool isUselessCol(bool hasSelectValFunc, SExprNode* pProj) { return NULL == ((SExprNode*)pProj)->pAssociation; } +static SNode* createConstantValue() { + SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (NULL == pVal) { + return NULL; + } + pVal->node.resType.type = TSDB_DATA_TYPE_INT; + pVal->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes; + const int32_t val = 1; + nodesSetValueNodeValue(pVal, (void*)&val); + pVal->translate = true; + return (SNode*)pVal; +} + static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { SNode* pProj = NULL; WHERE_EACH(pProj, pSelect->pProjectionList) { @@ -212,6 +231,9 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelec } WHERE_NEXT; } + if (0 == LIST_LENGTH(pSelect->pProjectionList)) { + return nodesListStrictAppend(pSelect->pProjectionList, createConstantValue()); + } return TSDB_CODE_SUCCESS; } @@ -227,12 +249,16 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) { } } } - DESTORY_LIST(pSelect->pGroupByList); + NODES_DESTORY_LIST(pSelect->pGroupByList); } return code; } -static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { +static int32_t calcConstSelectWithoutFrom(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { + return calcConstProjections(pCxt, pSelect, subquery); +} + +static int32_t calcConstSelectFrom(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { int32_t code = calcConstFromTable(pCxt, pSelect->pFromTable); if (TSDB_CODE_SUCCESS == code) { code = calcConstProjections(pCxt, pSelect, subquery); @@ -258,6 +284,14 @@ static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bo return code; } +static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) { + if (NULL == pSelect->pFromTable) { + return calcConstSelectWithoutFrom(pCxt, pSelect, subquery); + } else { + return calcConstSelectFrom(pCxt, pSelect, subquery); + } +} + static int32_t calcConstDelete(SCalcConstContext* pCxt, SDeleteStmt* pDelete) { int32_t code = calcConstFromTable(pCxt, pDelete->pFromTable); if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 21f227b7ea..6726bb7dfd 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -63,6 +63,7 @@ static SKeyword keywordTable[] = { {"CONNECTION", TK_CONNECTION}, {"CONNECTIONS", TK_CONNECTIONS}, {"CONSUMER", TK_CONSUMER}, + {"CONSUMERS", TK_CONSUMERS}, {"COUNT", TK_COUNT}, {"CREATE", TK_CREATE}, {"CONTAINS", TK_CONTAINS}, @@ -79,6 +80,7 @@ static SKeyword keywordTable[] = { {"DOUBLE", TK_DOUBLE}, {"DROP", TK_DROP}, {"DURATION", TK_DURATION}, + {"ENABLE", TK_ENABLE}, {"EXISTS", TK_EXISTS}, {"EXPLAIN", TK_EXPLAIN}, {"EVERY", TK_EVERY}, @@ -120,6 +122,7 @@ static SKeyword keywordTable[] = { {"MAXROWS", TK_MAXROWS}, {"MAX_DELAY", TK_MAX_DELAY}, {"MERGE", TK_MERGE}, + {"META", TK_META}, {"MINROWS", TK_MINROWS}, {"MINUS", TK_MINUS}, {"MNODE", TK_MNODE}, @@ -146,7 +149,7 @@ static SKeyword keywordTable[] = { {"PORT", TK_PORT}, {"PPS", TK_PPS}, {"PRECISION", TK_PRECISION}, - {"PRIVILEGE", TK_PRIVILEGE}, + // {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, @@ -186,7 +189,9 @@ static SKeyword keywordTable[] = { {"STREAM", TK_STREAM}, {"STREAMS", TK_STREAMS}, {"STRICT", TK_STRICT}, + {"SUBSCRIPTIONS", TK_SUBSCRIPTIONS}, {"SYNCDB", TK_SYNCDB}, + {"SYSINFO", TK_SYSINFO}, {"TABLE", TK_TABLE}, {"TABLES", TK_TABLES}, {"TAG", TK_TAG}, @@ -222,6 +227,7 @@ static SKeyword keywordTable[] = { {"WATERMARK", TK_WATERMARK}, {"WHERE", TK_WHERE}, {"WINDOW_CLOSE", TK_WINDOW_CLOSE}, + {"WITH", TK_WITH}, {"WRITE", TK_WRITE}, {"_C0", TK_ROWTS}, {"_QENDTS", TK_QENDTS}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 502e35cc4c..424968ac80 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -517,8 +517,9 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p if (NULL == pCol) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); } - setColumnInfoByExpr(pTable, (SExprNode*)pNode, &pCol); nodesListAppend(pList, (SNode*)pCol); + SListCell* pCell = nodesListGetCell(pList, LIST_LENGTH(pList) - 1); + setColumnInfoByExpr(pTable, (SExprNode*)pNode, (SColumnNode**)&pCell->pNode); } } return TSDB_CODE_SUCCESS; @@ -689,6 +690,10 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p } static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { + if (NULL != pCxt->pCurrSelectStmt && NULL == pCxt->pCurrSelectStmt->pFromTable) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName); + } + // count(*)/first(*)/last(*) and so on if (0 == strcmp((*pCol)->colName, "*")) { return DEAL_RES_CONTINUE; @@ -703,7 +708,11 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) { res = translateColumnUseAlias(pCxt, pCol, &found); } if (DEAL_RES_ERROR != res && !found) { - res = translateColumnWithoutPrefix(pCxt, pCol); + if (NULL != pCxt->pCurrSetOperator) { + res = generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName); + } else { + res = translateColumnWithoutPrefix(pCxt, pCol); + } } } return res; @@ -1008,6 +1017,17 @@ static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pO return DEAL_RES_CONTINUE; } +static EDealRes translateBitwiseOperator(STranslateContext* pCxt, SOperatorNode* pOp) { + SDataType ldt = ((SExprNode*)(pOp->pLeft))->resType; + SDataType rdt = ((SExprNode*)(pOp->pRight))->resType; + if (TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); + } + pOp->node.resType.type = TSDB_DATA_TYPE_BIGINT; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; + return DEAL_RES_CONTINUE; +} + static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode** pOpRef) { SOperatorNode* pOp = *pOpRef; @@ -1026,6 +1046,8 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode** pOpRe return translateComparisonOperator(pCxt, pOp); } else if (nodesIsJsonOp(pOp)) { return translateJsonOperator(pCxt, pOp); + } else if (nodesIsBitwiseOp(pOp)) { + return translateBitwiseOperator(pCxt, pOp); } return DEAL_RES_CONTINUE; } @@ -1200,6 +1222,7 @@ static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) { pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType); pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType); pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType); + pSelect->hasLastRowFunc = pSelect->hasLastRowFunc ? true : (FUNCTION_TYPE_LAST_ROW == pFunc->funcType); } } @@ -1995,7 +2018,7 @@ static int32_t getFillTimeRange(STranslateContext* pCxt, SNode* pWhere, STimeWin } SNode* pPrimaryKeyCond = NULL; - nodesPartitionCond(&pCond, &pPrimaryKeyCond, NULL, NULL); + nodesPartitionCond(&pCond, &pPrimaryKeyCond, NULL, NULL, NULL); int32_t code = TSDB_CODE_SUCCESS; if (NULL != pPrimaryKeyCond) { @@ -2143,9 +2166,6 @@ static EDealRes checkStateExpr(SNode* pNode, void* pContext) { if (COLUMN_TYPE_TAG == pCol->colType) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); } - if (TSDB_SUPER_TABLE == pCol->tableType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE); - } } return DEAL_RES_CONTINUE; } @@ -2376,6 +2396,8 @@ static SNode* createGroupingSet(SNode* pExpr) { return (SNode*)pGroupingSet; } +// from: select unique(expr), col1 + col2 from t where_clause partition_by_clause order_by_clause ... +// to: select expr, first(col1) + first(col2) from t where_clause partition_by_clause group by expr order_by_clause ... static int32_t rewriteUniqueStmt(STranslateContext* pCxt, SSelectStmt* pSelect) { if (!pSelect->hasUniqueFunc) { return TSDB_CODE_SUCCESS; @@ -2441,6 +2463,8 @@ static SNode* createOrderByExpr(STranslateContext* pCxt) { return (SNode*)pOrder; } +// from: select tail(expr, k, f) from t where_clause partition_by_clause order_by_clause ... +// to: select expr from t where_clause order by _rowts desc limit k offset f static int32_t rewriteTailStmt(STranslateContext* pCxt, SSelectStmt* pSelect) { if (!pSelect->hasTailFunc) { return TSDB_CODE_SUCCESS; @@ -2489,7 +2513,13 @@ static int32_t replaceOrderByAlias(STranslateContext* pCxt, SNodeList* pProjecti return pCxt->errCode; } -static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { +static int32_t translateSelectWithoutFrom(STranslateContext* pCxt, SSelectStmt* pSelect) { + pCxt->pCurrSelectStmt = pSelect; + pCxt->currClause = SQL_CLAUSE_SELECT; + return translateExprList(pCxt, pSelect->pProjectionList); +} + +static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->pCurrSelectStmt = pSelect; int32_t code = translateFrom(pCxt, pSelect->pFromTable); if (TSDB_CODE_SUCCESS == code) { @@ -2538,6 +2568,14 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (NULL == pSelect->pFromTable) { + return translateSelectWithoutFrom(pCxt, pSelect); + } else { + return translateSelectFrom(pCxt, pSelect); + } +} + static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) { SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); if (NULL == pCol) { @@ -2623,6 +2661,13 @@ static int32_t translateSetOperOrderBy(STranslateContext* pCxt, SSetOperator* pS return code; } +static int32_t checkSetOperLimit(STranslateContext* pCxt, SLimitNode* pLimit) { + if ((NULL != pLimit && pLimit->offset < 0)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_OFFSET_LESS_ZERO); + } + return TSDB_CODE_SUCCESS; +} + static int32_t translateSetOperator(STranslateContext* pCxt, SSetOperator* pSetOperator) { int32_t code = translateQuery(pCxt, pSetOperator->pLeft); if (TSDB_CODE_SUCCESS == code) { @@ -2638,6 +2683,9 @@ static int32_t translateSetOperator(STranslateContext* pCxt, SSetOperator* pSetO if (TSDB_CODE_SUCCESS == code) { code = translateSetOperOrderBy(pCxt, pSetOperator); } + if (TSDB_CODE_SUCCESS == code) { + code = checkSetOperLimit(pCxt, (SLimitNode*)pSetOperator->pLimit); + } return code; } @@ -2649,7 +2697,7 @@ static int32_t partitionDeleteWhere(STranslateContext* pCxt, SDeleteStmt* pDelet SNode* pPrimaryKeyCond = NULL; SNode* pOtherCond = NULL; - int32_t code = nodesPartitionCond(&pDelete->pWhere, &pPrimaryKeyCond, &pDelete->pTagIndexCond, &pOtherCond); + int32_t code = nodesPartitionCond(&pDelete->pWhere, &pPrimaryKeyCond, NULL, &pDelete->pTagCond, &pOtherCond); if (TSDB_CODE_SUCCESS == code && NULL != pOtherCond) { code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DELETE_WHERE); } @@ -3533,9 +3581,7 @@ static int32_t buildRollupFuncs(SNodeList* pFuncs, SArray** pArray) { } *pArray = taosArrayInit(LIST_LENGTH(pFuncs), TSDB_FUNC_NAME_LEN); SNode* pNode; - FOREACH(pNode, pFuncs) { - taosArrayPush(*pArray, ((SFunctionNode*)pNode)->functionName); - } + FOREACH(pNode, pFuncs) { taosArrayPush(*pArray, ((SFunctionNode*)pNode)->functionName); } return TSDB_CODE_SUCCESS; } @@ -3721,7 +3767,7 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt strcpy(createReq.user, pStmt->useName); createReq.createType = 0; createReq.superUser = 0; - createReq.sysInfo = 1; + createReq.sysInfo = pStmt->sysinfo; createReq.enable = 1; strcpy(createReq.pass, pStmt->password); @@ -3733,6 +3779,8 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt strcpy(alterReq.user, pStmt->useName); alterReq.alterType = pStmt->alterType; alterReq.superUser = 0; + alterReq.enable = pStmt->enable; + alterReq.sysInfo = pStmt->sysinfo; strcpy(alterReq.pass, pStmt->password); if (NULL != pCxt->pParseCxt->db) { strcpy(alterReq.dbname, pCxt->pParseCxt->db); @@ -3832,6 +3880,11 @@ static int32_t buildCreateSmaReq(STranslateContext* pCxt, SCreateIndexStmt* pStm (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pReq->interval); pReq->slidingUnit = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pReq->intervalUnit); + if (NULL != pStmt->pOptions->pStreamOptions) { + SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; + pReq->maxDelay = (NULL != pStreamOpt->pDelay ? ((SValueNode*)pStreamOpt->pDelay)->datum.i : 0); + pReq->watermark = (NULL != pStreamOpt->pWatermark ? ((SValueNode*)pStreamOpt->pWatermark)->datum.i : 0); + } int32_t code = getSmaIndexDstVgId(pCxt, pStmt->tableName, &pReq->dstVgId); if (TSDB_CODE_SUCCESS == code) { @@ -3853,6 +3906,18 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt return pCxt->errCode; } + if (NULL != pStmt->pOptions->pStreamOptions) { + SStreamOptions* pStreamOpt = (SStreamOptions*)pStmt->pOptions->pStreamOptions; + if (NULL != pStreamOpt->pWatermark && + (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStreamOpt->pWatermark))) { + return pCxt->errCode; + } + + if (NULL != pStreamOpt->pDelay && (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStreamOpt->pDelay))) { + return pCxt->errCode; + } + } + SMCreateSmaReq createSmaReq = {0}; int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); if (TSDB_CODE_SUCCESS == code) { @@ -3887,36 +3952,11 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p } static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) { - SEncoder encoder = {0}; - int32_t contLen = 0; - SVDropTSmaReq dropSmaReq = {0}; - strcpy(dropSmaReq.indexName, pStmt->indexName); - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - int32_t ret = 0; - tEncodeSize(tEncodeSVDropTSmaReq, &dropSmaReq, contLen, ret); - if (ret < 0) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_VND_DROP_SMA; - pCxt->pCmdMsg->msgLen = contLen; - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - void* pBuf = pCxt->pCmdMsg->pMsg; - if (tEncodeSVDropTSmaReq(&encoder, &dropSmaReq) < 0) { - tEncoderClear(&encoder); - return TSDB_CODE_OUT_OF_MEMORY; - } - tEncoderClear(&encoder); - return TSDB_CODE_SUCCESS; + SMDropSmaReq dropSmaReq = {0}; + SName name; + tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pStmt->indexName, &name), dropSmaReq.name); + dropSmaReq.igNotExists = pStmt->ignoreNotExists; + return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq); } static int16_t getCreateComponentNodeMsgType(ENodeType type) { @@ -3968,6 +4008,7 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName)); tNameGetFullDbName(&name, pReq->name); pReq->igExists = pStmt->ignoreExists; + pReq->withMeta = pStmt->withMeta; pReq->sql = strdup(pCxt->pParseCxt->pSql); if (NULL == pReq->sql) { @@ -4323,6 +4364,11 @@ static int32_t translateSplitVgroup(STranslateContext* pCxt, SSplitVgroupStmt* p return buildCmdMsg(pCxt, TDMT_MND_SPLIT_VGROUP, (FSerializeFunc)tSerializeSSplitVgroupReq, &req); } +static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) { + SShowVariablesReq req = {0}; + return buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req); +} + static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) { pStmt->pCfg = taosMemoryCalloc(1, sizeof(SDbCfgInfo)); if (NULL == pStmt->pCfg) { @@ -4467,6 +4513,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_SPLIT_VGROUP_STMT: code = translateSplitVgroup(pCxt, (SSplitVgroupStmt*)pNode); break; + case QUERY_NODE_SHOW_VARIABLES_STMT: + code = translateShowVariables(pCxt, (SShowStmt*)pNode); + break; case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: code = translateShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pNode); break; @@ -4592,6 +4641,24 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema** return TSDB_CODE_SUCCESS; } +static int32_t extractShowLocalVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) { + *numOfCols = 2; + *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); + if (NULL == (*pSchema)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + (*pSchema)[0].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[0].bytes = TSDB_CONFIG_OPTION_LEN; + strcpy((*pSchema)[0].name, "name"); + + (*pSchema)[1].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[1].bytes = TSDB_CONFIG_VALUE_LEN; + strcpy((*pSchema)[1].name, "value"); + + return TSDB_CODE_SUCCESS; +} + int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { if (NULL == pRoot) { return TSDB_CODE_SUCCESS; @@ -4610,6 +4677,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS case QUERY_NODE_SHOW_CREATE_TABLE_STMT: case QUERY_NODE_SHOW_CREATE_STABLE_STMT: return extractShowCreateTableResultSchema(numOfCols, pSchema); + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: + return extractShowLocalVariablesResultSchema(numOfCols, pSchema); default: break; } @@ -4643,6 +4712,8 @@ static const char* getSysDbName(ENodeType type) { case QUERY_NODE_SHOW_STREAMS_STMT: case QUERY_NODE_SHOW_TRANSACTIONS_STMT: case QUERY_NODE_SHOW_APPS_STMT: + case QUERY_NODE_SHOW_CONSUMERS_STMT: + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: return TSDB_PERFORMANCE_SCHEMA_DB; default: break; @@ -4698,6 +4769,10 @@ static const char* getSysTableName(ENodeType type) { return TSDB_PERFS_TABLE_APPS; case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: return TSDB_INS_TABLE_DNODE_VARIABLES; + case QUERY_NODE_SHOW_CONSUMERS_STMT: + return TSDB_PERFS_TABLE_CONSUMERS; + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: + return TSDB_PERFS_TABLE_SUBSCRIPTIONS; default: break; } @@ -5836,6 +5911,8 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_TRANSACTIONS_STMT: case QUERY_NODE_SHOW_VARIABLES_STMT: case QUERY_NODE_SHOW_APPS_STMT: + case QUERY_NODE_SHOW_CONSUMERS_STMT: + case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: code = rewriteShow(pCxt, pQuery); break; case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT: @@ -5926,12 +6003,12 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: case QUERY_NODE_SHOW_CREATE_TABLE_STMT: case QUERY_NODE_SHOW_CREATE_STABLE_STMT: + case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: pQuery->execMode = QUERY_EXEC_MODE_LOCAL; pQuery->haveResultSet = true; break; case QUERY_NODE_RESET_QUERY_CACHE_STMT: case QUERY_NODE_ALTER_LOCAL_STMT: - case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: pQuery->execMode = QUERY_EXEC_MODE_LOCAL; break; default: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index b474d95b3c..c4f4624355 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -897,7 +897,7 @@ STableCfg* tableCfgDup(STableCfg* pCfg) { if (pNew->pFuncs) { pNew->pFuncs = taosArrayDup(pNew->pFuncs); } - + int32_t schemaSize = (pCfg->numOfColumns + pCfg->numOfTags) * sizeof(SSchema); SSchema* pSchema = taosMemoryMalloc(schemaSize); @@ -912,7 +912,7 @@ int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, ST char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); STableCfg* pCfg = NULL; - int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableCfg, (void**)&pCfg); + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableCfg, (void**)&pCfg); if (TSDB_CODE_SUCCESS == code) { *pOutput = tableCfgDup(pCfg); if (NULL == *pOutput) { @@ -928,7 +928,12 @@ int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache) { } int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes) { - *pDnodes = taosArrayDup(pMetaCache->pDnodes); + SMetaRes* pRes = taosArrayGet(pMetaCache->pDnodes, 0); + if (TSDB_CODE_SUCCESS != pRes->code) { + return pRes->code; + } + + *pDnodes = taosArrayDup((SArray*)pRes->pRes); if (NULL == *pDnodes) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index c7651137b1..225d163f53 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -104,25 +104,26 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 364 +#define YYNOCODE 370 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SToken yy57; - EOrder yy162; - EJoinType yy204; - SAlterOption yy221; - int32_t yy228; - EFillMode yy270; - EOperatorType yy324; - int64_t yy389; - SNode* yy392; - SDataType yy448; - bool yy481; - ENullOrder yy529; - SNodeList* yy600; + ENullOrder yy77; + SAlterOption yy85; + int32_t yy100; + SToken yy109; + EOrder yy178; + int64_t yy209; + int8_t yy323; + SNodeList* yy404; + bool yy437; + EOperatorType yy440; + SNode* yy452; + SDataType yy504; + EJoinType yy532; + EFillMode yy614; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -138,17 +139,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 641 -#define YYNRULE 466 -#define YYNTOKEN 242 -#define YY_MAX_SHIFT 640 -#define YY_MIN_SHIFTREDUCE 933 -#define YY_MAX_SHIFTREDUCE 1398 -#define YY_ERROR_ACTION 1399 -#define YY_ACCEPT_ACTION 1400 -#define YY_NO_ACTION 1401 -#define YY_MIN_REDUCE 1402 -#define YY_MAX_REDUCE 1867 +#define YYNSTATE 653 +#define YYNRULE 477 +#define YYNTOKEN 246 +#define YY_MAX_SHIFT 652 +#define YY_MIN_SHIFTREDUCE 947 +#define YY_MAX_SHIFTREDUCE 1423 +#define YY_ERROR_ACTION 1424 +#define YY_ACCEPT_ACTION 1425 +#define YY_NO_ACTION 1426 +#define YY_MIN_REDUCE 1427 +#define YY_MAX_REDUCE 1903 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -215,619 +216,623 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2192) +#define YY_ACTTAB_COUNT (2208) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1697, 1845, 1522, 309, 412, 1697, 413, 1434, 326, 1400, - /* 10 */ 137, 1694, 37, 35, 1490, 1844, 1694, 1710, 417, 1842, - /* 20 */ 318, 556, 1208, 556, 1230, 38, 36, 34, 33, 32, - /* 30 */ 325, 324, 109, 420, 109, 413, 1434, 1690, 1696, 451, - /* 40 */ 1222, 456, 1690, 1696, 1726, 30, 240, 1206, 559, 1533, - /* 50 */ 1793, 1533, 540, 559, 22, 556, 555, 1680, 14, 539, - /* 60 */ 37, 35, 1335, 322, 1214, 1215, 157, 335, 318, 1710, - /* 70 */ 1208, 134, 520, 365, 1790, 38, 36, 34, 33, 32, - /* 80 */ 1535, 1, 1214, 1533, 1739, 67, 555, 85, 1711, 542, - /* 90 */ 1713, 1714, 538, 58, 559, 1206, 1726, 1779, 113, 76, - /* 100 */ 371, 292, 1775, 637, 519, 556, 14, 1528, 1845, 1680, - /* 110 */ 1425, 539, 1214, 1845, 1845, 543, 369, 1277, 1278, 963, - /* 120 */ 1526, 560, 152, 470, 555, 1631, 1842, 154, 152, 2, - /* 130 */ 430, 1842, 1842, 1533, 206, 82, 1739, 290, 478, 86, - /* 140 */ 1711, 542, 1713, 1714, 538, 1369, 559, 40, 118, 1779, - /* 150 */ 1680, 637, 198, 311, 1775, 148, 1525, 967, 968, 1209, - /* 160 */ 58, 1207, 70, 328, 473, 1277, 1278, 232, 56, 467, - /* 170 */ 364, 134, 363, 1233, 197, 495, 1806, 1223, 330, 1218, - /* 180 */ 1535, 1578, 1580, 1212, 1213, 41, 1259, 1260, 1262, 1263, - /* 190 */ 1264, 1265, 1266, 535, 557, 1274, 1275, 1276, 1279, 53, - /* 200 */ 1232, 1226, 52, 1579, 1580, 26, 59, 1209, 1845, 1207, - /* 210 */ 510, 155, 557, 1274, 1275, 38, 36, 34, 33, 32, - /* 220 */ 37, 35, 153, 155, 1424, 1710, 1842, 402, 318, 67, - /* 230 */ 1208, 1212, 1213, 302, 1259, 1260, 1262, 1263, 1264, 1265, - /* 240 */ 1266, 535, 557, 1274, 1275, 1276, 1279, 516, 1726, 465, - /* 250 */ 464, 1529, 1726, 489, 463, 1206, 509, 114, 460, 1668, - /* 260 */ 540, 459, 458, 457, 1680, 1680, 14, 539, 37, 35, - /* 270 */ 1112, 1113, 1214, 166, 165, 117, 318, 155, 1208, 1299, - /* 280 */ 520, 1511, 303, 58, 301, 300, 356, 453, 58, 2, - /* 290 */ 155, 455, 1739, 508, 1845, 85, 1711, 542, 1713, 1714, - /* 300 */ 538, 1304, 559, 1206, 344, 1779, 358, 354, 152, 292, - /* 310 */ 1775, 637, 1842, 454, 115, 38, 36, 34, 33, 32, - /* 320 */ 1214, 1845, 136, 1524, 1414, 1277, 1278, 1509, 518, 149, - /* 330 */ 1786, 1787, 1233, 1791, 1694, 152, 27, 8, 430, 1842, - /* 340 */ 1070, 582, 581, 580, 1074, 579, 1076, 1077, 578, 1079, - /* 350 */ 575, 1403, 1085, 572, 1087, 1088, 569, 566, 81, 637, - /* 360 */ 1690, 1696, 38, 36, 34, 33, 32, 1209, 78, 1207, - /* 370 */ 1359, 559, 99, 1277, 1278, 98, 97, 96, 95, 94, - /* 380 */ 93, 92, 91, 90, 593, 1349, 38, 36, 34, 33, - /* 390 */ 32, 1212, 1213, 522, 1259, 1260, 1262, 1263, 1264, 1265, - /* 400 */ 1266, 535, 557, 1274, 1275, 1276, 1279, 502, 1357, 1358, - /* 410 */ 1360, 1361, 980, 155, 979, 1209, 99, 1207, 155, 98, - /* 420 */ 97, 96, 95, 94, 93, 92, 91, 90, 37, 35, - /* 430 */ 1280, 11, 10, 1710, 462, 461, 318, 162, 1208, 1212, - /* 440 */ 1213, 981, 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, - /* 450 */ 557, 1274, 1275, 1276, 1279, 38, 36, 34, 33, 32, - /* 460 */ 1726, 479, 65, 1206, 1845, 64, 593, 155, 540, 980, - /* 470 */ 147, 979, 1585, 1680, 1231, 539, 37, 35, 1843, 308, - /* 480 */ 1214, 1461, 1842, 1572, 318, 1793, 1208, 1423, 1583, 1214, - /* 490 */ 38, 36, 34, 33, 32, 1422, 449, 9, 981, 1234, - /* 500 */ 1739, 1395, 1845, 87, 1711, 542, 1713, 1714, 538, 1789, - /* 510 */ 559, 1206, 1311, 1779, 199, 134, 152, 1778, 1775, 637, - /* 520 */ 1842, 543, 133, 1585, 1536, 1246, 1342, 1680, 1214, 321, - /* 530 */ 323, 1630, 1232, 1277, 1278, 1680, 293, 609, 607, 1583, - /* 540 */ 1421, 615, 614, 613, 333, 9, 612, 611, 610, 119, - /* 550 */ 605, 604, 603, 602, 601, 600, 599, 598, 127, 594, - /* 560 */ 1246, 1402, 38, 36, 34, 33, 32, 637, 1297, 505, - /* 570 */ 69, 291, 1285, 967, 968, 1209, 1420, 1207, 1232, 1419, - /* 580 */ 1680, 1277, 1278, 1394, 28, 108, 107, 106, 105, 104, - /* 590 */ 103, 102, 101, 100, 38, 36, 34, 33, 32, 1212, - /* 600 */ 1213, 1510, 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, - /* 610 */ 557, 1274, 1275, 1276, 1279, 556, 1680, 1585, 1585, 1680, - /* 620 */ 1298, 331, 585, 1209, 329, 1207, 370, 231, 1518, 134, - /* 630 */ 34, 33, 32, 1583, 1584, 1418, 37, 35, 1535, 511, - /* 640 */ 506, 200, 1303, 1533, 318, 591, 1208, 1212, 1213, 1417, - /* 650 */ 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, 557, 1274, - /* 660 */ 1275, 1276, 1279, 556, 125, 124, 588, 587, 586, 411, - /* 670 */ 419, 1206, 415, 415, 372, 1680, 556, 29, 316, 1292, - /* 680 */ 1293, 1294, 1295, 1296, 1300, 1301, 1302, 387, 1214, 1680, - /* 690 */ 185, 1533, 556, 263, 591, 597, 1563, 1505, 1416, 1261, - /* 700 */ 1190, 1191, 140, 388, 1533, 2, 1413, 556, 447, 443, - /* 710 */ 439, 435, 184, 125, 124, 588, 587, 586, 429, 1793, - /* 720 */ 1533, 1698, 1710, 1334, 289, 1232, 1230, 637, 1412, 1700, - /* 730 */ 1411, 455, 1694, 395, 7, 1533, 407, 68, 1680, 556, - /* 740 */ 182, 1277, 1278, 1788, 556, 1261, 1680, 1410, 1409, 1726, - /* 750 */ 1530, 380, 1235, 454, 408, 1657, 382, 540, 1690, 1696, - /* 760 */ 135, 524, 1680, 556, 539, 269, 1702, 1533, 1680, 559, - /* 770 */ 1680, 1621, 1533, 556, 487, 496, 589, 267, 55, 1576, - /* 780 */ 527, 54, 164, 1209, 553, 1207, 373, 1680, 1680, 1739, - /* 790 */ 596, 1533, 287, 1711, 542, 1713, 1714, 538, 167, 559, - /* 800 */ 181, 1533, 173, 1464, 178, 1520, 425, 1212, 1213, 1408, - /* 810 */ 1259, 1260, 1262, 1263, 1264, 1265, 1266, 535, 557, 1274, - /* 820 */ 1275, 1276, 1279, 58, 590, 171, 406, 1576, 1516, 401, - /* 830 */ 400, 399, 398, 397, 394, 393, 392, 391, 390, 386, - /* 840 */ 385, 384, 383, 377, 376, 375, 374, 203, 1032, 1680, - /* 850 */ 38, 36, 34, 33, 32, 556, 556, 1208, 556, 516, - /* 860 */ 1407, 84, 1406, 465, 464, 1034, 554, 253, 463, 332, - /* 870 */ 1405, 114, 460, 1798, 1330, 459, 458, 457, 608, 1451, - /* 880 */ 212, 534, 1206, 1533, 1533, 190, 1533, 117, 188, 486, - /* 890 */ 1710, 1508, 1261, 62, 61, 368, 293, 1217, 161, 1214, - /* 900 */ 1680, 466, 1680, 192, 362, 516, 191, 1330, 194, 196, - /* 910 */ 1680, 193, 195, 1446, 1444, 288, 584, 1726, 352, 359, - /* 920 */ 350, 346, 342, 158, 337, 519, 115, 477, 1297, 1415, - /* 930 */ 1680, 1333, 539, 117, 1216, 468, 471, 123, 637, 1004, - /* 940 */ 475, 150, 1786, 1787, 532, 1791, 235, 11, 10, 48, - /* 950 */ 525, 216, 1491, 155, 448, 503, 1005, 1739, 1710, 480, - /* 960 */ 86, 1711, 542, 1713, 1714, 538, 1440, 559, 1397, 1398, - /* 970 */ 1779, 528, 115, 39, 311, 1775, 148, 223, 491, 39, - /* 980 */ 1298, 1727, 1710, 334, 591, 1726, 39, 151, 1786, 1787, - /* 990 */ 1356, 1791, 218, 540, 1209, 242, 1207, 1807, 1680, 1435, - /* 1000 */ 539, 1573, 1303, 125, 124, 588, 587, 586, 1809, 1726, - /* 1010 */ 121, 1220, 633, 517, 1305, 234, 237, 540, 1212, 1213, - /* 1020 */ 1267, 239, 1680, 1710, 539, 1739, 3, 1163, 272, 1711, - /* 1030 */ 542, 1713, 1714, 538, 122, 559, 244, 29, 316, 1292, - /* 1040 */ 1293, 1294, 1295, 1296, 1300, 1301, 1302, 123, 1219, 1739, - /* 1050 */ 1726, 548, 86, 1711, 542, 1713, 1714, 538, 540, 559, - /* 1060 */ 48, 564, 1779, 1680, 1710, 539, 311, 1775, 1858, 1289, - /* 1070 */ 122, 123, 110, 122, 5, 250, 336, 1813, 1230, 339, - /* 1080 */ 343, 298, 1174, 1032, 299, 259, 389, 163, 1063, 396, - /* 1090 */ 1739, 1726, 1623, 86, 1711, 542, 1713, 1714, 538, 540, - /* 1100 */ 559, 262, 1091, 1779, 1680, 404, 539, 311, 1775, 1858, - /* 1110 */ 403, 1095, 1102, 1100, 126, 405, 409, 1236, 1836, 410, - /* 1120 */ 418, 1239, 421, 170, 172, 1238, 422, 423, 1240, 426, - /* 1130 */ 424, 1739, 175, 177, 86, 1711, 542, 1713, 1714, 538, - /* 1140 */ 1710, 559, 427, 1237, 1779, 428, 180, 450, 311, 1775, - /* 1150 */ 1858, 431, 452, 66, 183, 1523, 187, 1519, 481, 1797, - /* 1160 */ 189, 128, 307, 89, 260, 129, 1521, 1726, 482, 485, - /* 1170 */ 201, 204, 488, 1517, 130, 540, 131, 490, 207, 1235, - /* 1180 */ 1680, 210, 539, 1810, 504, 546, 6, 492, 1662, 1820, - /* 1190 */ 1661, 1819, 513, 1800, 222, 520, 142, 499, 500, 224, - /* 1200 */ 498, 225, 493, 1710, 501, 1330, 310, 1739, 497, 226, - /* 1210 */ 278, 1711, 542, 1713, 1714, 538, 507, 559, 214, 217, - /* 1220 */ 1710, 116, 1234, 42, 1841, 18, 526, 529, 227, 523, - /* 1230 */ 1726, 233, 312, 1861, 544, 545, 1845, 320, 540, 1794, - /* 1240 */ 1629, 549, 246, 1680, 1628, 539, 551, 1726, 261, 550, - /* 1250 */ 154, 77, 1534, 248, 1842, 540, 75, 562, 520, 264, - /* 1260 */ 1680, 228, 539, 1760, 1577, 1506, 256, 49, 636, 266, - /* 1270 */ 1739, 270, 1674, 278, 1711, 542, 1713, 1714, 538, 279, - /* 1280 */ 559, 271, 268, 1710, 141, 236, 1673, 1739, 530, 60, - /* 1290 */ 87, 1711, 542, 1713, 1714, 538, 238, 559, 1672, 1845, - /* 1300 */ 1779, 1710, 338, 1669, 531, 1775, 340, 341, 1201, 1202, - /* 1310 */ 1726, 159, 345, 152, 1667, 347, 348, 1842, 537, 349, - /* 1320 */ 1666, 1665, 351, 1680, 353, 539, 1664, 355, 1726, 1663, - /* 1330 */ 357, 1647, 160, 360, 361, 1177, 540, 1176, 1641, 1640, - /* 1340 */ 366, 1680, 367, 539, 1639, 1638, 1149, 1616, 63, 1615, - /* 1350 */ 1739, 378, 1710, 286, 1711, 542, 1713, 1714, 538, 536, - /* 1360 */ 559, 533, 1751, 1614, 1613, 1612, 1611, 1610, 1739, 379, - /* 1370 */ 640, 138, 1711, 542, 1713, 1714, 538, 381, 559, 1726, - /* 1380 */ 1609, 1608, 1607, 1606, 258, 1605, 1604, 540, 1603, 1602, - /* 1390 */ 1601, 1600, 1680, 516, 539, 1599, 145, 1598, 1597, 1596, - /* 1400 */ 120, 1595, 631, 627, 623, 619, 257, 1594, 1593, 1592, - /* 1410 */ 1591, 1590, 1589, 1710, 1151, 1588, 521, 1859, 1587, 1739, - /* 1420 */ 1586, 117, 87, 1711, 542, 1713, 1714, 538, 1463, 559, - /* 1430 */ 1431, 83, 1779, 168, 251, 146, 970, 1776, 969, 111, - /* 1440 */ 1726, 520, 1430, 169, 414, 1655, 1649, 416, 540, 1637, - /* 1450 */ 112, 174, 1636, 1680, 176, 539, 1626, 1512, 179, 1462, - /* 1460 */ 115, 1460, 434, 998, 433, 1458, 1710, 552, 438, 1456, - /* 1470 */ 432, 1454, 437, 436, 441, 229, 1786, 515, 442, 514, - /* 1480 */ 1739, 440, 1845, 282, 1711, 542, 1713, 1714, 538, 1710, - /* 1490 */ 559, 444, 445, 1726, 1443, 494, 154, 446, 208, 1442, - /* 1500 */ 1842, 540, 1429, 1514, 186, 1106, 1680, 516, 539, 1105, - /* 1510 */ 1513, 1031, 1452, 1030, 1029, 1028, 1726, 1182, 606, 202, - /* 1520 */ 608, 1025, 512, 47, 540, 1024, 304, 1023, 1447, 1680, - /* 1530 */ 305, 539, 469, 1739, 1445, 117, 138, 1711, 542, 1713, - /* 1540 */ 1714, 538, 315, 559, 306, 1710, 1428, 472, 474, 1427, - /* 1550 */ 88, 476, 1654, 1184, 51, 520, 1739, 1648, 483, 287, - /* 1560 */ 1711, 542, 1713, 1714, 538, 1635, 559, 1634, 1633, 1625, - /* 1570 */ 71, 15, 1726, 4, 115, 209, 39, 1371, 23, 213, - /* 1580 */ 537, 205, 1860, 484, 45, 1680, 211, 539, 50, 229, - /* 1590 */ 1786, 515, 139, 514, 220, 215, 1845, 132, 1710, 1355, - /* 1600 */ 219, 24, 221, 1348, 1700, 72, 230, 1710, 143, 1327, - /* 1610 */ 152, 25, 1739, 1326, 1842, 286, 1711, 542, 1713, 1714, - /* 1620 */ 538, 1710, 559, 44, 1752, 1726, 1388, 17, 1383, 1377, - /* 1630 */ 10, 1382, 313, 540, 1726, 1387, 1386, 314, 1680, 19, - /* 1640 */ 539, 1269, 540, 1268, 31, 1290, 144, 1680, 1726, 539, - /* 1650 */ 156, 317, 16, 12, 13, 20, 540, 43, 1254, 21, - /* 1660 */ 319, 1680, 1710, 539, 1624, 1739, 541, 247, 287, 1711, - /* 1670 */ 542, 1713, 1714, 538, 1739, 559, 241, 287, 1711, 542, - /* 1680 */ 1713, 1714, 538, 1710, 559, 1353, 243, 547, 1739, 1726, - /* 1690 */ 245, 273, 1711, 542, 1713, 1714, 538, 540, 559, 73, - /* 1700 */ 74, 78, 1680, 1699, 539, 252, 1742, 1224, 1271, 249, - /* 1710 */ 1726, 1092, 558, 46, 561, 563, 327, 1089, 540, 565, - /* 1720 */ 567, 568, 570, 1680, 1086, 539, 571, 573, 1080, 1739, - /* 1730 */ 574, 576, 274, 1711, 542, 1713, 1714, 538, 1078, 559, - /* 1740 */ 1069, 1710, 1084, 583, 577, 1101, 1083, 79, 1082, 1081, - /* 1750 */ 1739, 80, 1710, 281, 1711, 542, 1713, 1714, 538, 57, - /* 1760 */ 559, 254, 1097, 1710, 996, 592, 1020, 595, 1726, 255, - /* 1770 */ 1038, 1013, 1018, 1017, 1016, 1035, 540, 1015, 1014, 1726, - /* 1780 */ 1012, 1680, 1011, 539, 1033, 1008, 1007, 540, 1006, 1003, - /* 1790 */ 1726, 1002, 1680, 1001, 539, 1459, 617, 616, 540, 618, - /* 1800 */ 1457, 620, 621, 1680, 622, 539, 1455, 624, 1739, 625, - /* 1810 */ 626, 283, 1711, 542, 1713, 1714, 538, 1453, 559, 1739, - /* 1820 */ 629, 628, 275, 1711, 542, 1713, 1714, 538, 1710, 559, - /* 1830 */ 1739, 630, 1441, 284, 1711, 542, 1713, 1714, 538, 632, - /* 1840 */ 559, 1426, 634, 635, 1710, 1210, 265, 638, 639, 1401, - /* 1850 */ 1401, 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, 1401, - /* 1860 */ 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, 1401, - /* 1870 */ 539, 1726, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 540, - /* 1880 */ 1401, 1401, 1401, 1401, 1680, 1401, 539, 1401, 1401, 1401, - /* 1890 */ 1401, 1401, 1401, 1710, 1401, 1739, 1401, 1401, 276, 1711, - /* 1900 */ 542, 1713, 1714, 538, 1401, 559, 1401, 1710, 1401, 1401, - /* 1910 */ 1401, 1739, 1401, 1401, 285, 1711, 542, 1713, 1714, 538, - /* 1920 */ 1726, 559, 1401, 1401, 1401, 1401, 1401, 1401, 540, 1401, - /* 1930 */ 1401, 1401, 1401, 1680, 1726, 539, 1401, 1401, 1401, 1401, - /* 1940 */ 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, 1710, 539, - /* 1950 */ 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, - /* 1960 */ 1739, 1401, 1401, 277, 1711, 542, 1713, 1714, 538, 1710, - /* 1970 */ 559, 1401, 1401, 1401, 1739, 1726, 1401, 1722, 1711, 542, - /* 1980 */ 1713, 1714, 538, 540, 559, 1401, 1401, 1401, 1680, 1401, - /* 1990 */ 539, 1401, 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, - /* 2000 */ 1401, 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, - /* 2010 */ 1401, 539, 1401, 1401, 1401, 1739, 1401, 1401, 1721, 1711, - /* 2020 */ 542, 1713, 1714, 538, 1401, 559, 1401, 1710, 1401, 1401, - /* 2030 */ 1401, 1401, 1401, 1401, 1401, 1401, 1739, 1401, 1710, 1720, - /* 2040 */ 1711, 542, 1713, 1714, 538, 1401, 559, 1401, 1401, 1710, - /* 2050 */ 1401, 1401, 1401, 1401, 1726, 1401, 1401, 1401, 1401, 1401, - /* 2060 */ 1401, 1401, 540, 1401, 1401, 1726, 1401, 1680, 1401, 539, - /* 2070 */ 1401, 1401, 1401, 540, 1401, 1401, 1726, 1401, 1680, 1401, - /* 2080 */ 539, 1401, 1401, 1401, 540, 1401, 1401, 1401, 1401, 1680, - /* 2090 */ 1710, 539, 1401, 1401, 1739, 1401, 1401, 296, 1711, 542, - /* 2100 */ 1713, 1714, 538, 1401, 559, 1739, 1401, 1401, 295, 1711, - /* 2110 */ 542, 1713, 1714, 538, 1710, 559, 1739, 1726, 1401, 297, - /* 2120 */ 1711, 542, 1713, 1714, 538, 540, 559, 1401, 1401, 1401, - /* 2130 */ 1680, 1401, 539, 1401, 1401, 1401, 1401, 1401, 1401, 1401, - /* 2140 */ 1401, 1726, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 540, - /* 2150 */ 1401, 1401, 1401, 1401, 1680, 1401, 539, 1739, 1401, 1401, - /* 2160 */ 294, 1711, 542, 1713, 1714, 538, 1401, 559, 1401, 1401, - /* 2170 */ 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, 1401, - /* 2180 */ 1401, 1739, 1401, 1401, 280, 1711, 542, 1713, 1714, 538, - /* 2190 */ 1401, 559, + /* 0 */ 422, 1661, 423, 1462, 430, 1730, 423, 1462, 317, 1881, + /* 10 */ 141, 1425, 39, 37, 1518, 373, 1727, 69, 1552, 1550, + /* 20 */ 326, 1428, 1230, 1880, 379, 1730, 1367, 1878, 334, 1727, + /* 30 */ 115, 140, 1254, 1439, 1743, 1228, 1727, 338, 566, 1556, + /* 40 */ 1606, 1608, 101, 1723, 1729, 100, 99, 98, 97, 96, + /* 50 */ 95, 94, 93, 92, 570, 1881, 1723, 1729, 61, 14, + /* 60 */ 1309, 296, 1761, 1723, 1729, 1236, 1254, 570, 1761, 156, + /* 70 */ 550, 566, 343, 1878, 570, 1713, 519, 549, 39, 37, + /* 80 */ 1360, 427, 1, 504, 1255, 1230, 326, 1252, 1230, 33, + /* 90 */ 32, 439, 530, 40, 38, 36, 35, 34, 1228, 1743, + /* 100 */ 43, 1228, 151, 1774, 649, 520, 87, 1744, 552, 1746, + /* 110 */ 1747, 548, 1881, 570, 518, 1600, 1814, 69, 1301, 1302, + /* 120 */ 298, 1810, 60, 1881, 1255, 14, 156, 1761, 1236, 1881, + /* 130 */ 1878, 1236, 1881, 567, 567, 547, 60, 156, 526, 1557, + /* 140 */ 1713, 1878, 549, 157, 111, 161, 158, 1878, 2, 101, + /* 150 */ 1878, 460, 100, 99, 98, 97, 96, 95, 94, 93, + /* 160 */ 92, 1561, 1561, 1231, 1394, 1229, 119, 649, 1774, 604, + /* 170 */ 649, 287, 1744, 552, 1746, 1747, 548, 546, 570, 543, + /* 180 */ 1786, 1323, 1129, 1130, 1301, 1302, 1450, 1234, 1235, 534, + /* 190 */ 1283, 1284, 1286, 1287, 1288, 1289, 1290, 545, 568, 1298, + /* 200 */ 1299, 1300, 1303, 1285, 1328, 166, 117, 295, 1829, 1252, + /* 210 */ 40, 38, 36, 35, 34, 159, 405, 1427, 1236, 417, + /* 220 */ 528, 153, 1822, 1823, 567, 1827, 1231, 1713, 1229, 1231, + /* 230 */ 67, 1229, 1826, 66, 1384, 377, 390, 1285, 418, 27, + /* 240 */ 392, 110, 109, 108, 107, 106, 105, 104, 103, 102, + /* 250 */ 1234, 1235, 1561, 1234, 1235, 159, 1283, 1284, 1286, 1287, + /* 260 */ 1288, 1289, 1290, 545, 568, 1298, 1299, 1300, 1303, 159, + /* 270 */ 383, 512, 1382, 1383, 1385, 1386, 33, 32, 39, 37, + /* 280 */ 40, 38, 36, 35, 34, 1254, 326, 608, 1230, 1533, + /* 290 */ 1087, 593, 592, 591, 1091, 590, 1093, 1094, 589, 1096, + /* 300 */ 586, 1228, 1102, 583, 1104, 1105, 580, 577, 11, 10, + /* 310 */ 416, 22, 566, 411, 410, 409, 408, 407, 404, 403, + /* 320 */ 402, 401, 400, 396, 395, 394, 393, 387, 386, 385, + /* 330 */ 384, 1236, 381, 380, 39, 37, 1743, 1253, 310, 30, + /* 340 */ 240, 997, 326, 996, 1230, 33, 32, 209, 8, 40, + /* 350 */ 38, 36, 35, 34, 474, 473, 458, 1228, 1731, 472, + /* 360 */ 980, 1256, 116, 469, 1761, 567, 468, 467, 466, 1727, + /* 370 */ 649, 998, 550, 60, 42, 73, 111, 1713, 596, 549, + /* 380 */ 535, 14, 497, 465, 1301, 1302, 311, 1236, 309, 308, + /* 390 */ 1335, 462, 412, 1561, 530, 464, 1723, 1729, 515, 479, + /* 400 */ 984, 985, 1881, 1449, 2, 1774, 1440, 570, 87, 1744, + /* 410 */ 552, 1746, 1747, 548, 489, 570, 1879, 463, 1814, 567, + /* 420 */ 1878, 567, 298, 1810, 84, 553, 649, 1492, 201, 1231, + /* 430 */ 378, 1229, 382, 329, 1881, 607, 1658, 120, 170, 169, + /* 440 */ 1301, 1302, 482, 1448, 1713, 1553, 476, 1561, 156, 1561, + /* 450 */ 490, 200, 1878, 1234, 1235, 1546, 1283, 1284, 1286, 1287, + /* 460 */ 1288, 1289, 1290, 545, 568, 1298, 1299, 1300, 1303, 330, + /* 470 */ 521, 516, 39, 37, 1304, 421, 55, 138, 425, 54, + /* 480 */ 326, 159, 1230, 567, 1713, 1231, 1563, 1229, 474, 473, + /* 490 */ 1881, 231, 1420, 472, 397, 1228, 116, 469, 526, 1519, + /* 500 */ 468, 467, 466, 526, 156, 58, 159, 159, 1878, 1234, + /* 510 */ 1235, 1561, 1283, 1284, 1286, 1287, 1288, 1289, 1290, 545, + /* 520 */ 568, 1298, 1299, 1300, 1303, 1236, 119, 39, 37, 1607, + /* 530 */ 1608, 119, 567, 364, 1257, 326, 1447, 1230, 984, 985, + /* 540 */ 33, 32, 9, 398, 40, 38, 36, 35, 34, 202, + /* 550 */ 1228, 33, 32, 366, 362, 40, 38, 36, 35, 34, + /* 560 */ 1561, 567, 429, 1743, 649, 425, 117, 336, 997, 1446, + /* 570 */ 996, 117, 438, 1657, 1419, 138, 305, 1713, 1301, 1302, + /* 580 */ 1236, 154, 1822, 1823, 1563, 1827, 155, 1822, 1823, 1561, + /* 590 */ 1827, 1761, 602, 39, 37, 235, 567, 9, 998, 550, + /* 600 */ 1445, 326, 1444, 1230, 1713, 464, 549, 1558, 71, 304, + /* 610 */ 1713, 129, 128, 599, 598, 597, 1228, 567, 506, 649, + /* 620 */ 471, 470, 1479, 1231, 1561, 1229, 1374, 463, 1690, 36, + /* 630 */ 35, 34, 1774, 1301, 1302, 288, 1744, 552, 1746, 1747, + /* 640 */ 548, 1713, 570, 1713, 475, 1561, 1236, 1234, 1235, 1049, + /* 650 */ 1283, 1284, 1286, 1287, 1288, 1289, 1290, 545, 568, 1298, + /* 660 */ 1299, 1300, 1303, 2, 212, 567, 567, 33, 32, 1254, + /* 670 */ 567, 40, 38, 36, 35, 34, 498, 502, 1231, 1051, + /* 680 */ 1229, 564, 33, 32, 1651, 649, 40, 38, 36, 35, + /* 690 */ 34, 620, 618, 1561, 1561, 168, 1834, 1355, 1561, 1301, + /* 700 */ 1302, 1538, 1234, 1235, 1548, 1283, 1284, 1286, 1287, 1288, + /* 710 */ 1289, 1290, 545, 568, 1298, 1299, 1300, 1303, 299, 60, + /* 720 */ 567, 33, 32, 652, 339, 40, 38, 36, 35, 34, + /* 730 */ 1544, 565, 138, 299, 532, 205, 1613, 262, 567, 1539, + /* 740 */ 488, 1563, 1268, 331, 1231, 1443, 1229, 1613, 1561, 256, + /* 750 */ 1321, 149, 1611, 486, 337, 484, 642, 638, 634, 630, + /* 760 */ 260, 244, 1743, 1611, 1537, 1321, 1561, 1442, 1234, 1235, + /* 770 */ 1441, 1283, 1284, 1286, 1287, 1288, 1289, 1290, 545, 568, + /* 780 */ 1298, 1299, 1300, 1303, 138, 85, 1713, 139, 254, 553, + /* 790 */ 1761, 1438, 273, 1564, 1359, 602, 1268, 439, 550, 372, + /* 800 */ 1659, 371, 567, 1713, 1322, 549, 271, 57, 1713, 1829, + /* 810 */ 56, 1713, 544, 340, 129, 128, 599, 598, 597, 1322, + /* 820 */ 1437, 563, 604, 1212, 1213, 1656, 171, 1327, 305, 1613, + /* 830 */ 1561, 1774, 1713, 1825, 88, 1744, 552, 1746, 1747, 548, + /* 840 */ 1285, 570, 1327, 1489, 1814, 1612, 1436, 1435, 319, 1810, + /* 850 */ 1894, 60, 159, 211, 78, 1701, 7, 595, 1434, 1849, + /* 860 */ 1433, 1713, 29, 324, 1316, 1317, 1318, 1319, 1320, 1324, + /* 870 */ 1325, 1326, 245, 246, 1204, 1554, 204, 29, 324, 1316, + /* 880 */ 1317, 1318, 1319, 1320, 1324, 1325, 1326, 1713, 1713, 86, + /* 890 */ 33, 32, 513, 1432, 40, 38, 36, 35, 34, 1713, + /* 900 */ 1743, 1713, 352, 1431, 626, 625, 624, 341, 1829, 623, + /* 910 */ 622, 621, 121, 616, 615, 614, 613, 612, 611, 610, + /* 920 */ 609, 131, 605, 619, 64, 63, 376, 1430, 1761, 165, + /* 930 */ 208, 542, 1824, 304, 1713, 370, 529, 333, 332, 600, + /* 940 */ 537, 1713, 1604, 549, 1713, 601, 294, 1244, 1604, 360, + /* 950 */ 1239, 358, 354, 350, 162, 345, 267, 457, 72, 1591, + /* 960 */ 1237, 1743, 193, 367, 195, 191, 223, 194, 1713, 1774, + /* 970 */ 1536, 1474, 88, 1744, 552, 1746, 1747, 548, 197, 570, + /* 980 */ 199, 196, 1814, 198, 159, 1472, 319, 1810, 152, 1761, + /* 990 */ 1236, 52, 501, 477, 11, 10, 1238, 529, 491, 50, + /* 1000 */ 232, 1762, 1713, 83, 549, 26, 1358, 480, 505, 1842, + /* 1010 */ 1733, 33, 32, 80, 28, 40, 38, 36, 35, 34, + /* 1020 */ 33, 32, 1743, 342, 40, 38, 36, 35, 34, 571, + /* 1030 */ 1774, 1355, 137, 88, 1744, 552, 1746, 1747, 548, 1381, + /* 1040 */ 570, 1422, 1423, 1814, 1463, 1601, 1735, 319, 1810, 152, + /* 1050 */ 1761, 1845, 216, 41, 527, 234, 237, 239, 550, 1313, + /* 1060 */ 41, 5, 41, 1713, 602, 549, 242, 344, 3, 1252, + /* 1070 */ 1843, 123, 347, 351, 126, 127, 50, 1743, 306, 1049, + /* 1080 */ 1242, 575, 126, 129, 128, 599, 598, 597, 1245, 1468, + /* 1090 */ 1240, 1774, 218, 1329, 88, 1744, 552, 1746, 1747, 548, + /* 1100 */ 1291, 570, 1180, 127, 1814, 1761, 247, 112, 319, 1810, + /* 1110 */ 1894, 559, 1248, 550, 253, 1080, 266, 307, 1713, 1872, + /* 1120 */ 549, 1108, 1112, 568, 1298, 1299, 1241, 1196, 126, 263, + /* 1130 */ 1743, 1021, 399, 538, 1653, 167, 406, 644, 1258, 1743, + /* 1140 */ 414, 413, 415, 1119, 419, 1261, 1774, 1117, 431, 88, + /* 1150 */ 1744, 552, 1746, 1747, 548, 420, 570, 1743, 1761, 1814, + /* 1160 */ 428, 1022, 174, 319, 1810, 1894, 550, 1761, 130, 1260, + /* 1170 */ 433, 1713, 176, 549, 1833, 550, 432, 1262, 434, 179, + /* 1180 */ 1713, 181, 549, 1259, 437, 1761, 459, 183, 530, 436, + /* 1190 */ 68, 440, 186, 550, 461, 91, 1551, 530, 1713, 1774, + /* 1200 */ 549, 190, 280, 1744, 552, 1746, 1747, 548, 1774, 570, + /* 1210 */ 1547, 280, 1744, 552, 1746, 1747, 548, 192, 570, 132, + /* 1220 */ 133, 1549, 1743, 1545, 134, 135, 1774, 297, 1881, 89, + /* 1230 */ 1744, 552, 1746, 1747, 548, 1695, 570, 1881, 1743, 1814, + /* 1240 */ 264, 203, 158, 1813, 1810, 492, 1878, 1743, 493, 496, + /* 1250 */ 1761, 156, 1257, 206, 499, 1878, 503, 316, 550, 210, + /* 1260 */ 514, 1846, 509, 1713, 556, 549, 1761, 1856, 214, 511, + /* 1270 */ 217, 318, 6, 517, 550, 1761, 523, 510, 1836, 1713, + /* 1280 */ 224, 549, 508, 550, 507, 1855, 1355, 118, 1713, 226, + /* 1290 */ 549, 1774, 222, 227, 89, 1744, 552, 1746, 1747, 548, + /* 1300 */ 1743, 570, 146, 225, 1814, 1256, 1830, 1774, 541, 1810, + /* 1310 */ 142, 1744, 552, 1746, 1747, 548, 1774, 570, 44, 89, + /* 1320 */ 1744, 552, 1746, 1747, 548, 539, 570, 1877, 1761, 1814, + /* 1330 */ 188, 536, 320, 18, 1811, 124, 550, 233, 236, 228, + /* 1340 */ 1795, 1713, 125, 549, 144, 554, 555, 1897, 533, 456, + /* 1350 */ 452, 448, 444, 187, 1743, 531, 1895, 1694, 1663, 557, + /* 1360 */ 540, 328, 560, 1743, 561, 249, 251, 238, 562, 1774, + /* 1370 */ 265, 77, 283, 1744, 552, 1746, 1747, 548, 70, 570, + /* 1380 */ 1562, 185, 1761, 79, 573, 268, 1534, 645, 259, 1605, + /* 1390 */ 550, 1761, 646, 648, 51, 1713, 145, 549, 289, 550, + /* 1400 */ 272, 291, 290, 270, 1713, 1707, 549, 1706, 62, 1705, + /* 1410 */ 346, 522, 348, 1743, 1702, 349, 1223, 1224, 323, 163, + /* 1420 */ 353, 1700, 355, 1774, 1743, 356, 142, 1744, 552, 1746, + /* 1430 */ 1747, 548, 1774, 570, 357, 288, 1744, 552, 1746, 1747, + /* 1440 */ 548, 1761, 570, 184, 177, 1699, 182, 359, 1698, 547, + /* 1450 */ 435, 361, 1761, 1697, 1713, 363, 549, 1696, 365, 1680, + /* 1460 */ 550, 164, 368, 369, 1199, 1713, 1198, 549, 1674, 175, + /* 1470 */ 1673, 374, 1896, 375, 1672, 1671, 1743, 1168, 1646, 325, + /* 1480 */ 1645, 1644, 1774, 65, 1643, 287, 1744, 552, 1746, 1747, + /* 1490 */ 548, 1642, 570, 1774, 1787, 1641, 288, 1744, 552, 1746, + /* 1500 */ 1747, 548, 1640, 570, 1761, 1639, 388, 389, 1638, 391, + /* 1510 */ 1637, 1636, 550, 1635, 1634, 1633, 1632, 1713, 1631, 549, + /* 1520 */ 1630, 1629, 1628, 1627, 1626, 1625, 1624, 122, 1623, 1743, + /* 1530 */ 1622, 327, 1621, 1620, 1619, 1618, 1617, 1616, 1743, 1170, + /* 1540 */ 1615, 1614, 1491, 1459, 150, 1774, 172, 1743, 288, 1744, + /* 1550 */ 552, 1746, 1747, 548, 1458, 570, 1688, 1761, 113, 987, + /* 1560 */ 986, 1682, 1670, 1669, 180, 550, 1761, 1655, 1540, 173, + /* 1570 */ 1713, 1490, 549, 424, 550, 1761, 1488, 426, 114, 1713, + /* 1580 */ 1486, 549, 1484, 550, 1482, 441, 178, 443, 1713, 1471, + /* 1590 */ 549, 442, 445, 1470, 447, 449, 1455, 1542, 1774, 1743, + /* 1600 */ 446, 274, 1744, 552, 1746, 1747, 548, 1774, 570, 451, + /* 1610 */ 275, 1744, 552, 1746, 1747, 548, 1774, 570, 453, 276, + /* 1620 */ 1744, 552, 1746, 1747, 548, 1015, 570, 1761, 450, 49, + /* 1630 */ 455, 1122, 454, 1123, 1541, 550, 1048, 1047, 1046, 1045, + /* 1640 */ 1713, 1743, 549, 617, 1480, 1042, 1041, 1040, 189, 619, + /* 1650 */ 312, 1475, 313, 1473, 478, 314, 481, 1454, 483, 1453, + /* 1660 */ 485, 1743, 1452, 487, 1687, 90, 1206, 1681, 1774, 1761, + /* 1670 */ 494, 282, 1744, 552, 1746, 1747, 548, 550, 570, 1668, + /* 1680 */ 1666, 136, 1713, 1743, 549, 1667, 1665, 1664, 15, 1761, + /* 1690 */ 4, 1408, 41, 47, 10, 23, 213, 550, 1396, 207, + /* 1700 */ 143, 53, 1713, 215, 549, 1380, 219, 221, 24, 220, + /* 1710 */ 1774, 1761, 1373, 284, 1744, 552, 1746, 1747, 548, 550, + /* 1720 */ 570, 500, 495, 315, 1713, 74, 549, 1733, 16, 1352, + /* 1730 */ 1774, 25, 46, 277, 1744, 552, 1746, 1747, 548, 1743, + /* 1740 */ 570, 1351, 230, 147, 17, 1407, 1413, 321, 1743, 1412, + /* 1750 */ 1411, 1402, 1774, 322, 19, 285, 1744, 552, 1746, 1747, + /* 1760 */ 548, 1314, 570, 148, 1276, 1293, 31, 1761, 160, 1662, + /* 1770 */ 1654, 250, 1732, 1292, 241, 550, 1761, 45, 1378, 551, + /* 1780 */ 1713, 12, 549, 558, 550, 13, 20, 21, 243, 1713, + /* 1790 */ 248, 549, 80, 255, 1246, 75, 572, 574, 1743, 1295, + /* 1800 */ 252, 76, 1777, 569, 1101, 48, 335, 1743, 1774, 578, + /* 1810 */ 1109, 278, 1744, 552, 1746, 1747, 548, 1774, 570, 576, + /* 1820 */ 286, 1744, 552, 1746, 1747, 548, 1761, 570, 1106, 1103, + /* 1830 */ 579, 581, 582, 584, 550, 1761, 587, 1097, 585, 1713, + /* 1840 */ 1095, 549, 588, 550, 1100, 1099, 1086, 1098, 1713, 594, + /* 1850 */ 549, 1118, 257, 1114, 1013, 81, 603, 1743, 82, 59, + /* 1860 */ 1037, 606, 258, 1035, 1055, 1034, 1743, 1774, 1033, 1032, + /* 1870 */ 279, 1744, 552, 1746, 1747, 548, 1774, 570, 1031, 292, + /* 1880 */ 1744, 552, 1746, 1747, 548, 1761, 570, 1030, 1029, 1028, + /* 1890 */ 1050, 1052, 1025, 550, 1761, 1024, 1023, 1020, 1713, 1019, + /* 1900 */ 549, 1018, 550, 1487, 627, 628, 629, 1713, 1485, 549, + /* 1910 */ 631, 633, 1483, 635, 1481, 632, 637, 636, 1743, 639, + /* 1920 */ 640, 641, 1469, 643, 977, 1451, 1774, 1743, 261, 293, + /* 1930 */ 1744, 552, 1746, 1747, 548, 1774, 570, 647, 1755, 1744, + /* 1940 */ 552, 1746, 1747, 548, 650, 570, 1761, 1426, 1232, 269, + /* 1950 */ 651, 1426, 1426, 1426, 550, 1761, 1426, 1426, 1426, 1713, + /* 1960 */ 1426, 549, 1426, 550, 1426, 1426, 1426, 1426, 1713, 1426, + /* 1970 */ 549, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, + /* 1980 */ 1743, 1426, 1426, 1426, 1426, 1426, 1426, 1774, 1426, 1743, + /* 1990 */ 1754, 1744, 552, 1746, 1747, 548, 1774, 570, 1743, 1753, + /* 2000 */ 1744, 552, 1746, 1747, 548, 1426, 570, 1743, 1761, 1426, + /* 2010 */ 526, 1426, 1426, 1426, 1426, 1426, 550, 1761, 1426, 1426, + /* 2020 */ 1426, 1713, 1426, 549, 1426, 550, 1761, 1426, 1426, 1426, + /* 2030 */ 1713, 1426, 549, 1426, 550, 1761, 1426, 1426, 119, 1713, + /* 2040 */ 1426, 549, 1426, 550, 1426, 1426, 1426, 1426, 1713, 1774, + /* 2050 */ 549, 1426, 302, 1744, 552, 1746, 1747, 548, 1774, 570, + /* 2060 */ 530, 301, 1744, 552, 1746, 1747, 548, 1774, 570, 1426, + /* 2070 */ 303, 1744, 552, 1746, 1747, 548, 1774, 570, 117, 300, + /* 2080 */ 1744, 552, 1746, 1747, 548, 1743, 570, 1426, 1426, 1426, + /* 2090 */ 1426, 1426, 1426, 229, 1822, 525, 1426, 524, 1426, 526, + /* 2100 */ 1881, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, + /* 2110 */ 1426, 1426, 1426, 1761, 158, 1426, 1426, 1426, 1878, 1426, + /* 2120 */ 1426, 550, 1426, 1426, 1426, 1426, 1713, 119, 549, 1426, + /* 2130 */ 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, + /* 2140 */ 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 530, + /* 2150 */ 1426, 1426, 1426, 1426, 1774, 1426, 1426, 281, 1744, 552, + /* 2160 */ 1746, 1747, 548, 1426, 570, 1426, 1426, 117, 1426, 1426, + /* 2170 */ 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, + /* 2180 */ 1426, 1426, 229, 1822, 525, 1426, 524, 1426, 1426, 1881, + /* 2190 */ 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, 1426, + /* 2200 */ 1426, 1426, 1426, 156, 1426, 1426, 1426, 1878, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 274, 341, 273, 277, 248, 274, 250, 251, 277, 242, - /* 10 */ 257, 285, 12, 13, 261, 355, 285, 245, 14, 359, - /* 20 */ 20, 252, 22, 252, 20, 12, 13, 14, 15, 16, - /* 30 */ 12, 13, 263, 248, 263, 250, 251, 311, 312, 270, - /* 40 */ 22, 270, 311, 312, 272, 326, 327, 47, 322, 280, - /* 50 */ 313, 280, 280, 322, 41, 252, 20, 285, 58, 287, - /* 60 */ 12, 13, 14, 264, 64, 47, 263, 300, 20, 245, - /* 70 */ 22, 272, 300, 300, 337, 12, 13, 14, 15, 16, - /* 80 */ 281, 81, 64, 280, 312, 256, 20, 315, 316, 317, - /* 90 */ 318, 319, 320, 81, 322, 47, 272, 325, 269, 254, - /* 100 */ 252, 329, 330, 103, 280, 252, 58, 278, 341, 285, - /* 110 */ 245, 287, 64, 341, 341, 287, 263, 117, 118, 4, - /* 120 */ 275, 103, 355, 4, 20, 297, 359, 355, 355, 81, - /* 130 */ 57, 359, 359, 280, 55, 254, 312, 289, 19, 315, - /* 140 */ 316, 317, 318, 319, 320, 82, 322, 81, 267, 325, - /* 150 */ 285, 103, 33, 329, 330, 331, 275, 42, 43, 159, - /* 160 */ 81, 161, 83, 264, 45, 117, 118, 343, 3, 50, - /* 170 */ 158, 272, 160, 20, 55, 351, 352, 159, 283, 161, - /* 180 */ 281, 286, 287, 183, 184, 81, 186, 187, 188, 189, - /* 190 */ 190, 191, 192, 193, 194, 195, 196, 197, 198, 80, - /* 200 */ 20, 183, 83, 286, 287, 2, 4, 159, 341, 161, - /* 210 */ 20, 211, 194, 195, 196, 12, 13, 14, 15, 16, - /* 220 */ 12, 13, 355, 211, 245, 245, 359, 75, 20, 256, - /* 230 */ 22, 183, 184, 35, 186, 187, 188, 189, 190, 191, - /* 240 */ 192, 193, 194, 195, 196, 197, 198, 252, 272, 60, - /* 250 */ 61, 278, 272, 300, 65, 47, 280, 68, 69, 0, - /* 260 */ 280, 72, 73, 74, 285, 285, 58, 287, 12, 13, - /* 270 */ 117, 118, 64, 121, 122, 280, 20, 211, 22, 142, - /* 280 */ 300, 0, 84, 81, 86, 87, 154, 89, 81, 81, - /* 290 */ 211, 93, 312, 317, 341, 315, 316, 317, 318, 319, - /* 300 */ 320, 164, 322, 47, 45, 325, 174, 175, 355, 329, - /* 310 */ 330, 103, 359, 115, 319, 12, 13, 14, 15, 16, - /* 320 */ 64, 341, 244, 274, 246, 117, 118, 0, 333, 334, - /* 330 */ 335, 336, 20, 338, 285, 355, 199, 81, 57, 359, - /* 340 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - /* 350 */ 104, 0, 106, 107, 108, 109, 110, 111, 81, 103, - /* 360 */ 311, 312, 12, 13, 14, 15, 16, 159, 91, 161, - /* 370 */ 183, 322, 21, 117, 118, 24, 25, 26, 27, 28, - /* 380 */ 29, 30, 31, 32, 57, 82, 12, 13, 14, 15, - /* 390 */ 16, 183, 184, 228, 186, 187, 188, 189, 190, 191, - /* 400 */ 192, 193, 194, 195, 196, 197, 198, 220, 221, 222, - /* 410 */ 223, 224, 20, 211, 22, 159, 21, 161, 211, 24, - /* 420 */ 25, 26, 27, 28, 29, 30, 31, 32, 12, 13, - /* 430 */ 14, 1, 2, 245, 258, 259, 20, 55, 22, 183, - /* 440 */ 184, 49, 186, 187, 188, 189, 190, 191, 192, 193, - /* 450 */ 194, 195, 196, 197, 198, 12, 13, 14, 15, 16, - /* 460 */ 272, 300, 80, 47, 341, 83, 57, 211, 280, 20, - /* 470 */ 271, 22, 272, 285, 20, 287, 12, 13, 355, 279, - /* 480 */ 64, 0, 359, 284, 20, 313, 22, 245, 288, 64, - /* 490 */ 12, 13, 14, 15, 16, 245, 47, 81, 49, 20, - /* 500 */ 312, 151, 341, 315, 316, 317, 318, 319, 320, 337, - /* 510 */ 322, 47, 82, 325, 113, 272, 355, 329, 330, 103, - /* 520 */ 359, 287, 148, 272, 281, 82, 14, 285, 64, 295, - /* 530 */ 279, 297, 20, 117, 118, 285, 58, 258, 259, 288, - /* 540 */ 245, 60, 61, 62, 63, 81, 65, 66, 67, 68, - /* 550 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, - /* 560 */ 82, 0, 12, 13, 14, 15, 16, 103, 90, 146, - /* 570 */ 169, 170, 14, 42, 43, 159, 245, 161, 20, 245, - /* 580 */ 285, 117, 118, 233, 2, 24, 25, 26, 27, 28, - /* 590 */ 29, 30, 31, 32, 12, 13, 14, 15, 16, 183, - /* 600 */ 184, 0, 186, 187, 188, 189, 190, 191, 192, 193, - /* 610 */ 194, 195, 196, 197, 198, 252, 285, 272, 272, 285, - /* 620 */ 142, 264, 92, 159, 279, 161, 263, 148, 273, 272, - /* 630 */ 14, 15, 16, 288, 288, 245, 12, 13, 281, 216, - /* 640 */ 217, 112, 164, 280, 20, 93, 22, 183, 184, 245, - /* 650 */ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - /* 660 */ 196, 197, 198, 252, 112, 113, 114, 115, 116, 249, - /* 670 */ 249, 47, 252, 252, 263, 285, 252, 199, 200, 201, - /* 680 */ 202, 203, 204, 205, 206, 207, 208, 263, 64, 285, - /* 690 */ 33, 280, 252, 265, 93, 260, 268, 262, 245, 187, - /* 700 */ 171, 172, 45, 263, 280, 81, 245, 252, 51, 52, - /* 710 */ 53, 54, 55, 112, 113, 114, 115, 116, 263, 313, - /* 720 */ 280, 274, 245, 4, 18, 20, 20, 103, 245, 44, - /* 730 */ 245, 93, 285, 27, 37, 280, 30, 80, 285, 252, - /* 740 */ 83, 117, 118, 337, 252, 187, 285, 245, 245, 272, - /* 750 */ 263, 45, 20, 115, 48, 263, 50, 280, 311, 312, - /* 760 */ 18, 41, 285, 252, 287, 23, 81, 280, 285, 322, - /* 770 */ 285, 280, 280, 252, 263, 298, 282, 35, 36, 285, - /* 780 */ 41, 39, 291, 159, 263, 161, 80, 285, 285, 312, - /* 790 */ 64, 280, 315, 316, 317, 318, 319, 320, 56, 322, - /* 800 */ 143, 280, 145, 0, 147, 273, 149, 183, 184, 245, - /* 810 */ 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - /* 820 */ 196, 197, 198, 81, 282, 168, 120, 285, 273, 123, - /* 830 */ 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, - /* 840 */ 134, 135, 136, 137, 138, 139, 140, 273, 47, 285, - /* 850 */ 12, 13, 14, 15, 16, 252, 252, 22, 252, 252, - /* 860 */ 245, 119, 245, 60, 61, 64, 263, 263, 65, 263, - /* 870 */ 245, 68, 69, 209, 210, 72, 73, 74, 41, 0, - /* 880 */ 148, 273, 47, 280, 280, 85, 280, 280, 88, 304, - /* 890 */ 245, 0, 187, 151, 152, 153, 58, 47, 156, 64, - /* 900 */ 285, 22, 285, 85, 162, 252, 88, 210, 85, 85, - /* 910 */ 285, 88, 88, 0, 0, 173, 273, 272, 176, 82, - /* 920 */ 178, 179, 180, 181, 182, 280, 319, 21, 90, 246, - /* 930 */ 285, 212, 287, 280, 47, 22, 22, 41, 103, 47, - /* 940 */ 34, 334, 335, 336, 58, 338, 362, 1, 2, 41, - /* 950 */ 230, 41, 261, 211, 253, 353, 64, 312, 245, 308, - /* 960 */ 315, 316, 317, 318, 319, 320, 0, 322, 117, 118, - /* 970 */ 325, 232, 319, 41, 329, 330, 331, 348, 82, 41, - /* 980 */ 142, 272, 245, 253, 93, 272, 41, 334, 335, 336, - /* 990 */ 82, 338, 82, 280, 159, 41, 161, 352, 285, 251, - /* 1000 */ 287, 284, 164, 112, 113, 114, 115, 116, 314, 272, - /* 1010 */ 41, 161, 46, 339, 82, 356, 356, 280, 183, 184, - /* 1020 */ 82, 356, 285, 245, 287, 312, 342, 82, 315, 316, - /* 1030 */ 317, 318, 319, 320, 41, 322, 82, 199, 200, 201, - /* 1040 */ 202, 203, 204, 205, 206, 207, 208, 41, 161, 312, - /* 1050 */ 272, 82, 315, 316, 317, 318, 319, 320, 280, 322, - /* 1060 */ 41, 41, 325, 285, 245, 287, 329, 330, 331, 183, - /* 1070 */ 41, 41, 41, 41, 213, 82, 310, 340, 20, 252, - /* 1080 */ 45, 309, 157, 47, 258, 302, 252, 40, 82, 292, - /* 1090 */ 312, 272, 252, 315, 316, 317, 318, 319, 320, 280, - /* 1100 */ 322, 82, 82, 325, 285, 142, 287, 329, 330, 331, - /* 1110 */ 290, 82, 82, 82, 82, 290, 252, 20, 340, 247, - /* 1120 */ 247, 20, 306, 256, 256, 20, 287, 299, 20, 299, - /* 1130 */ 301, 312, 256, 256, 315, 316, 317, 318, 319, 320, - /* 1140 */ 245, 322, 280, 20, 325, 293, 256, 247, 329, 330, - /* 1150 */ 331, 252, 272, 256, 256, 272, 272, 272, 167, 340, - /* 1160 */ 272, 272, 247, 252, 306, 272, 272, 272, 305, 287, - /* 1170 */ 254, 254, 252, 272, 272, 280, 272, 299, 254, 20, - /* 1180 */ 285, 254, 287, 314, 219, 218, 225, 280, 285, 347, - /* 1190 */ 285, 347, 150, 350, 349, 300, 347, 285, 227, 346, - /* 1200 */ 226, 345, 293, 245, 285, 210, 285, 312, 214, 344, - /* 1210 */ 315, 316, 317, 318, 319, 320, 285, 322, 296, 296, - /* 1220 */ 245, 280, 20, 40, 358, 81, 229, 231, 310, 358, - /* 1230 */ 272, 357, 234, 363, 285, 285, 341, 285, 280, 313, - /* 1240 */ 296, 145, 280, 285, 296, 287, 293, 272, 268, 294, - /* 1250 */ 355, 81, 280, 254, 359, 280, 254, 276, 300, 252, - /* 1260 */ 285, 332, 287, 328, 285, 262, 254, 303, 247, 255, - /* 1270 */ 312, 266, 0, 315, 316, 317, 318, 319, 320, 266, - /* 1280 */ 322, 266, 243, 245, 307, 357, 0, 312, 358, 40, - /* 1290 */ 315, 316, 317, 318, 319, 320, 357, 322, 0, 341, - /* 1300 */ 325, 245, 72, 0, 329, 330, 47, 177, 47, 47, - /* 1310 */ 272, 47, 177, 355, 0, 47, 47, 359, 280, 177, - /* 1320 */ 0, 0, 177, 285, 47, 287, 0, 22, 272, 0, - /* 1330 */ 47, 0, 81, 164, 163, 161, 280, 159, 0, 0, - /* 1340 */ 155, 285, 154, 287, 0, 0, 44, 0, 141, 0, - /* 1350 */ 312, 136, 245, 315, 316, 317, 318, 319, 320, 321, - /* 1360 */ 322, 323, 324, 0, 0, 0, 0, 0, 312, 47, - /* 1370 */ 19, 315, 316, 317, 318, 319, 320, 136, 322, 272, - /* 1380 */ 0, 0, 0, 0, 33, 0, 0, 280, 0, 0, - /* 1390 */ 0, 0, 285, 252, 287, 0, 45, 0, 0, 0, - /* 1400 */ 40, 0, 51, 52, 53, 54, 55, 0, 0, 0, - /* 1410 */ 0, 0, 0, 245, 22, 0, 360, 361, 0, 312, - /* 1420 */ 0, 280, 315, 316, 317, 318, 319, 320, 0, 322, - /* 1430 */ 0, 80, 325, 40, 83, 41, 14, 330, 14, 37, - /* 1440 */ 272, 300, 0, 38, 44, 0, 0, 44, 280, 0, - /* 1450 */ 37, 37, 0, 285, 150, 287, 0, 0, 37, 0, - /* 1460 */ 319, 0, 37, 59, 45, 0, 245, 116, 37, 0, - /* 1470 */ 47, 0, 45, 47, 45, 334, 335, 336, 37, 338, - /* 1480 */ 312, 47, 341, 315, 316, 317, 318, 319, 320, 245, - /* 1490 */ 322, 47, 45, 272, 0, 144, 355, 37, 147, 0, - /* 1500 */ 359, 280, 0, 0, 88, 47, 285, 252, 287, 22, - /* 1510 */ 0, 47, 0, 47, 47, 47, 272, 166, 41, 168, - /* 1520 */ 41, 47, 354, 90, 280, 47, 22, 47, 0, 285, - /* 1530 */ 22, 287, 48, 312, 0, 280, 315, 316, 317, 318, - /* 1540 */ 319, 320, 298, 322, 22, 245, 0, 47, 22, 0, - /* 1550 */ 20, 22, 0, 47, 148, 300, 312, 0, 22, 315, - /* 1560 */ 316, 317, 318, 319, 320, 0, 322, 0, 0, 0, - /* 1570 */ 81, 215, 272, 41, 319, 37, 41, 82, 81, 81, - /* 1580 */ 280, 145, 361, 148, 41, 285, 143, 287, 148, 334, - /* 1590 */ 335, 336, 81, 338, 41, 82, 341, 165, 245, 82, - /* 1600 */ 81, 81, 44, 82, 44, 81, 44, 245, 44, 82, - /* 1610 */ 355, 41, 312, 82, 359, 315, 316, 317, 318, 319, - /* 1620 */ 320, 245, 322, 41, 324, 272, 82, 41, 47, 82, - /* 1630 */ 2, 47, 47, 280, 272, 47, 47, 47, 285, 41, - /* 1640 */ 287, 82, 280, 82, 81, 183, 44, 285, 272, 287, - /* 1650 */ 44, 298, 215, 81, 215, 81, 280, 209, 22, 81, - /* 1660 */ 298, 285, 245, 287, 0, 312, 185, 37, 315, 316, - /* 1670 */ 317, 318, 319, 320, 312, 322, 82, 315, 316, 317, - /* 1680 */ 318, 319, 320, 245, 322, 82, 81, 146, 312, 272, - /* 1690 */ 81, 315, 316, 317, 318, 319, 320, 280, 322, 81, - /* 1700 */ 81, 91, 285, 44, 287, 44, 81, 22, 82, 143, - /* 1710 */ 272, 82, 81, 81, 92, 47, 47, 82, 280, 81, - /* 1720 */ 47, 81, 47, 285, 82, 287, 81, 47, 82, 312, - /* 1730 */ 81, 47, 315, 316, 317, 318, 319, 320, 82, 322, - /* 1740 */ 22, 245, 105, 93, 81, 47, 105, 81, 105, 105, - /* 1750 */ 312, 81, 245, 315, 316, 317, 318, 319, 320, 81, - /* 1760 */ 322, 41, 22, 245, 59, 58, 47, 79, 272, 41, - /* 1770 */ 64, 22, 47, 47, 47, 64, 280, 47, 47, 272, - /* 1780 */ 47, 285, 47, 287, 47, 47, 47, 280, 47, 47, - /* 1790 */ 272, 47, 285, 47, 287, 0, 45, 47, 280, 37, - /* 1800 */ 0, 47, 45, 285, 37, 287, 0, 47, 312, 45, - /* 1810 */ 37, 315, 316, 317, 318, 319, 320, 0, 322, 312, - /* 1820 */ 45, 47, 315, 316, 317, 318, 319, 320, 245, 322, - /* 1830 */ 312, 37, 0, 315, 316, 317, 318, 319, 320, 47, - /* 1840 */ 322, 0, 22, 21, 245, 22, 22, 21, 20, 364, - /* 1850 */ 364, 364, 364, 364, 364, 272, 364, 364, 364, 364, - /* 1860 */ 364, 364, 364, 280, 364, 364, 364, 364, 285, 364, - /* 1870 */ 287, 272, 364, 364, 364, 364, 364, 364, 364, 280, - /* 1880 */ 364, 364, 364, 364, 285, 364, 287, 364, 364, 364, - /* 1890 */ 364, 364, 364, 245, 364, 312, 364, 364, 315, 316, - /* 1900 */ 317, 318, 319, 320, 364, 322, 364, 245, 364, 364, - /* 1910 */ 364, 312, 364, 364, 315, 316, 317, 318, 319, 320, - /* 1920 */ 272, 322, 364, 364, 364, 364, 364, 364, 280, 364, - /* 1930 */ 364, 364, 364, 285, 272, 287, 364, 364, 364, 364, - /* 1940 */ 364, 364, 280, 364, 364, 364, 364, 285, 245, 287, - /* 1950 */ 364, 364, 364, 364, 364, 364, 364, 364, 364, 364, - /* 1960 */ 312, 364, 364, 315, 316, 317, 318, 319, 320, 245, - /* 1970 */ 322, 364, 364, 364, 312, 272, 364, 315, 316, 317, - /* 1980 */ 318, 319, 320, 280, 322, 364, 364, 364, 285, 364, - /* 1990 */ 287, 364, 364, 364, 364, 364, 272, 364, 364, 364, - /* 2000 */ 364, 364, 364, 364, 280, 364, 364, 364, 364, 285, - /* 2010 */ 364, 287, 364, 364, 364, 312, 364, 364, 315, 316, - /* 2020 */ 317, 318, 319, 320, 364, 322, 364, 245, 364, 364, - /* 2030 */ 364, 364, 364, 364, 364, 364, 312, 364, 245, 315, - /* 2040 */ 316, 317, 318, 319, 320, 364, 322, 364, 364, 245, - /* 2050 */ 364, 364, 364, 364, 272, 364, 364, 364, 364, 364, - /* 2060 */ 364, 364, 280, 364, 364, 272, 364, 285, 364, 287, - /* 2070 */ 364, 364, 364, 280, 364, 364, 272, 364, 285, 364, - /* 2080 */ 287, 364, 364, 364, 280, 364, 364, 364, 364, 285, - /* 2090 */ 245, 287, 364, 364, 312, 364, 364, 315, 316, 317, - /* 2100 */ 318, 319, 320, 364, 322, 312, 364, 364, 315, 316, - /* 2110 */ 317, 318, 319, 320, 245, 322, 312, 272, 364, 315, - /* 2120 */ 316, 317, 318, 319, 320, 280, 322, 364, 364, 364, - /* 2130 */ 285, 364, 287, 364, 364, 364, 364, 364, 364, 364, - /* 2140 */ 364, 272, 364, 364, 364, 364, 364, 364, 364, 280, - /* 2150 */ 364, 364, 364, 364, 285, 364, 287, 312, 364, 364, - /* 2160 */ 315, 316, 317, 318, 319, 320, 364, 322, 364, 364, - /* 2170 */ 364, 364, 364, 364, 364, 364, 364, 364, 364, 364, - /* 2180 */ 364, 312, 364, 364, 315, 316, 317, 318, 319, 320, - /* 2190 */ 364, 322, + /* 0 */ 253, 0, 255, 256, 253, 279, 255, 256, 282, 347, + /* 10 */ 262, 246, 12, 13, 266, 307, 290, 261, 279, 278, + /* 20 */ 20, 0, 22, 361, 257, 279, 14, 365, 282, 290, + /* 30 */ 274, 248, 20, 250, 249, 35, 290, 288, 20, 283, + /* 40 */ 291, 292, 21, 317, 318, 24, 25, 26, 27, 28, + /* 50 */ 29, 30, 31, 32, 328, 347, 317, 318, 4, 59, + /* 60 */ 14, 294, 277, 317, 318, 65, 20, 328, 277, 361, + /* 70 */ 285, 20, 307, 365, 328, 290, 285, 292, 12, 13, + /* 80 */ 14, 14, 82, 307, 20, 22, 20, 20, 22, 8, + /* 90 */ 9, 58, 307, 12, 13, 14, 15, 16, 35, 249, + /* 100 */ 82, 35, 276, 318, 104, 20, 321, 322, 323, 324, + /* 110 */ 325, 326, 347, 328, 323, 289, 331, 261, 118, 119, + /* 120 */ 335, 336, 82, 347, 20, 59, 361, 277, 65, 347, + /* 130 */ 365, 65, 347, 257, 257, 285, 82, 361, 257, 283, + /* 140 */ 290, 365, 292, 361, 268, 268, 361, 365, 82, 21, + /* 150 */ 365, 275, 24, 25, 26, 27, 28, 29, 30, 31, + /* 160 */ 32, 285, 285, 163, 83, 165, 285, 104, 318, 58, + /* 170 */ 104, 321, 322, 323, 324, 325, 326, 327, 328, 329, + /* 180 */ 330, 145, 118, 119, 118, 119, 249, 187, 188, 43, + /* 190 */ 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + /* 200 */ 200, 201, 202, 191, 168, 56, 325, 18, 319, 20, + /* 210 */ 12, 13, 14, 15, 16, 215, 27, 0, 65, 30, + /* 220 */ 339, 340, 341, 342, 257, 344, 163, 290, 165, 163, + /* 230 */ 81, 165, 343, 84, 187, 268, 47, 191, 49, 203, + /* 240 */ 51, 24, 25, 26, 27, 28, 29, 30, 31, 32, + /* 250 */ 187, 188, 285, 187, 188, 215, 190, 191, 192, 193, + /* 260 */ 194, 195, 196, 197, 198, 199, 200, 201, 202, 215, + /* 270 */ 81, 224, 225, 226, 227, 228, 8, 9, 12, 13, + /* 280 */ 12, 13, 14, 15, 16, 20, 20, 265, 22, 267, + /* 290 */ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + /* 300 */ 105, 35, 107, 108, 109, 110, 111, 112, 1, 2, + /* 310 */ 121, 43, 20, 124, 125, 126, 127, 128, 129, 130, + /* 320 */ 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, + /* 330 */ 141, 65, 143, 144, 12, 13, 249, 20, 37, 332, + /* 340 */ 333, 20, 20, 22, 22, 8, 9, 56, 82, 12, + /* 350 */ 13, 14, 15, 16, 61, 62, 35, 35, 279, 66, + /* 360 */ 4, 20, 69, 70, 277, 257, 73, 74, 75, 290, + /* 370 */ 104, 50, 285, 82, 82, 84, 268, 290, 93, 292, + /* 380 */ 234, 59, 311, 275, 118, 119, 85, 65, 87, 88, + /* 390 */ 83, 90, 76, 285, 307, 94, 317, 318, 148, 4, + /* 400 */ 44, 45, 347, 249, 82, 318, 250, 328, 321, 322, + /* 410 */ 323, 324, 325, 326, 19, 328, 361, 116, 331, 257, + /* 420 */ 365, 257, 335, 336, 259, 292, 104, 0, 33, 163, + /* 430 */ 268, 165, 268, 300, 347, 65, 303, 272, 122, 123, + /* 440 */ 118, 119, 47, 249, 290, 280, 51, 285, 361, 285, + /* 450 */ 307, 56, 365, 187, 188, 278, 190, 191, 192, 193, + /* 460 */ 194, 195, 196, 197, 198, 199, 200, 201, 202, 269, + /* 470 */ 220, 221, 12, 13, 14, 254, 81, 277, 257, 84, + /* 480 */ 20, 215, 22, 257, 290, 163, 286, 165, 61, 62, + /* 490 */ 347, 150, 155, 66, 268, 35, 69, 70, 257, 266, + /* 500 */ 73, 74, 75, 257, 361, 3, 215, 215, 365, 187, + /* 510 */ 188, 285, 190, 191, 192, 193, 194, 195, 196, 197, + /* 520 */ 198, 199, 200, 201, 202, 65, 285, 12, 13, 291, + /* 530 */ 292, 285, 257, 158, 20, 20, 249, 22, 44, 45, + /* 540 */ 8, 9, 82, 268, 12, 13, 14, 15, 16, 114, + /* 550 */ 35, 8, 9, 178, 179, 12, 13, 14, 15, 16, + /* 560 */ 285, 257, 254, 249, 104, 257, 325, 269, 20, 249, + /* 570 */ 22, 325, 268, 302, 237, 277, 305, 290, 118, 119, + /* 580 */ 65, 340, 341, 342, 286, 344, 340, 341, 342, 285, + /* 590 */ 344, 277, 94, 12, 13, 368, 257, 82, 50, 285, + /* 600 */ 249, 20, 249, 22, 290, 94, 292, 268, 173, 174, + /* 610 */ 290, 113, 114, 115, 116, 117, 35, 257, 304, 104, + /* 620 */ 263, 264, 0, 163, 285, 165, 83, 116, 268, 14, + /* 630 */ 15, 16, 318, 118, 119, 321, 322, 323, 324, 325, + /* 640 */ 326, 290, 328, 290, 22, 285, 65, 187, 188, 35, + /* 650 */ 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + /* 660 */ 200, 201, 202, 82, 150, 257, 257, 8, 9, 20, + /* 670 */ 257, 12, 13, 14, 15, 16, 268, 268, 163, 65, + /* 680 */ 165, 268, 8, 9, 285, 104, 12, 13, 14, 15, + /* 690 */ 16, 263, 264, 285, 285, 296, 213, 214, 285, 118, + /* 700 */ 119, 0, 187, 188, 278, 190, 191, 192, 193, 194, + /* 710 */ 195, 196, 197, 198, 199, 200, 201, 202, 59, 82, + /* 720 */ 257, 8, 9, 19, 269, 12, 13, 14, 15, 16, + /* 730 */ 278, 268, 277, 59, 232, 278, 277, 33, 257, 0, + /* 740 */ 21, 286, 83, 284, 163, 249, 165, 277, 285, 268, + /* 750 */ 91, 47, 293, 34, 284, 36, 52, 53, 54, 55, + /* 760 */ 56, 113, 249, 293, 0, 91, 285, 249, 187, 188, + /* 770 */ 249, 190, 191, 192, 193, 194, 195, 196, 197, 198, + /* 780 */ 199, 200, 201, 202, 277, 81, 290, 18, 84, 292, + /* 790 */ 277, 249, 23, 286, 4, 94, 83, 58, 285, 162, + /* 800 */ 303, 164, 257, 290, 145, 292, 37, 38, 290, 319, + /* 810 */ 41, 290, 278, 268, 113, 114, 115, 116, 117, 145, + /* 820 */ 249, 117, 58, 175, 176, 302, 57, 168, 305, 277, + /* 830 */ 285, 318, 290, 343, 321, 322, 323, 324, 325, 326, + /* 840 */ 191, 328, 168, 0, 331, 293, 249, 249, 335, 336, + /* 850 */ 337, 82, 215, 149, 259, 0, 39, 278, 249, 346, + /* 860 */ 249, 290, 203, 204, 205, 206, 207, 208, 209, 210, + /* 870 */ 211, 212, 113, 114, 170, 280, 172, 203, 204, 205, + /* 880 */ 206, 207, 208, 209, 210, 211, 212, 290, 290, 120, + /* 890 */ 8, 9, 359, 249, 12, 13, 14, 15, 16, 290, + /* 900 */ 249, 290, 47, 249, 61, 62, 63, 64, 319, 66, + /* 910 */ 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + /* 920 */ 77, 78, 79, 43, 155, 156, 157, 249, 277, 160, + /* 930 */ 56, 59, 343, 174, 290, 166, 285, 12, 13, 287, + /* 940 */ 43, 290, 290, 292, 290, 287, 177, 22, 290, 180, + /* 950 */ 35, 182, 183, 184, 185, 186, 270, 258, 84, 273, + /* 960 */ 35, 249, 86, 83, 86, 89, 354, 89, 290, 318, + /* 970 */ 0, 0, 321, 322, 323, 324, 325, 326, 86, 328, + /* 980 */ 86, 89, 331, 89, 215, 0, 335, 336, 337, 277, + /* 990 */ 65, 150, 151, 22, 1, 2, 35, 285, 314, 43, + /* 1000 */ 349, 277, 290, 82, 292, 2, 216, 22, 357, 358, + /* 1010 */ 46, 8, 9, 92, 2, 12, 13, 14, 15, 16, + /* 1020 */ 8, 9, 249, 258, 12, 13, 14, 15, 16, 104, + /* 1030 */ 318, 214, 150, 321, 322, 323, 324, 325, 326, 83, + /* 1040 */ 328, 118, 119, 331, 256, 289, 82, 335, 336, 337, + /* 1050 */ 277, 320, 43, 43, 345, 362, 362, 362, 285, 187, + /* 1060 */ 43, 217, 43, 290, 94, 292, 43, 316, 348, 20, + /* 1070 */ 358, 43, 257, 47, 43, 43, 43, 249, 315, 35, + /* 1080 */ 165, 43, 43, 113, 114, 115, 116, 117, 163, 0, + /* 1090 */ 165, 318, 83, 83, 321, 322, 323, 324, 325, 326, + /* 1100 */ 83, 328, 83, 43, 331, 277, 83, 43, 335, 336, + /* 1110 */ 337, 83, 187, 285, 83, 83, 83, 263, 290, 346, + /* 1120 */ 292, 83, 83, 198, 199, 200, 165, 161, 43, 309, + /* 1130 */ 249, 35, 257, 236, 257, 42, 297, 48, 20, 249, + /* 1140 */ 145, 295, 295, 83, 257, 20, 318, 83, 313, 321, + /* 1150 */ 322, 323, 324, 325, 326, 251, 328, 249, 277, 331, + /* 1160 */ 251, 65, 261, 335, 336, 337, 285, 277, 83, 20, + /* 1170 */ 306, 290, 261, 292, 346, 285, 292, 20, 308, 261, + /* 1180 */ 290, 261, 292, 20, 298, 277, 251, 261, 307, 306, + /* 1190 */ 261, 257, 261, 285, 277, 257, 277, 307, 290, 318, + /* 1200 */ 292, 277, 321, 322, 323, 324, 325, 326, 318, 328, + /* 1210 */ 277, 321, 322, 323, 324, 325, 326, 277, 328, 277, + /* 1220 */ 277, 277, 249, 277, 277, 277, 318, 251, 347, 321, + /* 1230 */ 322, 323, 324, 325, 326, 290, 328, 347, 249, 331, + /* 1240 */ 313, 259, 361, 335, 336, 171, 365, 249, 312, 292, + /* 1250 */ 277, 361, 20, 259, 257, 365, 257, 306, 285, 259, + /* 1260 */ 223, 320, 290, 290, 222, 292, 277, 353, 301, 290, + /* 1270 */ 301, 290, 229, 290, 285, 277, 154, 231, 356, 290, + /* 1280 */ 352, 292, 230, 285, 218, 353, 214, 285, 290, 350, + /* 1290 */ 292, 318, 355, 316, 321, 322, 323, 324, 325, 326, + /* 1300 */ 249, 328, 353, 351, 331, 20, 319, 318, 335, 336, + /* 1310 */ 321, 322, 323, 324, 325, 326, 318, 328, 42, 321, + /* 1320 */ 322, 323, 324, 325, 326, 235, 328, 364, 277, 331, + /* 1330 */ 33, 233, 238, 82, 336, 301, 285, 363, 363, 338, + /* 1340 */ 334, 290, 301, 292, 47, 290, 290, 369, 364, 52, + /* 1350 */ 53, 54, 55, 56, 249, 366, 367, 290, 290, 290, + /* 1360 */ 364, 290, 147, 249, 299, 285, 259, 363, 298, 318, + /* 1370 */ 273, 259, 321, 322, 323, 324, 325, 326, 81, 328, + /* 1380 */ 285, 84, 277, 82, 281, 257, 267, 36, 259, 290, + /* 1390 */ 285, 277, 252, 251, 310, 290, 305, 292, 271, 285, + /* 1400 */ 247, 271, 271, 260, 290, 0, 292, 0, 42, 0, + /* 1410 */ 73, 360, 35, 249, 0, 181, 35, 35, 304, 35, + /* 1420 */ 181, 0, 35, 318, 249, 35, 321, 322, 323, 324, + /* 1430 */ 325, 326, 318, 328, 181, 321, 322, 323, 324, 325, + /* 1440 */ 326, 277, 328, 146, 147, 0, 149, 181, 0, 285, + /* 1450 */ 153, 35, 277, 0, 290, 22, 292, 0, 35, 0, + /* 1460 */ 285, 82, 168, 167, 165, 290, 163, 292, 0, 172, + /* 1470 */ 0, 159, 367, 158, 0, 0, 249, 46, 0, 304, + /* 1480 */ 0, 0, 318, 142, 0, 321, 322, 323, 324, 325, + /* 1490 */ 326, 0, 328, 318, 330, 0, 321, 322, 323, 324, + /* 1500 */ 325, 326, 0, 328, 277, 0, 137, 35, 0, 137, + /* 1510 */ 0, 0, 285, 0, 0, 0, 0, 290, 0, 292, + /* 1520 */ 0, 0, 0, 0, 0, 0, 0, 42, 0, 249, + /* 1530 */ 0, 304, 0, 0, 0, 0, 0, 0, 249, 22, + /* 1540 */ 0, 0, 0, 0, 43, 318, 42, 249, 321, 322, + /* 1550 */ 323, 324, 325, 326, 0, 328, 0, 277, 39, 14, + /* 1560 */ 14, 0, 0, 0, 154, 285, 277, 0, 0, 40, + /* 1570 */ 290, 0, 292, 46, 285, 277, 0, 46, 39, 290, + /* 1580 */ 0, 292, 0, 285, 0, 35, 39, 39, 290, 0, + /* 1590 */ 292, 47, 35, 0, 39, 35, 0, 0, 318, 249, + /* 1600 */ 47, 321, 322, 323, 324, 325, 326, 318, 328, 39, + /* 1610 */ 321, 322, 323, 324, 325, 326, 318, 328, 35, 321, + /* 1620 */ 322, 323, 324, 325, 326, 60, 328, 277, 47, 91, + /* 1630 */ 39, 22, 47, 35, 0, 285, 35, 35, 35, 35, + /* 1640 */ 290, 249, 292, 43, 0, 35, 35, 35, 89, 43, + /* 1650 */ 22, 0, 22, 0, 49, 22, 35, 0, 35, 0, + /* 1660 */ 35, 249, 0, 22, 0, 20, 35, 0, 318, 277, + /* 1670 */ 22, 321, 322, 323, 324, 325, 326, 285, 328, 0, + /* 1680 */ 0, 169, 290, 249, 292, 0, 0, 0, 219, 277, + /* 1690 */ 43, 35, 43, 43, 2, 82, 82, 285, 83, 147, + /* 1700 */ 82, 150, 290, 83, 292, 83, 82, 46, 82, 43, + /* 1710 */ 318, 277, 83, 321, 322, 323, 324, 325, 326, 285, + /* 1720 */ 328, 152, 150, 150, 290, 82, 292, 46, 219, 83, + /* 1730 */ 318, 43, 43, 321, 322, 323, 324, 325, 326, 249, + /* 1740 */ 328, 83, 46, 46, 43, 35, 83, 35, 249, 35, + /* 1750 */ 35, 83, 318, 35, 43, 321, 322, 323, 324, 325, + /* 1760 */ 326, 187, 328, 46, 22, 83, 82, 277, 46, 0, + /* 1770 */ 0, 39, 46, 83, 83, 285, 277, 213, 83, 189, + /* 1780 */ 290, 82, 292, 148, 285, 219, 82, 82, 82, 290, + /* 1790 */ 82, 292, 92, 46, 22, 82, 93, 35, 249, 83, + /* 1800 */ 146, 82, 82, 82, 106, 82, 35, 249, 318, 35, + /* 1810 */ 83, 321, 322, 323, 324, 325, 326, 318, 328, 82, + /* 1820 */ 321, 322, 323, 324, 325, 326, 277, 328, 83, 83, + /* 1830 */ 82, 35, 82, 35, 285, 277, 35, 83, 82, 290, + /* 1840 */ 83, 292, 82, 285, 106, 106, 22, 106, 290, 94, + /* 1850 */ 292, 35, 43, 22, 60, 82, 59, 249, 82, 82, + /* 1860 */ 35, 80, 43, 35, 65, 35, 249, 318, 35, 35, + /* 1870 */ 321, 322, 323, 324, 325, 326, 318, 328, 35, 321, + /* 1880 */ 322, 323, 324, 325, 326, 277, 328, 22, 35, 35, + /* 1890 */ 35, 65, 35, 285, 277, 35, 35, 35, 290, 35, + /* 1900 */ 292, 35, 285, 0, 35, 47, 39, 290, 0, 292, + /* 1910 */ 35, 39, 0, 35, 0, 47, 39, 47, 249, 35, + /* 1920 */ 47, 39, 0, 35, 35, 0, 318, 249, 22, 321, + /* 1930 */ 322, 323, 324, 325, 326, 318, 328, 21, 321, 322, + /* 1940 */ 323, 324, 325, 326, 21, 328, 277, 370, 22, 22, + /* 1950 */ 20, 370, 370, 370, 285, 277, 370, 370, 370, 290, + /* 1960 */ 370, 292, 370, 285, 370, 370, 370, 370, 290, 370, + /* 1970 */ 292, 370, 370, 370, 370, 370, 370, 370, 370, 370, + /* 1980 */ 249, 370, 370, 370, 370, 370, 370, 318, 370, 249, + /* 1990 */ 321, 322, 323, 324, 325, 326, 318, 328, 249, 321, + /* 2000 */ 322, 323, 324, 325, 326, 370, 328, 249, 277, 370, + /* 2010 */ 257, 370, 370, 370, 370, 370, 285, 277, 370, 370, + /* 2020 */ 370, 290, 370, 292, 370, 285, 277, 370, 370, 370, + /* 2030 */ 290, 370, 292, 370, 285, 277, 370, 370, 285, 290, + /* 2040 */ 370, 292, 370, 285, 370, 370, 370, 370, 290, 318, + /* 2050 */ 292, 370, 321, 322, 323, 324, 325, 326, 318, 328, + /* 2060 */ 307, 321, 322, 323, 324, 325, 326, 318, 328, 370, + /* 2070 */ 321, 322, 323, 324, 325, 326, 318, 328, 325, 321, + /* 2080 */ 322, 323, 324, 325, 326, 249, 328, 370, 370, 370, + /* 2090 */ 370, 370, 370, 340, 341, 342, 370, 344, 370, 257, + /* 2100 */ 347, 370, 370, 370, 370, 370, 370, 370, 370, 370, + /* 2110 */ 370, 370, 370, 277, 361, 370, 370, 370, 365, 370, + /* 2120 */ 370, 285, 370, 370, 370, 370, 290, 285, 292, 370, + /* 2130 */ 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, + /* 2140 */ 370, 370, 370, 370, 370, 370, 370, 370, 370, 307, + /* 2150 */ 370, 370, 370, 370, 318, 370, 370, 321, 322, 323, + /* 2160 */ 324, 325, 326, 370, 328, 370, 370, 325, 370, 370, + /* 2170 */ 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, + /* 2180 */ 370, 370, 340, 341, 342, 370, 344, 370, 370, 347, + /* 2190 */ 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, + /* 2200 */ 370, 370, 370, 361, 370, 370, 370, 365, }; -#define YY_SHIFT_COUNT (640) +#define YY_SHIFT_COUNT (652) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1841) +#define YY_SHIFT_MAX (1930) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 742, 0, 0, 48, 208, 208, 208, 208, 256, 256, - /* 10 */ 208, 208, 416, 464, 624, 464, 464, 464, 464, 464, - /* 20 */ 464, 464, 464, 464, 464, 464, 464, 464, 464, 464, - /* 30 */ 464, 464, 464, 464, 464, 464, 464, 464, 464, 464, - /* 40 */ 66, 66, 104, 104, 104, 18, 18, 18, 18, 12, - /* 50 */ 79, 207, 36, 36, 115, 115, 202, 153, 207, 207, - /* 60 */ 36, 36, 36, 36, 36, 36, 36, 36, 73, 36, - /* 70 */ 36, 180, 190, 312, 180, 36, 36, 180, 36, 180, - /* 80 */ 180, 180, 36, 409, 706, 478, 838, 838, 395, 189, - /* 90 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, - /* 100 */ 835, 835, 835, 835, 835, 835, 835, 835, 835, 198, - /* 110 */ 153, 4, 4, 281, 801, 479, 479, 479, 327, 801, - /* 120 */ 454, 312, 180, 180, 425, 425, 530, 726, 246, 246, - /* 130 */ 246, 246, 246, 246, 246, 1351, 351, 803, 350, 187, - /* 140 */ 449, 401, 423, 512, 558, 392, 531, 638, 732, 664, - /* 150 */ 697, 664, 165, 165, 165, 719, 705, 861, 1058, 1035, - /* 160 */ 1036, 925, 1058, 1058, 1047, 963, 963, 1058, 1097, 1097, - /* 170 */ 1101, 73, 312, 73, 1105, 1108, 73, 1105, 73, 454, - /* 180 */ 1123, 73, 73, 1058, 73, 1097, 180, 180, 180, 180, - /* 190 */ 180, 180, 180, 180, 180, 180, 180, 1058, 1097, 425, - /* 200 */ 425, 1101, 409, 991, 312, 409, 1058, 1105, 409, 454, - /* 210 */ 1123, 409, 1159, 425, 965, 967, 425, 965, 967, 425, - /* 220 */ 425, 180, 961, 1042, 965, 971, 974, 994, 861, 995, - /* 230 */ 454, 1202, 1183, 996, 997, 998, 996, 997, 996, 997, - /* 240 */ 1144, 967, 425, 425, 967, 425, 1096, 454, 1123, 409, - /* 250 */ 530, 409, 454, 1170, 425, 726, 1058, 409, 1097, 2192, - /* 260 */ 2192, 2192, 2192, 2192, 2192, 2192, 481, 657, 561, 119, - /* 270 */ 601, 891, 63, 13, 303, 203, 582, 374, 443, 552, - /* 280 */ 550, 550, 550, 550, 550, 550, 550, 550, 132, 382, - /* 290 */ 152, 529, 430, 137, 616, 616, 616, 616, 259, 837, - /* 300 */ 800, 818, 823, 824, 879, 913, 914, 906, 896, 908, - /* 310 */ 910, 946, 851, 720, 739, 932, 886, 938, 685, 945, - /* 320 */ 954, 969, 993, 1006, 850, 887, 1019, 1020, 1029, 1030, - /* 330 */ 1031, 1032, 277, 892, 966, 1272, 1286, 1249, 1298, 1230, - /* 340 */ 1303, 1259, 1130, 1261, 1262, 1264, 1135, 1314, 1268, 1269, - /* 350 */ 1142, 1320, 1145, 1321, 1277, 1326, 1305, 1329, 1283, 1331, - /* 360 */ 1251, 1169, 1171, 1174, 1178, 1338, 1339, 1185, 1188, 1344, - /* 370 */ 1345, 1302, 1347, 1207, 1349, 1363, 1364, 1365, 1366, 1215, - /* 380 */ 1322, 1367, 1241, 1380, 1381, 1382, 1383, 1385, 1386, 1388, - /* 390 */ 1389, 1390, 1391, 1395, 1397, 1398, 1399, 1360, 1401, 1407, - /* 400 */ 1408, 1409, 1410, 1411, 1392, 1412, 1415, 1418, 1420, 1428, - /* 410 */ 1430, 1393, 1402, 1394, 1422, 1400, 1424, 1403, 1442, 1405, - /* 420 */ 1413, 1445, 1446, 1449, 1414, 1304, 1452, 1456, 1421, 1457, - /* 430 */ 1404, 1459, 1461, 1423, 1419, 1425, 1465, 1426, 1427, 1431, - /* 440 */ 1469, 1434, 1429, 1441, 1471, 1444, 1447, 1460, 1494, 1499, - /* 450 */ 1502, 1503, 1433, 1416, 1458, 1487, 1510, 1464, 1466, 1467, - /* 460 */ 1468, 1477, 1479, 1474, 1478, 1480, 1512, 1504, 1528, 1508, - /* 470 */ 1484, 1534, 1522, 1500, 1546, 1526, 1549, 1529, 1530, 1552, - /* 480 */ 1406, 1506, 1557, 1432, 1536, 1435, 1436, 1565, 1567, 1568, - /* 490 */ 1440, 1569, 1489, 1538, 1443, 1532, 1535, 1356, 1497, 1495, - /* 500 */ 1498, 1513, 1543, 1517, 1511, 1519, 1520, 1521, 1553, 1558, - /* 510 */ 1560, 1524, 1570, 1437, 1527, 1531, 1562, 1448, 1582, 1564, - /* 520 */ 1544, 1586, 1439, 1547, 1581, 1584, 1585, 1588, 1589, 1590, - /* 530 */ 1547, 1628, 1462, 1598, 1559, 1563, 1561, 1602, 1572, 1574, - /* 540 */ 1606, 1636, 1481, 1578, 1594, 1603, 1605, 1609, 1541, 1618, - /* 550 */ 1664, 1630, 1566, 1619, 1610, 1659, 1661, 1625, 1626, 1631, - /* 560 */ 1685, 1632, 1622, 1629, 1668, 1669, 1638, 1635, 1673, 1640, - /* 570 */ 1642, 1675, 1645, 1646, 1680, 1649, 1656, 1684, 1663, 1637, - /* 580 */ 1641, 1643, 1644, 1718, 1650, 1666, 1670, 1698, 1678, 1720, - /* 590 */ 1720, 1740, 1705, 1707, 1719, 1706, 1688, 1728, 1725, 1726, - /* 600 */ 1727, 1730, 1731, 1749, 1733, 1735, 1711, 1477, 1737, 1479, - /* 610 */ 1738, 1739, 1741, 1742, 1744, 1746, 1795, 1750, 1751, 1762, - /* 620 */ 1800, 1754, 1757, 1767, 1806, 1760, 1764, 1773, 1817, 1774, - /* 630 */ 1775, 1794, 1832, 1792, 1841, 1820, 1822, 1823, 1824, 1826, - /* 640 */ 1828, + /* 0 */ 769, 0, 0, 66, 322, 322, 322, 322, 266, 266, + /* 10 */ 322, 322, 460, 515, 581, 515, 515, 515, 515, 515, + /* 20 */ 515, 515, 515, 515, 515, 515, 515, 515, 515, 515, + /* 30 */ 515, 515, 515, 515, 515, 515, 515, 515, 515, 515, + /* 40 */ 515, 515, 292, 292, 18, 18, 18, 925, 925, 925, + /* 50 */ 925, 637, 291, 40, 51, 51, 356, 356, 54, 64, + /* 60 */ 40, 40, 51, 51, 51, 51, 51, 51, 51, 51, + /* 70 */ 33, 51, 51, 51, 85, 104, 265, 51, 51, 265, + /* 80 */ 51, 265, 265, 265, 51, 111, 189, 659, 674, 674, + /* 90 */ 128, 293, 63, 63, 63, 63, 63, 63, 63, 63, + /* 100 */ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + /* 110 */ 63, 301, 64, 67, 67, 739, 614, 341, 341, 341, + /* 120 */ 764, 614, 317, 104, 1, 1, 265, 265, 153, 153, + /* 130 */ 285, 370, 195, 195, 195, 195, 195, 195, 195, 704, + /* 140 */ 21, 427, 337, 47, 321, 435, 250, 12, 46, 548, + /* 150 */ 494, 511, 514, 483, 817, 483, 502, 502, 502, 790, + /* 160 */ 649, 844, 1049, 1026, 1044, 966, 1049, 1049, 1093, 995, + /* 170 */ 995, 1049, 1118, 1118, 1125, 33, 104, 33, 1149, 1157, + /* 180 */ 33, 1149, 33, 1163, 33, 33, 1049, 33, 1118, 265, + /* 190 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, + /* 200 */ 1049, 1118, 153, 1125, 111, 1074, 104, 111, 1049, 1049, + /* 210 */ 1149, 111, 1232, 153, 1037, 1042, 153, 1037, 1042, 153, + /* 220 */ 153, 265, 1043, 1122, 1037, 1046, 1052, 1066, 844, 1072, + /* 230 */ 317, 1285, 1276, 1090, 1098, 1094, 1090, 1098, 1090, 1098, + /* 240 */ 1251, 1042, 153, 153, 153, 153, 153, 1042, 153, 1215, + /* 250 */ 317, 1163, 111, 285, 111, 317, 1301, 153, 370, 1049, + /* 260 */ 111, 1351, 1118, 2208, 2208, 2208, 2208, 2208, 2208, 2208, + /* 270 */ 843, 1297, 217, 395, 81, 268, 543, 1003, 1012, 882, + /* 280 */ 713, 532, 532, 532, 532, 532, 532, 532, 532, 701, + /* 290 */ 970, 498, 198, 198, 375, 149, 316, 719, 307, 36, + /* 300 */ 615, 615, 615, 615, 648, 759, 855, 880, 876, 878, + /* 310 */ 892, 894, 622, 971, 985, 874, 841, 956, 1009, 993, + /* 320 */ 923, 146, 897, 1010, 872, 1017, 964, 1019, 1023, 1028, + /* 330 */ 1031, 1032, 915, 961, 1033, 1038, 1039, 1060, 1064, 1085, + /* 340 */ 921, 1096, 1089, 1405, 1407, 1366, 1409, 1337, 1414, 1377, + /* 350 */ 1234, 1381, 1382, 1384, 1239, 1421, 1387, 1390, 1253, 1445, + /* 360 */ 1266, 1448, 1416, 1453, 1433, 1457, 1423, 1459, 1379, 1294, + /* 370 */ 1296, 1299, 1303, 1468, 1470, 1312, 1315, 1474, 1475, 1431, + /* 380 */ 1478, 1480, 1481, 1341, 1484, 1491, 1495, 1502, 1505, 1369, + /* 390 */ 1472, 1508, 1372, 1510, 1511, 1513, 1514, 1515, 1516, 1518, + /* 400 */ 1520, 1521, 1522, 1523, 1524, 1525, 1526, 1485, 1528, 1530, + /* 410 */ 1532, 1533, 1534, 1535, 1517, 1536, 1537, 1540, 1541, 1542, + /* 420 */ 1543, 1504, 1519, 1501, 1545, 1527, 1546, 1531, 1554, 1529, + /* 430 */ 1539, 1556, 1561, 1562, 1547, 1410, 1563, 1567, 1568, 1565, + /* 440 */ 1571, 1576, 1550, 1544, 1548, 1580, 1557, 1553, 1555, 1582, + /* 450 */ 1560, 1581, 1570, 1584, 1583, 1585, 1591, 1589, 1593, 1596, + /* 460 */ 1597, 1538, 1559, 1598, 1609, 1634, 1601, 1602, 1603, 1604, + /* 470 */ 1600, 1606, 1610, 1611, 1612, 1644, 1628, 1651, 1630, 1605, + /* 480 */ 1653, 1633, 1621, 1657, 1623, 1659, 1625, 1662, 1641, 1645, + /* 490 */ 1664, 1551, 1631, 1667, 1512, 1648, 1572, 1552, 1679, 1680, + /* 500 */ 1573, 1569, 1685, 1686, 1687, 1647, 1649, 1469, 1613, 1615, + /* 510 */ 1614, 1620, 1650, 1622, 1618, 1624, 1626, 1629, 1666, 1661, + /* 520 */ 1681, 1643, 1688, 1509, 1646, 1658, 1696, 1564, 1689, 1697, + /* 530 */ 1663, 1701, 1566, 1668, 1656, 1710, 1712, 1714, 1715, 1718, + /* 540 */ 1668, 1692, 1574, 1711, 1682, 1684, 1690, 1717, 1699, 1704, + /* 550 */ 1722, 1742, 1590, 1705, 1691, 1695, 1706, 1769, 1708, 1635, + /* 560 */ 1713, 1770, 1732, 1654, 1719, 1700, 1726, 1747, 1720, 1716, + /* 570 */ 1721, 1772, 1723, 1703, 1727, 1762, 1771, 1737, 1745, 1774, + /* 580 */ 1748, 1746, 1796, 1750, 1754, 1798, 1756, 1757, 1801, 1760, + /* 590 */ 1698, 1738, 1739, 1741, 1824, 1755, 1773, 1776, 1816, 1777, + /* 600 */ 1809, 1809, 1831, 1794, 1797, 1825, 1799, 1781, 1819, 1828, + /* 610 */ 1830, 1833, 1834, 1843, 1865, 1853, 1854, 1826, 1600, 1855, + /* 620 */ 1606, 1857, 1860, 1861, 1862, 1864, 1866, 1903, 1869, 1858, + /* 630 */ 1867, 1908, 1875, 1868, 1872, 1912, 1878, 1870, 1877, 1914, + /* 640 */ 1884, 1873, 1882, 1922, 1888, 1889, 1925, 1906, 1916, 1926, + /* 650 */ 1927, 1923, 1930, }; -#define YY_REDUCE_COUNT (265) -#define YY_REDUCE_MIN (-340) -#define YY_REDUCE_MAX (1869) +#define YY_REDUCE_COUNT (269) +#define YY_REDUCE_MIN (-338) +#define YY_REDUCE_MAX (1842) static const short yy_reduce_ofst[] = { - /* 0 */ -233, -228, -20, -176, 645, 737, 778, 819, 895, 958, - /* 10 */ 188, 975, 1038, 1056, 1107, 477, 1168, 1221, 1244, 1300, - /* 20 */ 1353, 1362, 713, 1376, 1417, 1438, 1496, 1507, 1518, 1583, - /* 30 */ 1599, 1648, 1662, 1703, 1724, 1782, 1793, 1804, 1845, 1869, - /* 40 */ 1141, 1255, -5, 607, 653, -274, -269, 49, 447, -227, - /* 50 */ -47, 161, -231, -229, -244, -215, -340, -105, -133, 123, - /* 60 */ -197, -147, 363, 411, 424, 440, 455, 487, -171, 492, - /* 70 */ 511, 200, -24, 234, -201, 521, 603, 251, 604, -101, - /* 80 */ 345, 357, 606, -119, -152, -281, -281, -281, 78, -247, - /* 90 */ -135, -21, 242, 250, 295, 331, 334, 390, 404, 453, - /* 100 */ 461, 483, 485, 502, 503, 564, 615, 617, 625, 199, - /* 110 */ -83, 420, 421, -27, 176, -263, 172, 406, -155, 279, - /* 120 */ 491, -172, 243, 346, 494, 542, 428, 435, -271, 355, - /* 130 */ 532, 555, 574, 608, 643, 585, 683, 691, 584, 602, - /* 140 */ 701, 651, 629, 709, 709, 730, 748, 717, 694, 674, - /* 150 */ 674, 674, 659, 660, 665, 684, 709, 766, 827, 772, - /* 160 */ 826, 783, 834, 840, 797, 820, 825, 864, 872, 873, - /* 170 */ 816, 867, 839, 868, 828, 829, 876, 830, 877, 862, - /* 180 */ 852, 890, 897, 899, 898, 900, 880, 883, 884, 885, - /* 190 */ 888, 889, 893, 894, 901, 902, 904, 911, 915, 903, - /* 200 */ 905, 858, 916, 863, 882, 917, 920, 878, 924, 907, - /* 210 */ 909, 927, 869, 912, 842, 922, 919, 844, 923, 921, - /* 220 */ 931, 709, 843, 845, 849, 853, 856, 865, 918, 674, - /* 230 */ 941, 926, 929, 866, 874, 870, 871, 928, 930, 939, - /* 240 */ 935, 944, 949, 950, 948, 952, 955, 962, 953, 999, - /* 250 */ 980, 1002, 972, 981, 979, 1003, 1007, 1012, 1021, 964, - /* 260 */ 977, 1005, 1013, 1015, 1014, 1039, + /* 0 */ -235, -215, 87, 651, 712, 513, 773, 828, 881, 890, + /* 10 */ 908, 973, -150, 989, 998, 314, 1051, 1105, 1114, 1164, + /* 20 */ 1175, 1227, 1280, 1289, 1298, 1350, 1392, 1412, 1434, 1490, + /* 30 */ 1499, 1549, 1558, 1608, 1617, 1669, 1678, 1731, 1740, 1749, + /* 40 */ 1758, 1836, 1753, 1842, -119, 241, 246, -274, -254, -261, + /* 50 */ 79, -292, -224, 143, -124, 108, -253, -249, -338, -251, + /* 60 */ -218, 55, -123, -33, 162, 164, 226, 275, 304, 339, + /* 70 */ -244, 360, 408, 409, -209, 133, 200, 413, 463, 459, + /* 80 */ 481, 298, 470, 455, 545, 165, -233, 7, 7, 7, + /* 90 */ -217, -252, -63, 154, 194, 287, 320, 351, 353, 496, + /* 100 */ 518, 521, 542, 571, 597, 598, 609, 611, 644, 654, + /* 110 */ 678, -174, 238, 221, 308, -144, 357, -111, 490, 589, + /* 120 */ 595, 428, 399, 497, 271, 523, 507, 552, 652, 658, + /* 130 */ 686, 22, -259, 177, 426, 452, 457, 534, 579, 71, + /* 140 */ 156, 233, 227, 533, 699, 684, 612, 724, 724, 765, + /* 150 */ 788, 756, 731, 709, 709, 709, 693, 694, 695, 720, + /* 160 */ 724, 751, 815, 763, 854, 820, 875, 877, 839, 846, + /* 170 */ 847, 887, 904, 909, 835, 901, 884, 911, 864, 870, + /* 180 */ 918, 883, 920, 886, 926, 929, 934, 931, 935, 917, + /* 190 */ 919, 924, 933, 940, 942, 943, 944, 946, 947, 948, + /* 200 */ 938, 976, 945, 927, 982, 936, 957, 994, 997, 999, + /* 210 */ 951, 1000, 941, 972, 914, 967, 979, 932, 969, 981, + /* 220 */ 983, 724, 922, 937, 949, 928, 952, 939, 977, 709, + /* 230 */ 1002, 987, 1001, 963, 974, 978, 984, 975, 996, 1004, + /* 240 */ 1006, 1034, 1055, 1056, 1067, 1068, 1069, 1041, 1071, 1065, + /* 250 */ 1080, 1070, 1107, 1097, 1112, 1095, 1103, 1099, 1119, 1128, + /* 260 */ 1129, 1140, 1142, 1084, 1091, 1127, 1130, 1131, 1143, 1153, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 10 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 20 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 30 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 40 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 50 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 60 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1468, 1399, - /* 70 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 80 */ 1399, 1399, 1399, 1466, 1617, 1399, 1781, 1399, 1399, 1399, - /* 90 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 100 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 110 */ 1399, 1399, 1399, 1468, 1399, 1792, 1792, 1792, 1466, 1399, - /* 120 */ 1399, 1399, 1399, 1399, 1399, 1399, 1562, 1399, 1399, 1399, - /* 130 */ 1399, 1399, 1399, 1399, 1399, 1650, 1399, 1399, 1862, 1399, - /* 140 */ 1399, 1656, 1816, 1399, 1399, 1399, 1399, 1515, 1808, 1784, - /* 150 */ 1798, 1785, 1847, 1847, 1847, 1801, 1399, 1812, 1399, 1399, - /* 160 */ 1399, 1642, 1399, 1399, 1622, 1619, 1619, 1399, 1399, 1399, - /* 170 */ 1399, 1468, 1399, 1468, 1399, 1399, 1468, 1399, 1468, 1399, - /* 180 */ 1399, 1468, 1468, 1399, 1468, 1399, 1399, 1399, 1399, 1399, - /* 190 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 200 */ 1399, 1399, 1466, 1652, 1399, 1466, 1399, 1399, 1466, 1399, - /* 210 */ 1399, 1466, 1399, 1399, 1823, 1821, 1399, 1823, 1821, 1399, - /* 220 */ 1399, 1399, 1835, 1831, 1823, 1839, 1837, 1814, 1812, 1798, - /* 230 */ 1399, 1399, 1399, 1853, 1849, 1865, 1853, 1849, 1853, 1849, - /* 240 */ 1399, 1821, 1399, 1399, 1821, 1399, 1627, 1399, 1399, 1466, - /* 250 */ 1399, 1466, 1399, 1531, 1399, 1399, 1399, 1466, 1399, 1644, - /* 260 */ 1658, 1565, 1565, 1565, 1469, 1404, 1399, 1399, 1399, 1399, - /* 270 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1527, - /* 280 */ 1725, 1834, 1833, 1757, 1756, 1755, 1753, 1724, 1399, 1399, - /* 290 */ 1399, 1399, 1399, 1399, 1718, 1719, 1717, 1716, 1399, 1399, - /* 300 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 310 */ 1399, 1782, 1399, 1850, 1854, 1399, 1399, 1399, 1701, 1399, - /* 320 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 330 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 340 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 350 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 360 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 370 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 380 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 390 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 400 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 410 */ 1399, 1399, 1399, 1433, 1399, 1399, 1399, 1399, 1399, 1399, - /* 420 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 430 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 440 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 450 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 460 */ 1399, 1496, 1495, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 470 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 480 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 490 */ 1399, 1399, 1399, 1399, 1399, 1805, 1815, 1399, 1399, 1399, - /* 500 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 510 */ 1701, 1399, 1832, 1399, 1791, 1787, 1399, 1399, 1783, 1399, - /* 520 */ 1399, 1848, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 530 */ 1399, 1777, 1399, 1750, 1399, 1399, 1399, 1399, 1399, 1399, - /* 540 */ 1399, 1399, 1712, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 550 */ 1399, 1399, 1399, 1399, 1399, 1700, 1399, 1741, 1399, 1399, - /* 560 */ 1399, 1399, 1399, 1399, 1399, 1399, 1559, 1399, 1399, 1399, - /* 570 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1544, - /* 580 */ 1542, 1541, 1540, 1399, 1537, 1399, 1399, 1399, 1399, 1568, - /* 590 */ 1567, 1399, 1399, 1399, 1399, 1399, 1399, 1488, 1399, 1399, - /* 600 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1479, 1399, 1478, - /* 610 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 620 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 630 */ 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, 1399, - /* 640 */ 1399, + /* 0 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 10 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 20 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 30 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 40 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 50 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 60 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 70 */ 1496, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 80 */ 1424, 1424, 1424, 1424, 1424, 1494, 1647, 1424, 1816, 1424, + /* 90 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 100 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 110 */ 1424, 1424, 1424, 1424, 1424, 1496, 1424, 1828, 1828, 1828, + /* 120 */ 1494, 1424, 1424, 1424, 1691, 1691, 1424, 1424, 1424, 1424, + /* 130 */ 1590, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1683, + /* 140 */ 1424, 1424, 1898, 1424, 1424, 1689, 1852, 1424, 1424, 1424, + /* 150 */ 1424, 1543, 1844, 1820, 1834, 1821, 1883, 1883, 1883, 1837, + /* 160 */ 1424, 1848, 1424, 1424, 1424, 1675, 1424, 1424, 1652, 1649, + /* 170 */ 1649, 1424, 1424, 1424, 1424, 1496, 1424, 1496, 1424, 1424, + /* 180 */ 1496, 1424, 1496, 1424, 1496, 1496, 1424, 1496, 1424, 1424, + /* 190 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 200 */ 1424, 1424, 1424, 1424, 1494, 1685, 1424, 1494, 1424, 1424, + /* 210 */ 1424, 1494, 1424, 1424, 1859, 1857, 1424, 1859, 1857, 1424, + /* 220 */ 1424, 1424, 1871, 1867, 1859, 1875, 1873, 1850, 1848, 1834, + /* 230 */ 1424, 1424, 1818, 1889, 1885, 1901, 1889, 1885, 1889, 1885, + /* 240 */ 1424, 1857, 1424, 1424, 1424, 1424, 1424, 1857, 1424, 1424, + /* 250 */ 1424, 1424, 1494, 1424, 1494, 1424, 1559, 1424, 1424, 1424, + /* 260 */ 1494, 1456, 1424, 1677, 1691, 1593, 1593, 1593, 1497, 1429, + /* 270 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 280 */ 1424, 1760, 1870, 1869, 1792, 1791, 1790, 1788, 1759, 1424, + /* 290 */ 1424, 1555, 1758, 1757, 1424, 1424, 1424, 1424, 1424, 1424, + /* 300 */ 1751, 1752, 1750, 1749, 1424, 1424, 1424, 1424, 1424, 1424, + /* 310 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1817, + /* 320 */ 1424, 1886, 1890, 1424, 1424, 1424, 1734, 1424, 1424, 1424, + /* 330 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 340 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 350 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 360 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 370 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 380 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 390 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 400 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 410 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 420 */ 1424, 1424, 1424, 1461, 1424, 1424, 1424, 1424, 1424, 1424, + /* 430 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 440 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 450 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 460 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 470 */ 1524, 1523, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 480 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 490 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 500 */ 1424, 1424, 1424, 1424, 1424, 1841, 1851, 1424, 1424, 1424, + /* 510 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 520 */ 1734, 1424, 1868, 1424, 1827, 1823, 1424, 1424, 1819, 1424, + /* 530 */ 1424, 1884, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 540 */ 1424, 1812, 1424, 1785, 1424, 1424, 1424, 1424, 1424, 1424, + /* 550 */ 1424, 1424, 1745, 1424, 1424, 1424, 1424, 1695, 1424, 1424, + /* 560 */ 1424, 1424, 1424, 1424, 1424, 1424, 1733, 1424, 1776, 1424, + /* 570 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1587, 1424, 1424, + /* 580 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 590 */ 1572, 1570, 1569, 1568, 1424, 1565, 1424, 1424, 1424, 1424, + /* 600 */ 1596, 1595, 1424, 1424, 1424, 1424, 1424, 1424, 1516, 1424, + /* 610 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1507, 1424, + /* 620 */ 1506, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 630 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 640 */ 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, 1424, + /* 650 */ 1424, 1424, 1424, }; /********** End of lemon-generated parsing tables *****************************/ @@ -881,7 +886,9 @@ static const YYCODETYPE yyFallback[] = { 0, /* CONNS => nothing */ 0, /* STATE => nothing */ 0, /* USER => nothing */ - 0, /* PRIVILEGE => nothing */ + 0, /* ENABLE => nothing */ + 0, /* NK_INTEGER => nothing */ + 0, /* SYSINFO => nothing */ 0, /* DROP => nothing */ 0, /* GRANT => nothing */ 0, /* ON => nothing */ @@ -894,7 +901,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* NK_DOT => nothing */ 0, /* DNODE => nothing */ 0, /* PORT => nothing */ - 0, /* NK_INTEGER => nothing */ 0, /* DNODES => nothing */ 0, /* NK_IPTOKEN => nothing */ 0, /* LOCAL => nothing */ @@ -989,13 +995,16 @@ static const YYCODETYPE yyFallback[] = { 0, /* CLUSTER => nothing */ 0, /* TRANSACTIONS => nothing */ 0, /* DISTRIBUTED => nothing */ + 0, /* CONSUMERS => nothing */ + 0, /* SUBSCRIPTIONS => nothing */ 0, /* LIKE => nothing */ 0, /* INDEX => nothing */ - 0, /* FULLTEXT => nothing */ 0, /* FUNCTION => nothing */ 0, /* INTERVAL => nothing */ 0, /* TOPIC => nothing */ 0, /* AS => nothing */ + 0, /* WITH => nothing */ + 0, /* META => nothing */ 0, /* CONSUMER => nothing */ 0, /* GROUP => nothing */ 0, /* DESC => nothing */ @@ -1083,12 +1092,12 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ID => nothing */ - 235, /* NK_BITNOT => ID */ - 235, /* INSERT => ID */ - 235, /* VALUES => ID */ - 235, /* IMPORT => ID */ - 235, /* NK_SEMI => ID */ - 235, /* FILE => ID */ + 239, /* NK_BITNOT => ID */ + 239, /* INSERT => ID */ + 239, /* VALUES => ID */ + 239, /* IMPORT => ID */ + 239, /* NK_SEMI => ID */ + 239, /* FILE => ID */ }; #endif /* YYFALLBACK */ @@ -1210,336 +1219,342 @@ static const char *const yyTokenName[] = { /* 31 */ "CONNS", /* 32 */ "STATE", /* 33 */ "USER", - /* 34 */ "PRIVILEGE", - /* 35 */ "DROP", - /* 36 */ "GRANT", - /* 37 */ "ON", - /* 38 */ "TO", - /* 39 */ "REVOKE", - /* 40 */ "FROM", - /* 41 */ "NK_COMMA", - /* 42 */ "READ", - /* 43 */ "WRITE", - /* 44 */ "NK_DOT", - /* 45 */ "DNODE", - /* 46 */ "PORT", - /* 47 */ "NK_INTEGER", - /* 48 */ "DNODES", - /* 49 */ "NK_IPTOKEN", - /* 50 */ "LOCAL", - /* 51 */ "QNODE", - /* 52 */ "BNODE", - /* 53 */ "SNODE", - /* 54 */ "MNODE", - /* 55 */ "DATABASE", - /* 56 */ "USE", - /* 57 */ "IF", - /* 58 */ "NOT", - /* 59 */ "EXISTS", - /* 60 */ "BUFFER", - /* 61 */ "CACHELAST", - /* 62 */ "COMP", - /* 63 */ "DURATION", - /* 64 */ "NK_VARIABLE", - /* 65 */ "FSYNC", - /* 66 */ "MAXROWS", - /* 67 */ "MINROWS", - /* 68 */ "KEEP", - /* 69 */ "PAGES", - /* 70 */ "PAGESIZE", - /* 71 */ "PRECISION", - /* 72 */ "REPLICA", - /* 73 */ "STRICT", - /* 74 */ "WAL", - /* 75 */ "VGROUPS", - /* 76 */ "SINGLE_STABLE", - /* 77 */ "RETENTIONS", - /* 78 */ "SCHEMALESS", - /* 79 */ "NK_COLON", - /* 80 */ "TABLE", - /* 81 */ "NK_LP", - /* 82 */ "NK_RP", - /* 83 */ "STABLE", - /* 84 */ "ADD", - /* 85 */ "COLUMN", - /* 86 */ "MODIFY", - /* 87 */ "RENAME", - /* 88 */ "TAG", - /* 89 */ "SET", - /* 90 */ "NK_EQ", - /* 91 */ "USING", - /* 92 */ "TAGS", - /* 93 */ "COMMENT", - /* 94 */ "BOOL", - /* 95 */ "TINYINT", - /* 96 */ "SMALLINT", - /* 97 */ "INT", - /* 98 */ "INTEGER", - /* 99 */ "BIGINT", - /* 100 */ "FLOAT", - /* 101 */ "DOUBLE", - /* 102 */ "BINARY", - /* 103 */ "TIMESTAMP", - /* 104 */ "NCHAR", - /* 105 */ "UNSIGNED", - /* 106 */ "JSON", - /* 107 */ "VARCHAR", - /* 108 */ "MEDIUMBLOB", - /* 109 */ "BLOB", - /* 110 */ "VARBINARY", - /* 111 */ "DECIMAL", - /* 112 */ "MAX_DELAY", - /* 113 */ "WATERMARK", - /* 114 */ "ROLLUP", - /* 115 */ "TTL", - /* 116 */ "SMA", - /* 117 */ "FIRST", - /* 118 */ "LAST", - /* 119 */ "SHOW", - /* 120 */ "DATABASES", - /* 121 */ "TABLES", - /* 122 */ "STABLES", - /* 123 */ "MNODES", - /* 124 */ "MODULES", - /* 125 */ "QNODES", - /* 126 */ "FUNCTIONS", - /* 127 */ "INDEXES", - /* 128 */ "ACCOUNTS", - /* 129 */ "APPS", - /* 130 */ "CONNECTIONS", - /* 131 */ "LICENCE", - /* 132 */ "GRANTS", - /* 133 */ "QUERIES", - /* 134 */ "SCORES", - /* 135 */ "TOPICS", - /* 136 */ "VARIABLES", - /* 137 */ "BNODES", - /* 138 */ "SNODES", - /* 139 */ "CLUSTER", - /* 140 */ "TRANSACTIONS", - /* 141 */ "DISTRIBUTED", - /* 142 */ "LIKE", - /* 143 */ "INDEX", - /* 144 */ "FULLTEXT", - /* 145 */ "FUNCTION", - /* 146 */ "INTERVAL", - /* 147 */ "TOPIC", - /* 148 */ "AS", - /* 149 */ "CONSUMER", - /* 150 */ "GROUP", - /* 151 */ "DESC", - /* 152 */ "DESCRIBE", - /* 153 */ "RESET", - /* 154 */ "QUERY", - /* 155 */ "CACHE", - /* 156 */ "EXPLAIN", - /* 157 */ "ANALYZE", - /* 158 */ "VERBOSE", - /* 159 */ "NK_BOOL", - /* 160 */ "RATIO", - /* 161 */ "NK_FLOAT", - /* 162 */ "COMPACT", - /* 163 */ "VNODES", - /* 164 */ "IN", - /* 165 */ "OUTPUTTYPE", - /* 166 */ "AGGREGATE", - /* 167 */ "BUFSIZE", - /* 168 */ "STREAM", - /* 169 */ "INTO", - /* 170 */ "TRIGGER", - /* 171 */ "AT_ONCE", - /* 172 */ "WINDOW_CLOSE", - /* 173 */ "KILL", - /* 174 */ "CONNECTION", - /* 175 */ "TRANSACTION", - /* 176 */ "BALANCE", - /* 177 */ "VGROUP", - /* 178 */ "MERGE", - /* 179 */ "REDISTRIBUTE", - /* 180 */ "SPLIT", - /* 181 */ "SYNCDB", - /* 182 */ "DELETE", - /* 183 */ "NULL", - /* 184 */ "NK_QUESTION", - /* 185 */ "NK_ARROW", - /* 186 */ "ROWTS", - /* 187 */ "TBNAME", - /* 188 */ "QSTARTTS", - /* 189 */ "QENDTS", - /* 190 */ "WSTARTTS", - /* 191 */ "WENDTS", - /* 192 */ "WDURATION", - /* 193 */ "CAST", - /* 194 */ "NOW", - /* 195 */ "TODAY", - /* 196 */ "TIMEZONE", - /* 197 */ "COUNT", - /* 198 */ "LAST_ROW", - /* 199 */ "BETWEEN", - /* 200 */ "IS", - /* 201 */ "NK_LT", - /* 202 */ "NK_GT", - /* 203 */ "NK_LE", - /* 204 */ "NK_GE", - /* 205 */ "NK_NE", - /* 206 */ "MATCH", - /* 207 */ "NMATCH", - /* 208 */ "CONTAINS", - /* 209 */ "JOIN", - /* 210 */ "INNER", - /* 211 */ "SELECT", - /* 212 */ "DISTINCT", - /* 213 */ "WHERE", - /* 214 */ "PARTITION", - /* 215 */ "BY", - /* 216 */ "SESSION", - /* 217 */ "STATE_WINDOW", - /* 218 */ "SLIDING", - /* 219 */ "FILL", - /* 220 */ "VALUE", - /* 221 */ "NONE", - /* 222 */ "PREV", - /* 223 */ "LINEAR", - /* 224 */ "NEXT", - /* 225 */ "HAVING", - /* 226 */ "RANGE", - /* 227 */ "EVERY", - /* 228 */ "ORDER", - /* 229 */ "SLIMIT", - /* 230 */ "SOFFSET", - /* 231 */ "LIMIT", - /* 232 */ "OFFSET", - /* 233 */ "ASC", - /* 234 */ "NULLS", - /* 235 */ "ID", - /* 236 */ "NK_BITNOT", - /* 237 */ "INSERT", - /* 238 */ "VALUES", - /* 239 */ "IMPORT", - /* 240 */ "NK_SEMI", - /* 241 */ "FILE", - /* 242 */ "cmd", - /* 243 */ "account_options", - /* 244 */ "alter_account_options", - /* 245 */ "literal", - /* 246 */ "alter_account_option", - /* 247 */ "user_name", - /* 248 */ "privileges", - /* 249 */ "priv_level", - /* 250 */ "priv_type_list", - /* 251 */ "priv_type", - /* 252 */ "db_name", - /* 253 */ "dnode_endpoint", - /* 254 */ "not_exists_opt", - /* 255 */ "db_options", - /* 256 */ "exists_opt", - /* 257 */ "alter_db_options", - /* 258 */ "integer_list", - /* 259 */ "variable_list", - /* 260 */ "retention_list", - /* 261 */ "alter_db_option", - /* 262 */ "retention", - /* 263 */ "full_table_name", - /* 264 */ "column_def_list", - /* 265 */ "tags_def_opt", - /* 266 */ "table_options", - /* 267 */ "multi_create_clause", - /* 268 */ "tags_def", - /* 269 */ "multi_drop_clause", - /* 270 */ "alter_table_clause", - /* 271 */ "alter_table_options", - /* 272 */ "column_name", - /* 273 */ "type_name", - /* 274 */ "signed_literal", - /* 275 */ "create_subtable_clause", - /* 276 */ "specific_tags_opt", - /* 277 */ "literal_list", - /* 278 */ "drop_table_clause", - /* 279 */ "col_name_list", - /* 280 */ "table_name", - /* 281 */ "column_def", - /* 282 */ "duration_list", - /* 283 */ "rollup_func_list", - /* 284 */ "alter_table_option", - /* 285 */ "duration_literal", - /* 286 */ "rollup_func_name", - /* 287 */ "function_name", - /* 288 */ "col_name", - /* 289 */ "db_name_cond_opt", - /* 290 */ "like_pattern_opt", - /* 291 */ "table_name_cond", - /* 292 */ "from_db_opt", - /* 293 */ "index_name", - /* 294 */ "index_options", - /* 295 */ "func_list", - /* 296 */ "sliding_opt", - /* 297 */ "func", - /* 298 */ "expression_list", - /* 299 */ "topic_name", - /* 300 */ "query_expression", - /* 301 */ "cgroup_name", - /* 302 */ "analyze_opt", - /* 303 */ "explain_options", - /* 304 */ "agg_func_opt", - /* 305 */ "bufsize_opt", - /* 306 */ "stream_name", - /* 307 */ "stream_options", - /* 308 */ "into_opt", - /* 309 */ "dnode_list", - /* 310 */ "where_clause_opt", - /* 311 */ "signed", - /* 312 */ "literal_func", - /* 313 */ "table_alias", - /* 314 */ "column_alias", - /* 315 */ "expression", - /* 316 */ "pseudo_column", - /* 317 */ "column_reference", - /* 318 */ "function_expression", - /* 319 */ "subquery", - /* 320 */ "star_func", - /* 321 */ "star_func_para_list", - /* 322 */ "noarg_func", - /* 323 */ "other_para_list", - /* 324 */ "star_func_para", - /* 325 */ "predicate", - /* 326 */ "compare_op", - /* 327 */ "in_op", - /* 328 */ "in_predicate_value", - /* 329 */ "boolean_value_expression", - /* 330 */ "boolean_primary", - /* 331 */ "common_expression", - /* 332 */ "from_clause", - /* 333 */ "table_reference_list", - /* 334 */ "table_reference", - /* 335 */ "table_primary", - /* 336 */ "joined_table", - /* 337 */ "alias_opt", - /* 338 */ "parenthesized_joined_table", - /* 339 */ "join_type", - /* 340 */ "search_condition", - /* 341 */ "query_specification", - /* 342 */ "set_quantifier_opt", - /* 343 */ "select_list", - /* 344 */ "partition_by_clause_opt", - /* 345 */ "range_opt", - /* 346 */ "every_opt", - /* 347 */ "fill_opt", - /* 348 */ "twindow_clause_opt", - /* 349 */ "group_by_clause_opt", - /* 350 */ "having_clause_opt", - /* 351 */ "select_sublist", - /* 352 */ "select_item", - /* 353 */ "fill_mode", - /* 354 */ "group_by_list", - /* 355 */ "query_expression_body", - /* 356 */ "order_by_clause_opt", - /* 357 */ "slimit_clause_opt", - /* 358 */ "limit_clause_opt", - /* 359 */ "query_primary", - /* 360 */ "sort_specification_list", - /* 361 */ "sort_specification", - /* 362 */ "ordering_specification_opt", - /* 363 */ "null_ordering_opt", + /* 34 */ "ENABLE", + /* 35 */ "NK_INTEGER", + /* 36 */ "SYSINFO", + /* 37 */ "DROP", + /* 38 */ "GRANT", + /* 39 */ "ON", + /* 40 */ "TO", + /* 41 */ "REVOKE", + /* 42 */ "FROM", + /* 43 */ "NK_COMMA", + /* 44 */ "READ", + /* 45 */ "WRITE", + /* 46 */ "NK_DOT", + /* 47 */ "DNODE", + /* 48 */ "PORT", + /* 49 */ "DNODES", + /* 50 */ "NK_IPTOKEN", + /* 51 */ "LOCAL", + /* 52 */ "QNODE", + /* 53 */ "BNODE", + /* 54 */ "SNODE", + /* 55 */ "MNODE", + /* 56 */ "DATABASE", + /* 57 */ "USE", + /* 58 */ "IF", + /* 59 */ "NOT", + /* 60 */ "EXISTS", + /* 61 */ "BUFFER", + /* 62 */ "CACHELAST", + /* 63 */ "COMP", + /* 64 */ "DURATION", + /* 65 */ "NK_VARIABLE", + /* 66 */ "FSYNC", + /* 67 */ "MAXROWS", + /* 68 */ "MINROWS", + /* 69 */ "KEEP", + /* 70 */ "PAGES", + /* 71 */ "PAGESIZE", + /* 72 */ "PRECISION", + /* 73 */ "REPLICA", + /* 74 */ "STRICT", + /* 75 */ "WAL", + /* 76 */ "VGROUPS", + /* 77 */ "SINGLE_STABLE", + /* 78 */ "RETENTIONS", + /* 79 */ "SCHEMALESS", + /* 80 */ "NK_COLON", + /* 81 */ "TABLE", + /* 82 */ "NK_LP", + /* 83 */ "NK_RP", + /* 84 */ "STABLE", + /* 85 */ "ADD", + /* 86 */ "COLUMN", + /* 87 */ "MODIFY", + /* 88 */ "RENAME", + /* 89 */ "TAG", + /* 90 */ "SET", + /* 91 */ "NK_EQ", + /* 92 */ "USING", + /* 93 */ "TAGS", + /* 94 */ "COMMENT", + /* 95 */ "BOOL", + /* 96 */ "TINYINT", + /* 97 */ "SMALLINT", + /* 98 */ "INT", + /* 99 */ "INTEGER", + /* 100 */ "BIGINT", + /* 101 */ "FLOAT", + /* 102 */ "DOUBLE", + /* 103 */ "BINARY", + /* 104 */ "TIMESTAMP", + /* 105 */ "NCHAR", + /* 106 */ "UNSIGNED", + /* 107 */ "JSON", + /* 108 */ "VARCHAR", + /* 109 */ "MEDIUMBLOB", + /* 110 */ "BLOB", + /* 111 */ "VARBINARY", + /* 112 */ "DECIMAL", + /* 113 */ "MAX_DELAY", + /* 114 */ "WATERMARK", + /* 115 */ "ROLLUP", + /* 116 */ "TTL", + /* 117 */ "SMA", + /* 118 */ "FIRST", + /* 119 */ "LAST", + /* 120 */ "SHOW", + /* 121 */ "DATABASES", + /* 122 */ "TABLES", + /* 123 */ "STABLES", + /* 124 */ "MNODES", + /* 125 */ "MODULES", + /* 126 */ "QNODES", + /* 127 */ "FUNCTIONS", + /* 128 */ "INDEXES", + /* 129 */ "ACCOUNTS", + /* 130 */ "APPS", + /* 131 */ "CONNECTIONS", + /* 132 */ "LICENCE", + /* 133 */ "GRANTS", + /* 134 */ "QUERIES", + /* 135 */ "SCORES", + /* 136 */ "TOPICS", + /* 137 */ "VARIABLES", + /* 138 */ "BNODES", + /* 139 */ "SNODES", + /* 140 */ "CLUSTER", + /* 141 */ "TRANSACTIONS", + /* 142 */ "DISTRIBUTED", + /* 143 */ "CONSUMERS", + /* 144 */ "SUBSCRIPTIONS", + /* 145 */ "LIKE", + /* 146 */ "INDEX", + /* 147 */ "FUNCTION", + /* 148 */ "INTERVAL", + /* 149 */ "TOPIC", + /* 150 */ "AS", + /* 151 */ "WITH", + /* 152 */ "META", + /* 153 */ "CONSUMER", + /* 154 */ "GROUP", + /* 155 */ "DESC", + /* 156 */ "DESCRIBE", + /* 157 */ "RESET", + /* 158 */ "QUERY", + /* 159 */ "CACHE", + /* 160 */ "EXPLAIN", + /* 161 */ "ANALYZE", + /* 162 */ "VERBOSE", + /* 163 */ "NK_BOOL", + /* 164 */ "RATIO", + /* 165 */ "NK_FLOAT", + /* 166 */ "COMPACT", + /* 167 */ "VNODES", + /* 168 */ "IN", + /* 169 */ "OUTPUTTYPE", + /* 170 */ "AGGREGATE", + /* 171 */ "BUFSIZE", + /* 172 */ "STREAM", + /* 173 */ "INTO", + /* 174 */ "TRIGGER", + /* 175 */ "AT_ONCE", + /* 176 */ "WINDOW_CLOSE", + /* 177 */ "KILL", + /* 178 */ "CONNECTION", + /* 179 */ "TRANSACTION", + /* 180 */ "BALANCE", + /* 181 */ "VGROUP", + /* 182 */ "MERGE", + /* 183 */ "REDISTRIBUTE", + /* 184 */ "SPLIT", + /* 185 */ "SYNCDB", + /* 186 */ "DELETE", + /* 187 */ "NULL", + /* 188 */ "NK_QUESTION", + /* 189 */ "NK_ARROW", + /* 190 */ "ROWTS", + /* 191 */ "TBNAME", + /* 192 */ "QSTARTTS", + /* 193 */ "QENDTS", + /* 194 */ "WSTARTTS", + /* 195 */ "WENDTS", + /* 196 */ "WDURATION", + /* 197 */ "CAST", + /* 198 */ "NOW", + /* 199 */ "TODAY", + /* 200 */ "TIMEZONE", + /* 201 */ "COUNT", + /* 202 */ "LAST_ROW", + /* 203 */ "BETWEEN", + /* 204 */ "IS", + /* 205 */ "NK_LT", + /* 206 */ "NK_GT", + /* 207 */ "NK_LE", + /* 208 */ "NK_GE", + /* 209 */ "NK_NE", + /* 210 */ "MATCH", + /* 211 */ "NMATCH", + /* 212 */ "CONTAINS", + /* 213 */ "JOIN", + /* 214 */ "INNER", + /* 215 */ "SELECT", + /* 216 */ "DISTINCT", + /* 217 */ "WHERE", + /* 218 */ "PARTITION", + /* 219 */ "BY", + /* 220 */ "SESSION", + /* 221 */ "STATE_WINDOW", + /* 222 */ "SLIDING", + /* 223 */ "FILL", + /* 224 */ "VALUE", + /* 225 */ "NONE", + /* 226 */ "PREV", + /* 227 */ "LINEAR", + /* 228 */ "NEXT", + /* 229 */ "HAVING", + /* 230 */ "RANGE", + /* 231 */ "EVERY", + /* 232 */ "ORDER", + /* 233 */ "SLIMIT", + /* 234 */ "SOFFSET", + /* 235 */ "LIMIT", + /* 236 */ "OFFSET", + /* 237 */ "ASC", + /* 238 */ "NULLS", + /* 239 */ "ID", + /* 240 */ "NK_BITNOT", + /* 241 */ "INSERT", + /* 242 */ "VALUES", + /* 243 */ "IMPORT", + /* 244 */ "NK_SEMI", + /* 245 */ "FILE", + /* 246 */ "cmd", + /* 247 */ "account_options", + /* 248 */ "alter_account_options", + /* 249 */ "literal", + /* 250 */ "alter_account_option", + /* 251 */ "user_name", + /* 252 */ "sysinfo_opt", + /* 253 */ "privileges", + /* 254 */ "priv_level", + /* 255 */ "priv_type_list", + /* 256 */ "priv_type", + /* 257 */ "db_name", + /* 258 */ "dnode_endpoint", + /* 259 */ "not_exists_opt", + /* 260 */ "db_options", + /* 261 */ "exists_opt", + /* 262 */ "alter_db_options", + /* 263 */ "integer_list", + /* 264 */ "variable_list", + /* 265 */ "retention_list", + /* 266 */ "alter_db_option", + /* 267 */ "retention", + /* 268 */ "full_table_name", + /* 269 */ "column_def_list", + /* 270 */ "tags_def_opt", + /* 271 */ "table_options", + /* 272 */ "multi_create_clause", + /* 273 */ "tags_def", + /* 274 */ "multi_drop_clause", + /* 275 */ "alter_table_clause", + /* 276 */ "alter_table_options", + /* 277 */ "column_name", + /* 278 */ "type_name", + /* 279 */ "signed_literal", + /* 280 */ "create_subtable_clause", + /* 281 */ "specific_tags_opt", + /* 282 */ "literal_list", + /* 283 */ "drop_table_clause", + /* 284 */ "col_name_list", + /* 285 */ "table_name", + /* 286 */ "column_def", + /* 287 */ "duration_list", + /* 288 */ "rollup_func_list", + /* 289 */ "alter_table_option", + /* 290 */ "duration_literal", + /* 291 */ "rollup_func_name", + /* 292 */ "function_name", + /* 293 */ "col_name", + /* 294 */ "db_name_cond_opt", + /* 295 */ "like_pattern_opt", + /* 296 */ "table_name_cond", + /* 297 */ "from_db_opt", + /* 298 */ "index_name", + /* 299 */ "index_options", + /* 300 */ "func_list", + /* 301 */ "sliding_opt", + /* 302 */ "sma_stream_opt", + /* 303 */ "func", + /* 304 */ "expression_list", + /* 305 */ "stream_options", + /* 306 */ "topic_name", + /* 307 */ "query_expression", + /* 308 */ "cgroup_name", + /* 309 */ "analyze_opt", + /* 310 */ "explain_options", + /* 311 */ "agg_func_opt", + /* 312 */ "bufsize_opt", + /* 313 */ "stream_name", + /* 314 */ "into_opt", + /* 315 */ "dnode_list", + /* 316 */ "where_clause_opt", + /* 317 */ "signed", + /* 318 */ "literal_func", + /* 319 */ "table_alias", + /* 320 */ "column_alias", + /* 321 */ "expression", + /* 322 */ "pseudo_column", + /* 323 */ "column_reference", + /* 324 */ "function_expression", + /* 325 */ "subquery", + /* 326 */ "star_func", + /* 327 */ "star_func_para_list", + /* 328 */ "noarg_func", + /* 329 */ "other_para_list", + /* 330 */ "star_func_para", + /* 331 */ "predicate", + /* 332 */ "compare_op", + /* 333 */ "in_op", + /* 334 */ "in_predicate_value", + /* 335 */ "boolean_value_expression", + /* 336 */ "boolean_primary", + /* 337 */ "common_expression", + /* 338 */ "from_clause_opt", + /* 339 */ "table_reference_list", + /* 340 */ "table_reference", + /* 341 */ "table_primary", + /* 342 */ "joined_table", + /* 343 */ "alias_opt", + /* 344 */ "parenthesized_joined_table", + /* 345 */ "join_type", + /* 346 */ "search_condition", + /* 347 */ "query_specification", + /* 348 */ "set_quantifier_opt", + /* 349 */ "select_list", + /* 350 */ "partition_by_clause_opt", + /* 351 */ "range_opt", + /* 352 */ "every_opt", + /* 353 */ "fill_opt", + /* 354 */ "twindow_clause_opt", + /* 355 */ "group_by_clause_opt", + /* 356 */ "having_clause_opt", + /* 357 */ "select_sublist", + /* 358 */ "select_item", + /* 359 */ "fill_mode", + /* 360 */ "group_by_list", + /* 361 */ "query_expression_body", + /* 362 */ "order_by_clause_opt", + /* 363 */ "slimit_clause_opt", + /* 364 */ "limit_clause_opt", + /* 365 */ "query_primary", + /* 366 */ "sort_specification_list", + /* 367 */ "sort_specification", + /* 368 */ "ordering_specification_opt", + /* 369 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1571,448 +1586,459 @@ static const char *const yyRuleName[] = { /* 21 */ "alter_account_option ::= USERS literal", /* 22 */ "alter_account_option ::= CONNS literal", /* 23 */ "alter_account_option ::= STATE literal", - /* 24 */ "cmd ::= CREATE USER user_name PASS NK_STRING", + /* 24 */ "cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt", /* 25 */ "cmd ::= ALTER USER user_name PASS NK_STRING", - /* 26 */ "cmd ::= ALTER USER user_name PRIVILEGE NK_STRING", - /* 27 */ "cmd ::= DROP USER user_name", - /* 28 */ "cmd ::= GRANT privileges ON priv_level TO user_name", - /* 29 */ "cmd ::= REVOKE privileges ON priv_level FROM user_name", - /* 30 */ "privileges ::= ALL", - /* 31 */ "privileges ::= priv_type_list", - /* 32 */ "priv_type_list ::= priv_type", - /* 33 */ "priv_type_list ::= priv_type_list NK_COMMA priv_type", - /* 34 */ "priv_type ::= READ", - /* 35 */ "priv_type ::= WRITE", - /* 36 */ "priv_level ::= NK_STAR NK_DOT NK_STAR", - /* 37 */ "priv_level ::= db_name NK_DOT NK_STAR", - /* 38 */ "cmd ::= CREATE DNODE dnode_endpoint", - /* 39 */ "cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER", - /* 40 */ "cmd ::= DROP DNODE NK_INTEGER", - /* 41 */ "cmd ::= DROP DNODE dnode_endpoint", - /* 42 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING", - /* 43 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING", - /* 44 */ "cmd ::= ALTER ALL DNODES NK_STRING", - /* 45 */ "cmd ::= ALTER ALL DNODES NK_STRING NK_STRING", - /* 46 */ "dnode_endpoint ::= NK_STRING", - /* 47 */ "dnode_endpoint ::= NK_ID", - /* 48 */ "dnode_endpoint ::= NK_IPTOKEN", - /* 49 */ "cmd ::= ALTER LOCAL NK_STRING", - /* 50 */ "cmd ::= ALTER LOCAL NK_STRING NK_STRING", - /* 51 */ "cmd ::= CREATE QNODE ON DNODE NK_INTEGER", - /* 52 */ "cmd ::= DROP QNODE ON DNODE NK_INTEGER", - /* 53 */ "cmd ::= CREATE BNODE ON DNODE NK_INTEGER", - /* 54 */ "cmd ::= DROP BNODE ON DNODE NK_INTEGER", - /* 55 */ "cmd ::= CREATE SNODE ON DNODE NK_INTEGER", - /* 56 */ "cmd ::= DROP SNODE ON DNODE NK_INTEGER", - /* 57 */ "cmd ::= CREATE MNODE ON DNODE NK_INTEGER", - /* 58 */ "cmd ::= DROP MNODE ON DNODE NK_INTEGER", - /* 59 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", - /* 60 */ "cmd ::= DROP DATABASE exists_opt db_name", - /* 61 */ "cmd ::= USE db_name", - /* 62 */ "cmd ::= ALTER DATABASE db_name alter_db_options", - /* 63 */ "not_exists_opt ::= IF NOT EXISTS", - /* 64 */ "not_exists_opt ::=", - /* 65 */ "exists_opt ::= IF EXISTS", - /* 66 */ "exists_opt ::=", - /* 67 */ "db_options ::=", - /* 68 */ "db_options ::= db_options BUFFER NK_INTEGER", - /* 69 */ "db_options ::= db_options CACHELAST NK_INTEGER", - /* 70 */ "db_options ::= db_options COMP NK_INTEGER", - /* 71 */ "db_options ::= db_options DURATION NK_INTEGER", - /* 72 */ "db_options ::= db_options DURATION NK_VARIABLE", - /* 73 */ "db_options ::= db_options FSYNC NK_INTEGER", - /* 74 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 75 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 76 */ "db_options ::= db_options KEEP integer_list", - /* 77 */ "db_options ::= db_options KEEP variable_list", - /* 78 */ "db_options ::= db_options PAGES NK_INTEGER", - /* 79 */ "db_options ::= db_options PAGESIZE NK_INTEGER", - /* 80 */ "db_options ::= db_options PRECISION NK_STRING", - /* 81 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 82 */ "db_options ::= db_options STRICT NK_INTEGER", - /* 83 */ "db_options ::= db_options WAL NK_INTEGER", - /* 84 */ "db_options ::= db_options VGROUPS NK_INTEGER", - /* 85 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 86 */ "db_options ::= db_options RETENTIONS retention_list", - /* 87 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", - /* 88 */ "alter_db_options ::= alter_db_option", - /* 89 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 90 */ "alter_db_option ::= BUFFER NK_INTEGER", - /* 91 */ "alter_db_option ::= CACHELAST NK_INTEGER", - /* 92 */ "alter_db_option ::= FSYNC NK_INTEGER", - /* 93 */ "alter_db_option ::= KEEP integer_list", - /* 94 */ "alter_db_option ::= KEEP variable_list", - /* 95 */ "alter_db_option ::= PAGES NK_INTEGER", - /* 96 */ "alter_db_option ::= REPLICA NK_INTEGER", - /* 97 */ "alter_db_option ::= STRICT NK_INTEGER", - /* 98 */ "alter_db_option ::= WAL NK_INTEGER", - /* 99 */ "integer_list ::= NK_INTEGER", - /* 100 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 101 */ "variable_list ::= NK_VARIABLE", - /* 102 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 103 */ "retention_list ::= retention", - /* 104 */ "retention_list ::= retention_list NK_COMMA retention", - /* 105 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 106 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 107 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 108 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 109 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 110 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 111 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 112 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 113 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 114 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 115 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 116 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 117 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 118 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 119 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 120 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 121 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 122 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", - /* 123 */ "multi_create_clause ::= create_subtable_clause", - /* 124 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 125 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options", - /* 126 */ "multi_drop_clause ::= drop_table_clause", - /* 127 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 128 */ "drop_table_clause ::= exists_opt full_table_name", - /* 129 */ "specific_tags_opt ::=", - /* 130 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", - /* 131 */ "full_table_name ::= table_name", - /* 132 */ "full_table_name ::= db_name NK_DOT table_name", - /* 133 */ "column_def_list ::= column_def", - /* 134 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 135 */ "column_def ::= column_name type_name", - /* 136 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 137 */ "type_name ::= BOOL", - /* 138 */ "type_name ::= TINYINT", - /* 139 */ "type_name ::= SMALLINT", - /* 140 */ "type_name ::= INT", - /* 141 */ "type_name ::= INTEGER", - /* 142 */ "type_name ::= BIGINT", - /* 143 */ "type_name ::= FLOAT", - /* 144 */ "type_name ::= DOUBLE", - /* 145 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 146 */ "type_name ::= TIMESTAMP", - /* 147 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 148 */ "type_name ::= TINYINT UNSIGNED", - /* 149 */ "type_name ::= SMALLINT UNSIGNED", - /* 150 */ "type_name ::= INT UNSIGNED", - /* 151 */ "type_name ::= BIGINT UNSIGNED", - /* 152 */ "type_name ::= JSON", - /* 153 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 154 */ "type_name ::= MEDIUMBLOB", - /* 155 */ "type_name ::= BLOB", - /* 156 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 157 */ "type_name ::= DECIMAL", - /* 158 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 159 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 160 */ "tags_def_opt ::=", - /* 161 */ "tags_def_opt ::= tags_def", - /* 162 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 163 */ "table_options ::=", - /* 164 */ "table_options ::= table_options COMMENT NK_STRING", - /* 165 */ "table_options ::= table_options MAX_DELAY duration_list", - /* 166 */ "table_options ::= table_options WATERMARK duration_list", - /* 167 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", - /* 168 */ "table_options ::= table_options TTL NK_INTEGER", - /* 169 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 170 */ "alter_table_options ::= alter_table_option", - /* 171 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 172 */ "alter_table_option ::= COMMENT NK_STRING", - /* 173 */ "alter_table_option ::= TTL NK_INTEGER", - /* 174 */ "duration_list ::= duration_literal", - /* 175 */ "duration_list ::= duration_list NK_COMMA duration_literal", - /* 176 */ "rollup_func_list ::= rollup_func_name", - /* 177 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", - /* 178 */ "rollup_func_name ::= function_name", - /* 179 */ "rollup_func_name ::= FIRST", - /* 180 */ "rollup_func_name ::= LAST", - /* 181 */ "col_name_list ::= col_name", - /* 182 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 183 */ "col_name ::= column_name", - /* 184 */ "cmd ::= SHOW DNODES", - /* 185 */ "cmd ::= SHOW USERS", - /* 186 */ "cmd ::= SHOW DATABASES", - /* 187 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 188 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 189 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 190 */ "cmd ::= SHOW MNODES", - /* 191 */ "cmd ::= SHOW MODULES", - /* 192 */ "cmd ::= SHOW QNODES", - /* 193 */ "cmd ::= SHOW FUNCTIONS", - /* 194 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 195 */ "cmd ::= SHOW STREAMS", - /* 196 */ "cmd ::= SHOW ACCOUNTS", - /* 197 */ "cmd ::= SHOW APPS", - /* 198 */ "cmd ::= SHOW CONNECTIONS", - /* 199 */ "cmd ::= SHOW LICENCE", - /* 200 */ "cmd ::= SHOW GRANTS", - /* 201 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 202 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 203 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 204 */ "cmd ::= SHOW QUERIES", - /* 205 */ "cmd ::= SHOW SCORES", - /* 206 */ "cmd ::= SHOW TOPICS", - /* 207 */ "cmd ::= SHOW VARIABLES", - /* 208 */ "cmd ::= SHOW LOCAL VARIABLES", - /* 209 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", - /* 210 */ "cmd ::= SHOW BNODES", - /* 211 */ "cmd ::= SHOW SNODES", - /* 212 */ "cmd ::= SHOW CLUSTER", - /* 213 */ "cmd ::= SHOW TRANSACTIONS", - /* 214 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", - /* 215 */ "db_name_cond_opt ::=", - /* 216 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 217 */ "like_pattern_opt ::=", - /* 218 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 219 */ "table_name_cond ::= table_name", - /* 220 */ "from_db_opt ::=", - /* 221 */ "from_db_opt ::= FROM db_name", - /* 222 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 223 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 224 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 225 */ "index_options ::=", - /* 226 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 227 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 228 */ "func_list ::= func", - /* 229 */ "func_list ::= func_list NK_COMMA func", - /* 230 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 231 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 232 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 233 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 234 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 235 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 236 */ "cmd ::= DESC full_table_name", - /* 237 */ "cmd ::= DESCRIBE full_table_name", - /* 238 */ "cmd ::= RESET QUERY CACHE", - /* 239 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 240 */ "analyze_opt ::=", - /* 241 */ "analyze_opt ::= ANALYZE", - /* 242 */ "explain_options ::=", - /* 243 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 244 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 245 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 246 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 247 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 248 */ "agg_func_opt ::=", - /* 249 */ "agg_func_opt ::= AGGREGATE", - /* 250 */ "bufsize_opt ::=", - /* 251 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 252 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 253 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 254 */ "into_opt ::=", - /* 255 */ "into_opt ::= INTO full_table_name", - /* 256 */ "stream_options ::=", - /* 257 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 258 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 259 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 260 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 261 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 262 */ "cmd ::= KILL QUERY NK_STRING", - /* 263 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 264 */ "cmd ::= BALANCE VGROUP", - /* 265 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 266 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 267 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 268 */ "dnode_list ::= DNODE NK_INTEGER", - /* 269 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 270 */ "cmd ::= SYNCDB db_name REPLICA", - /* 271 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 272 */ "cmd ::= query_expression", - /* 273 */ "literal ::= NK_INTEGER", - /* 274 */ "literal ::= NK_FLOAT", - /* 275 */ "literal ::= NK_STRING", - /* 276 */ "literal ::= NK_BOOL", - /* 277 */ "literal ::= TIMESTAMP NK_STRING", - /* 278 */ "literal ::= duration_literal", - /* 279 */ "literal ::= NULL", - /* 280 */ "literal ::= NK_QUESTION", - /* 281 */ "duration_literal ::= NK_VARIABLE", - /* 282 */ "signed ::= NK_INTEGER", - /* 283 */ "signed ::= NK_PLUS NK_INTEGER", - /* 284 */ "signed ::= NK_MINUS NK_INTEGER", - /* 285 */ "signed ::= NK_FLOAT", - /* 286 */ "signed ::= NK_PLUS NK_FLOAT", - /* 287 */ "signed ::= NK_MINUS NK_FLOAT", - /* 288 */ "signed_literal ::= signed", - /* 289 */ "signed_literal ::= NK_STRING", - /* 290 */ "signed_literal ::= NK_BOOL", - /* 291 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 292 */ "signed_literal ::= duration_literal", - /* 293 */ "signed_literal ::= NULL", - /* 294 */ "signed_literal ::= literal_func", - /* 295 */ "literal_list ::= signed_literal", - /* 296 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 297 */ "db_name ::= NK_ID", - /* 298 */ "table_name ::= NK_ID", - /* 299 */ "column_name ::= NK_ID", - /* 300 */ "function_name ::= NK_ID", - /* 301 */ "table_alias ::= NK_ID", - /* 302 */ "column_alias ::= NK_ID", - /* 303 */ "user_name ::= NK_ID", - /* 304 */ "index_name ::= NK_ID", - /* 305 */ "topic_name ::= NK_ID", - /* 306 */ "stream_name ::= NK_ID", - /* 307 */ "cgroup_name ::= NK_ID", - /* 308 */ "expression ::= literal", - /* 309 */ "expression ::= pseudo_column", - /* 310 */ "expression ::= column_reference", - /* 311 */ "expression ::= function_expression", - /* 312 */ "expression ::= subquery", - /* 313 */ "expression ::= NK_LP expression NK_RP", - /* 314 */ "expression ::= NK_PLUS expression", - /* 315 */ "expression ::= NK_MINUS expression", - /* 316 */ "expression ::= expression NK_PLUS expression", - /* 317 */ "expression ::= expression NK_MINUS expression", - /* 318 */ "expression ::= expression NK_STAR expression", - /* 319 */ "expression ::= expression NK_SLASH expression", - /* 320 */ "expression ::= expression NK_REM expression", - /* 321 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 322 */ "expression_list ::= expression", - /* 323 */ "expression_list ::= expression_list NK_COMMA expression", - /* 324 */ "column_reference ::= column_name", - /* 325 */ "column_reference ::= table_name NK_DOT column_name", - /* 326 */ "pseudo_column ::= ROWTS", - /* 327 */ "pseudo_column ::= TBNAME", - /* 328 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 329 */ "pseudo_column ::= QSTARTTS", - /* 330 */ "pseudo_column ::= QENDTS", - /* 331 */ "pseudo_column ::= WSTARTTS", - /* 332 */ "pseudo_column ::= WENDTS", - /* 333 */ "pseudo_column ::= WDURATION", - /* 334 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 335 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 336 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 337 */ "function_expression ::= literal_func", - /* 338 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 339 */ "literal_func ::= NOW", - /* 340 */ "noarg_func ::= NOW", - /* 341 */ "noarg_func ::= TODAY", - /* 342 */ "noarg_func ::= TIMEZONE", - /* 343 */ "star_func ::= COUNT", - /* 344 */ "star_func ::= FIRST", - /* 345 */ "star_func ::= LAST", - /* 346 */ "star_func ::= LAST_ROW", - /* 347 */ "star_func_para_list ::= NK_STAR", - /* 348 */ "star_func_para_list ::= other_para_list", - /* 349 */ "other_para_list ::= star_func_para", - /* 350 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 351 */ "star_func_para ::= expression", - /* 352 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 353 */ "predicate ::= expression compare_op expression", - /* 354 */ "predicate ::= expression BETWEEN expression AND expression", - /* 355 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 356 */ "predicate ::= expression IS NULL", - /* 357 */ "predicate ::= expression IS NOT NULL", - /* 358 */ "predicate ::= expression in_op in_predicate_value", - /* 359 */ "compare_op ::= NK_LT", - /* 360 */ "compare_op ::= NK_GT", - /* 361 */ "compare_op ::= NK_LE", - /* 362 */ "compare_op ::= NK_GE", - /* 363 */ "compare_op ::= NK_NE", - /* 364 */ "compare_op ::= NK_EQ", - /* 365 */ "compare_op ::= LIKE", - /* 366 */ "compare_op ::= NOT LIKE", - /* 367 */ "compare_op ::= MATCH", - /* 368 */ "compare_op ::= NMATCH", - /* 369 */ "compare_op ::= CONTAINS", - /* 370 */ "in_op ::= IN", - /* 371 */ "in_op ::= NOT IN", - /* 372 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 373 */ "boolean_value_expression ::= boolean_primary", - /* 374 */ "boolean_value_expression ::= NOT boolean_primary", - /* 375 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 376 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 377 */ "boolean_primary ::= predicate", - /* 378 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 379 */ "common_expression ::= expression", - /* 380 */ "common_expression ::= boolean_value_expression", - /* 381 */ "from_clause ::= FROM table_reference_list", - /* 382 */ "table_reference_list ::= table_reference", - /* 383 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 384 */ "table_reference ::= table_primary", - /* 385 */ "table_reference ::= joined_table", - /* 386 */ "table_primary ::= table_name alias_opt", - /* 387 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 388 */ "table_primary ::= subquery alias_opt", - /* 389 */ "table_primary ::= parenthesized_joined_table", - /* 390 */ "alias_opt ::=", - /* 391 */ "alias_opt ::= table_alias", - /* 392 */ "alias_opt ::= AS table_alias", - /* 393 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 394 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 395 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 396 */ "join_type ::=", - /* 397 */ "join_type ::= INNER", - /* 398 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 399 */ "set_quantifier_opt ::=", - /* 400 */ "set_quantifier_opt ::= DISTINCT", - /* 401 */ "set_quantifier_opt ::= ALL", - /* 402 */ "select_list ::= NK_STAR", - /* 403 */ "select_list ::= select_sublist", - /* 404 */ "select_sublist ::= select_item", - /* 405 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 406 */ "select_item ::= common_expression", - /* 407 */ "select_item ::= common_expression column_alias", - /* 408 */ "select_item ::= common_expression AS column_alias", - /* 409 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 410 */ "where_clause_opt ::=", - /* 411 */ "where_clause_opt ::= WHERE search_condition", - /* 412 */ "partition_by_clause_opt ::=", - /* 413 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 414 */ "twindow_clause_opt ::=", - /* 415 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 416 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 417 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 418 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 419 */ "sliding_opt ::=", - /* 420 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 421 */ "fill_opt ::=", - /* 422 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 423 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 424 */ "fill_mode ::= NONE", - /* 425 */ "fill_mode ::= PREV", - /* 426 */ "fill_mode ::= NULL", - /* 427 */ "fill_mode ::= LINEAR", - /* 428 */ "fill_mode ::= NEXT", - /* 429 */ "group_by_clause_opt ::=", - /* 430 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 431 */ "group_by_list ::= expression", - /* 432 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 433 */ "having_clause_opt ::=", - /* 434 */ "having_clause_opt ::= HAVING search_condition", - /* 435 */ "range_opt ::=", - /* 436 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", - /* 437 */ "every_opt ::=", - /* 438 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 439 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 440 */ "query_expression_body ::= query_primary", - /* 441 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 442 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 443 */ "query_primary ::= query_specification", - /* 444 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 445 */ "order_by_clause_opt ::=", - /* 446 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 447 */ "slimit_clause_opt ::=", - /* 448 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 449 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 450 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 451 */ "limit_clause_opt ::=", - /* 452 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 453 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 454 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 455 */ "subquery ::= NK_LP query_expression NK_RP", - /* 456 */ "search_condition ::= common_expression", - /* 457 */ "sort_specification_list ::= sort_specification", - /* 458 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 459 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 460 */ "ordering_specification_opt ::=", - /* 461 */ "ordering_specification_opt ::= ASC", - /* 462 */ "ordering_specification_opt ::= DESC", - /* 463 */ "null_ordering_opt ::=", - /* 464 */ "null_ordering_opt ::= NULLS FIRST", - /* 465 */ "null_ordering_opt ::= NULLS LAST", + /* 26 */ "cmd ::= ALTER USER user_name ENABLE NK_INTEGER", + /* 27 */ "cmd ::= ALTER USER user_name SYSINFO NK_INTEGER", + /* 28 */ "cmd ::= DROP USER user_name", + /* 29 */ "sysinfo_opt ::=", + /* 30 */ "sysinfo_opt ::= SYSINFO NK_INTEGER", + /* 31 */ "cmd ::= GRANT privileges ON priv_level TO user_name", + /* 32 */ "cmd ::= REVOKE privileges ON priv_level FROM user_name", + /* 33 */ "privileges ::= ALL", + /* 34 */ "privileges ::= priv_type_list", + /* 35 */ "priv_type_list ::= priv_type", + /* 36 */ "priv_type_list ::= priv_type_list NK_COMMA priv_type", + /* 37 */ "priv_type ::= READ", + /* 38 */ "priv_type ::= WRITE", + /* 39 */ "priv_level ::= NK_STAR NK_DOT NK_STAR", + /* 40 */ "priv_level ::= db_name NK_DOT NK_STAR", + /* 41 */ "cmd ::= CREATE DNODE dnode_endpoint", + /* 42 */ "cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER", + /* 43 */ "cmd ::= DROP DNODE NK_INTEGER", + /* 44 */ "cmd ::= DROP DNODE dnode_endpoint", + /* 45 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING", + /* 46 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING", + /* 47 */ "cmd ::= ALTER ALL DNODES NK_STRING", + /* 48 */ "cmd ::= ALTER ALL DNODES NK_STRING NK_STRING", + /* 49 */ "dnode_endpoint ::= NK_STRING", + /* 50 */ "dnode_endpoint ::= NK_ID", + /* 51 */ "dnode_endpoint ::= NK_IPTOKEN", + /* 52 */ "cmd ::= ALTER LOCAL NK_STRING", + /* 53 */ "cmd ::= ALTER LOCAL NK_STRING NK_STRING", + /* 54 */ "cmd ::= CREATE QNODE ON DNODE NK_INTEGER", + /* 55 */ "cmd ::= DROP QNODE ON DNODE NK_INTEGER", + /* 56 */ "cmd ::= CREATE BNODE ON DNODE NK_INTEGER", + /* 57 */ "cmd ::= DROP BNODE ON DNODE NK_INTEGER", + /* 58 */ "cmd ::= CREATE SNODE ON DNODE NK_INTEGER", + /* 59 */ "cmd ::= DROP SNODE ON DNODE NK_INTEGER", + /* 60 */ "cmd ::= CREATE MNODE ON DNODE NK_INTEGER", + /* 61 */ "cmd ::= DROP MNODE ON DNODE NK_INTEGER", + /* 62 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", + /* 63 */ "cmd ::= DROP DATABASE exists_opt db_name", + /* 64 */ "cmd ::= USE db_name", + /* 65 */ "cmd ::= ALTER DATABASE db_name alter_db_options", + /* 66 */ "not_exists_opt ::= IF NOT EXISTS", + /* 67 */ "not_exists_opt ::=", + /* 68 */ "exists_opt ::= IF EXISTS", + /* 69 */ "exists_opt ::=", + /* 70 */ "db_options ::=", + /* 71 */ "db_options ::= db_options BUFFER NK_INTEGER", + /* 72 */ "db_options ::= db_options CACHELAST NK_INTEGER", + /* 73 */ "db_options ::= db_options COMP NK_INTEGER", + /* 74 */ "db_options ::= db_options DURATION NK_INTEGER", + /* 75 */ "db_options ::= db_options DURATION NK_VARIABLE", + /* 76 */ "db_options ::= db_options FSYNC NK_INTEGER", + /* 77 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 78 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 79 */ "db_options ::= db_options KEEP integer_list", + /* 80 */ "db_options ::= db_options KEEP variable_list", + /* 81 */ "db_options ::= db_options PAGES NK_INTEGER", + /* 82 */ "db_options ::= db_options PAGESIZE NK_INTEGER", + /* 83 */ "db_options ::= db_options PRECISION NK_STRING", + /* 84 */ "db_options ::= db_options REPLICA NK_INTEGER", + /* 85 */ "db_options ::= db_options STRICT NK_INTEGER", + /* 86 */ "db_options ::= db_options WAL NK_INTEGER", + /* 87 */ "db_options ::= db_options VGROUPS NK_INTEGER", + /* 88 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", + /* 89 */ "db_options ::= db_options RETENTIONS retention_list", + /* 90 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", + /* 91 */ "alter_db_options ::= alter_db_option", + /* 92 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 93 */ "alter_db_option ::= BUFFER NK_INTEGER", + /* 94 */ "alter_db_option ::= CACHELAST NK_INTEGER", + /* 95 */ "alter_db_option ::= FSYNC NK_INTEGER", + /* 96 */ "alter_db_option ::= KEEP integer_list", + /* 97 */ "alter_db_option ::= KEEP variable_list", + /* 98 */ "alter_db_option ::= PAGES NK_INTEGER", + /* 99 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 100 */ "alter_db_option ::= STRICT NK_INTEGER", + /* 101 */ "alter_db_option ::= WAL NK_INTEGER", + /* 102 */ "integer_list ::= NK_INTEGER", + /* 103 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 104 */ "variable_list ::= NK_VARIABLE", + /* 105 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 106 */ "retention_list ::= retention", + /* 107 */ "retention_list ::= retention_list NK_COMMA retention", + /* 108 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 109 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 110 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 111 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 112 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 113 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 114 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 115 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 116 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 117 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 118 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 119 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 120 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 121 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 122 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 123 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 124 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 125 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", + /* 126 */ "multi_create_clause ::= create_subtable_clause", + /* 127 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 128 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options", + /* 129 */ "multi_drop_clause ::= drop_table_clause", + /* 130 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 131 */ "drop_table_clause ::= exists_opt full_table_name", + /* 132 */ "specific_tags_opt ::=", + /* 133 */ "specific_tags_opt ::= NK_LP col_name_list NK_RP", + /* 134 */ "full_table_name ::= table_name", + /* 135 */ "full_table_name ::= db_name NK_DOT table_name", + /* 136 */ "column_def_list ::= column_def", + /* 137 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 138 */ "column_def ::= column_name type_name", + /* 139 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 140 */ "type_name ::= BOOL", + /* 141 */ "type_name ::= TINYINT", + /* 142 */ "type_name ::= SMALLINT", + /* 143 */ "type_name ::= INT", + /* 144 */ "type_name ::= INTEGER", + /* 145 */ "type_name ::= BIGINT", + /* 146 */ "type_name ::= FLOAT", + /* 147 */ "type_name ::= DOUBLE", + /* 148 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 149 */ "type_name ::= TIMESTAMP", + /* 150 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 151 */ "type_name ::= TINYINT UNSIGNED", + /* 152 */ "type_name ::= SMALLINT UNSIGNED", + /* 153 */ "type_name ::= INT UNSIGNED", + /* 154 */ "type_name ::= BIGINT UNSIGNED", + /* 155 */ "type_name ::= JSON", + /* 156 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 157 */ "type_name ::= MEDIUMBLOB", + /* 158 */ "type_name ::= BLOB", + /* 159 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 160 */ "type_name ::= DECIMAL", + /* 161 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 162 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 163 */ "tags_def_opt ::=", + /* 164 */ "tags_def_opt ::= tags_def", + /* 165 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 166 */ "table_options ::=", + /* 167 */ "table_options ::= table_options COMMENT NK_STRING", + /* 168 */ "table_options ::= table_options MAX_DELAY duration_list", + /* 169 */ "table_options ::= table_options WATERMARK duration_list", + /* 170 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", + /* 171 */ "table_options ::= table_options TTL NK_INTEGER", + /* 172 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 173 */ "alter_table_options ::= alter_table_option", + /* 174 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 175 */ "alter_table_option ::= COMMENT NK_STRING", + /* 176 */ "alter_table_option ::= TTL NK_INTEGER", + /* 177 */ "duration_list ::= duration_literal", + /* 178 */ "duration_list ::= duration_list NK_COMMA duration_literal", + /* 179 */ "rollup_func_list ::= rollup_func_name", + /* 180 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", + /* 181 */ "rollup_func_name ::= function_name", + /* 182 */ "rollup_func_name ::= FIRST", + /* 183 */ "rollup_func_name ::= LAST", + /* 184 */ "col_name_list ::= col_name", + /* 185 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 186 */ "col_name ::= column_name", + /* 187 */ "cmd ::= SHOW DNODES", + /* 188 */ "cmd ::= SHOW USERS", + /* 189 */ "cmd ::= SHOW DATABASES", + /* 190 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 191 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 192 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 193 */ "cmd ::= SHOW MNODES", + /* 194 */ "cmd ::= SHOW MODULES", + /* 195 */ "cmd ::= SHOW QNODES", + /* 196 */ "cmd ::= SHOW FUNCTIONS", + /* 197 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 198 */ "cmd ::= SHOW STREAMS", + /* 199 */ "cmd ::= SHOW ACCOUNTS", + /* 200 */ "cmd ::= SHOW APPS", + /* 201 */ "cmd ::= SHOW CONNECTIONS", + /* 202 */ "cmd ::= SHOW LICENCE", + /* 203 */ "cmd ::= SHOW GRANTS", + /* 204 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 205 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 206 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 207 */ "cmd ::= SHOW QUERIES", + /* 208 */ "cmd ::= SHOW SCORES", + /* 209 */ "cmd ::= SHOW TOPICS", + /* 210 */ "cmd ::= SHOW VARIABLES", + /* 211 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 212 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES", + /* 213 */ "cmd ::= SHOW BNODES", + /* 214 */ "cmd ::= SHOW SNODES", + /* 215 */ "cmd ::= SHOW CLUSTER", + /* 216 */ "cmd ::= SHOW TRANSACTIONS", + /* 217 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 218 */ "cmd ::= SHOW CONSUMERS", + /* 219 */ "cmd ::= SHOW SUBSCRIPTIONS", + /* 220 */ "db_name_cond_opt ::=", + /* 221 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 222 */ "like_pattern_opt ::=", + /* 223 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 224 */ "table_name_cond ::= table_name", + /* 225 */ "from_db_opt ::=", + /* 226 */ "from_db_opt ::= FROM db_name", + /* 227 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 228 */ "cmd ::= DROP INDEX exists_opt index_name", + /* 229 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", + /* 230 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", + /* 231 */ "func_list ::= func", + /* 232 */ "func_list ::= func_list NK_COMMA func", + /* 233 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 234 */ "sma_stream_opt ::=", + /* 235 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", + /* 236 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", + /* 237 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 238 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 239 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", + /* 240 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 241 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", + /* 242 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 243 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 244 */ "cmd ::= DESC full_table_name", + /* 245 */ "cmd ::= DESCRIBE full_table_name", + /* 246 */ "cmd ::= RESET QUERY CACHE", + /* 247 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 248 */ "analyze_opt ::=", + /* 249 */ "analyze_opt ::= ANALYZE", + /* 250 */ "explain_options ::=", + /* 251 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 252 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 253 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 254 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 255 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 256 */ "agg_func_opt ::=", + /* 257 */ "agg_func_opt ::= AGGREGATE", + /* 258 */ "bufsize_opt ::=", + /* 259 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 260 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 261 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 262 */ "into_opt ::=", + /* 263 */ "into_opt ::= INTO full_table_name", + /* 264 */ "stream_options ::=", + /* 265 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 266 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 267 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 268 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 269 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 270 */ "cmd ::= KILL QUERY NK_STRING", + /* 271 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 272 */ "cmd ::= BALANCE VGROUP", + /* 273 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 274 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 275 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 276 */ "dnode_list ::= DNODE NK_INTEGER", + /* 277 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 278 */ "cmd ::= SYNCDB db_name REPLICA", + /* 279 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 280 */ "cmd ::= query_expression", + /* 281 */ "literal ::= NK_INTEGER", + /* 282 */ "literal ::= NK_FLOAT", + /* 283 */ "literal ::= NK_STRING", + /* 284 */ "literal ::= NK_BOOL", + /* 285 */ "literal ::= TIMESTAMP NK_STRING", + /* 286 */ "literal ::= duration_literal", + /* 287 */ "literal ::= NULL", + /* 288 */ "literal ::= NK_QUESTION", + /* 289 */ "duration_literal ::= NK_VARIABLE", + /* 290 */ "signed ::= NK_INTEGER", + /* 291 */ "signed ::= NK_PLUS NK_INTEGER", + /* 292 */ "signed ::= NK_MINUS NK_INTEGER", + /* 293 */ "signed ::= NK_FLOAT", + /* 294 */ "signed ::= NK_PLUS NK_FLOAT", + /* 295 */ "signed ::= NK_MINUS NK_FLOAT", + /* 296 */ "signed_literal ::= signed", + /* 297 */ "signed_literal ::= NK_STRING", + /* 298 */ "signed_literal ::= NK_BOOL", + /* 299 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 300 */ "signed_literal ::= duration_literal", + /* 301 */ "signed_literal ::= NULL", + /* 302 */ "signed_literal ::= literal_func", + /* 303 */ "literal_list ::= signed_literal", + /* 304 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 305 */ "db_name ::= NK_ID", + /* 306 */ "table_name ::= NK_ID", + /* 307 */ "column_name ::= NK_ID", + /* 308 */ "function_name ::= NK_ID", + /* 309 */ "table_alias ::= NK_ID", + /* 310 */ "column_alias ::= NK_ID", + /* 311 */ "user_name ::= NK_ID", + /* 312 */ "index_name ::= NK_ID", + /* 313 */ "topic_name ::= NK_ID", + /* 314 */ "stream_name ::= NK_ID", + /* 315 */ "cgroup_name ::= NK_ID", + /* 316 */ "expression ::= literal", + /* 317 */ "expression ::= pseudo_column", + /* 318 */ "expression ::= column_reference", + /* 319 */ "expression ::= function_expression", + /* 320 */ "expression ::= subquery", + /* 321 */ "expression ::= NK_LP expression NK_RP", + /* 322 */ "expression ::= NK_PLUS expression", + /* 323 */ "expression ::= NK_MINUS expression", + /* 324 */ "expression ::= expression NK_PLUS expression", + /* 325 */ "expression ::= expression NK_MINUS expression", + /* 326 */ "expression ::= expression NK_STAR expression", + /* 327 */ "expression ::= expression NK_SLASH expression", + /* 328 */ "expression ::= expression NK_REM expression", + /* 329 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 330 */ "expression ::= expression NK_BITAND expression", + /* 331 */ "expression ::= expression NK_BITOR expression", + /* 332 */ "expression_list ::= expression", + /* 333 */ "expression_list ::= expression_list NK_COMMA expression", + /* 334 */ "column_reference ::= column_name", + /* 335 */ "column_reference ::= table_name NK_DOT column_name", + /* 336 */ "pseudo_column ::= ROWTS", + /* 337 */ "pseudo_column ::= TBNAME", + /* 338 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 339 */ "pseudo_column ::= QSTARTTS", + /* 340 */ "pseudo_column ::= QENDTS", + /* 341 */ "pseudo_column ::= WSTARTTS", + /* 342 */ "pseudo_column ::= WENDTS", + /* 343 */ "pseudo_column ::= WDURATION", + /* 344 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 345 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 346 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 347 */ "function_expression ::= literal_func", + /* 348 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 349 */ "literal_func ::= NOW", + /* 350 */ "noarg_func ::= NOW", + /* 351 */ "noarg_func ::= TODAY", + /* 352 */ "noarg_func ::= TIMEZONE", + /* 353 */ "star_func ::= COUNT", + /* 354 */ "star_func ::= FIRST", + /* 355 */ "star_func ::= LAST", + /* 356 */ "star_func ::= LAST_ROW", + /* 357 */ "star_func_para_list ::= NK_STAR", + /* 358 */ "star_func_para_list ::= other_para_list", + /* 359 */ "other_para_list ::= star_func_para", + /* 360 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 361 */ "star_func_para ::= expression", + /* 362 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 363 */ "predicate ::= expression compare_op expression", + /* 364 */ "predicate ::= expression BETWEEN expression AND expression", + /* 365 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 366 */ "predicate ::= expression IS NULL", + /* 367 */ "predicate ::= expression IS NOT NULL", + /* 368 */ "predicate ::= expression in_op in_predicate_value", + /* 369 */ "compare_op ::= NK_LT", + /* 370 */ "compare_op ::= NK_GT", + /* 371 */ "compare_op ::= NK_LE", + /* 372 */ "compare_op ::= NK_GE", + /* 373 */ "compare_op ::= NK_NE", + /* 374 */ "compare_op ::= NK_EQ", + /* 375 */ "compare_op ::= LIKE", + /* 376 */ "compare_op ::= NOT LIKE", + /* 377 */ "compare_op ::= MATCH", + /* 378 */ "compare_op ::= NMATCH", + /* 379 */ "compare_op ::= CONTAINS", + /* 380 */ "in_op ::= IN", + /* 381 */ "in_op ::= NOT IN", + /* 382 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 383 */ "boolean_value_expression ::= boolean_primary", + /* 384 */ "boolean_value_expression ::= NOT boolean_primary", + /* 385 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 386 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 387 */ "boolean_primary ::= predicate", + /* 388 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 389 */ "common_expression ::= expression", + /* 390 */ "common_expression ::= boolean_value_expression", + /* 391 */ "from_clause_opt ::=", + /* 392 */ "from_clause_opt ::= FROM table_reference_list", + /* 393 */ "table_reference_list ::= table_reference", + /* 394 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 395 */ "table_reference ::= table_primary", + /* 396 */ "table_reference ::= joined_table", + /* 397 */ "table_primary ::= table_name alias_opt", + /* 398 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 399 */ "table_primary ::= subquery alias_opt", + /* 400 */ "table_primary ::= parenthesized_joined_table", + /* 401 */ "alias_opt ::=", + /* 402 */ "alias_opt ::= table_alias", + /* 403 */ "alias_opt ::= AS table_alias", + /* 404 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 405 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 406 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 407 */ "join_type ::=", + /* 408 */ "join_type ::= INNER", + /* 409 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 410 */ "set_quantifier_opt ::=", + /* 411 */ "set_quantifier_opt ::= DISTINCT", + /* 412 */ "set_quantifier_opt ::= ALL", + /* 413 */ "select_list ::= NK_STAR", + /* 414 */ "select_list ::= select_sublist", + /* 415 */ "select_sublist ::= select_item", + /* 416 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 417 */ "select_item ::= common_expression", + /* 418 */ "select_item ::= common_expression column_alias", + /* 419 */ "select_item ::= common_expression AS column_alias", + /* 420 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 421 */ "where_clause_opt ::=", + /* 422 */ "where_clause_opt ::= WHERE search_condition", + /* 423 */ "partition_by_clause_opt ::=", + /* 424 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 425 */ "twindow_clause_opt ::=", + /* 426 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 427 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 428 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 429 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 430 */ "sliding_opt ::=", + /* 431 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 432 */ "fill_opt ::=", + /* 433 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 434 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 435 */ "fill_mode ::= NONE", + /* 436 */ "fill_mode ::= PREV", + /* 437 */ "fill_mode ::= NULL", + /* 438 */ "fill_mode ::= LINEAR", + /* 439 */ "fill_mode ::= NEXT", + /* 440 */ "group_by_clause_opt ::=", + /* 441 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 442 */ "group_by_list ::= expression", + /* 443 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 444 */ "having_clause_opt ::=", + /* 445 */ "having_clause_opt ::= HAVING search_condition", + /* 446 */ "range_opt ::=", + /* 447 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", + /* 448 */ "every_opt ::=", + /* 449 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 450 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 451 */ "query_expression_body ::= query_primary", + /* 452 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 453 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 454 */ "query_primary ::= query_specification", + /* 455 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", + /* 456 */ "order_by_clause_opt ::=", + /* 457 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 458 */ "slimit_clause_opt ::=", + /* 459 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 460 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 461 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 462 */ "limit_clause_opt ::=", + /* 463 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 464 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 465 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 466 */ "subquery ::= NK_LP query_expression NK_RP", + /* 467 */ "search_condition ::= common_expression", + /* 468 */ "sort_specification_list ::= sort_specification", + /* 469 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 470 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 471 */ "ordering_specification_opt ::=", + /* 472 */ "ordering_specification_opt ::= ASC", + /* 473 */ "ordering_specification_opt ::= DESC", + /* 474 */ "null_ordering_opt ::=", + /* 475 */ "null_ordering_opt ::= NULLS FIRST", + /* 476 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2139,176 +2165,182 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 242: /* cmd */ - case 245: /* literal */ - case 255: /* db_options */ - case 257: /* alter_db_options */ - case 262: /* retention */ - case 263: /* full_table_name */ - case 266: /* table_options */ - case 270: /* alter_table_clause */ - case 271: /* alter_table_options */ - case 274: /* signed_literal */ - case 275: /* create_subtable_clause */ - case 278: /* drop_table_clause */ - case 281: /* column_def */ - case 285: /* duration_literal */ - case 286: /* rollup_func_name */ - case 288: /* col_name */ - case 289: /* db_name_cond_opt */ - case 290: /* like_pattern_opt */ - case 291: /* table_name_cond */ - case 292: /* from_db_opt */ - case 294: /* index_options */ - case 296: /* sliding_opt */ - case 297: /* func */ - case 300: /* query_expression */ - case 303: /* explain_options */ - case 307: /* stream_options */ - case 308: /* into_opt */ - case 310: /* where_clause_opt */ - case 311: /* signed */ - case 312: /* literal_func */ - case 315: /* expression */ - case 316: /* pseudo_column */ - case 317: /* column_reference */ - case 318: /* function_expression */ - case 319: /* subquery */ - case 324: /* star_func_para */ - case 325: /* predicate */ - case 328: /* in_predicate_value */ - case 329: /* boolean_value_expression */ - case 330: /* boolean_primary */ - case 331: /* common_expression */ - case 332: /* from_clause */ - case 333: /* table_reference_list */ - case 334: /* table_reference */ - case 335: /* table_primary */ - case 336: /* joined_table */ - case 338: /* parenthesized_joined_table */ - case 340: /* search_condition */ - case 341: /* query_specification */ - case 345: /* range_opt */ - case 346: /* every_opt */ - case 347: /* fill_opt */ - case 348: /* twindow_clause_opt */ - case 350: /* having_clause_opt */ - case 352: /* select_item */ - case 355: /* query_expression_body */ - case 357: /* slimit_clause_opt */ - case 358: /* limit_clause_opt */ - case 359: /* query_primary */ - case 361: /* sort_specification */ + case 246: /* cmd */ + case 249: /* literal */ + case 260: /* db_options */ + case 262: /* alter_db_options */ + case 267: /* retention */ + case 268: /* full_table_name */ + case 271: /* table_options */ + case 275: /* alter_table_clause */ + case 276: /* alter_table_options */ + case 279: /* signed_literal */ + case 280: /* create_subtable_clause */ + case 283: /* drop_table_clause */ + case 286: /* column_def */ + case 290: /* duration_literal */ + case 291: /* rollup_func_name */ + case 293: /* col_name */ + case 294: /* db_name_cond_opt */ + case 295: /* like_pattern_opt */ + case 296: /* table_name_cond */ + case 297: /* from_db_opt */ + case 299: /* index_options */ + case 301: /* sliding_opt */ + case 302: /* sma_stream_opt */ + case 303: /* func */ + case 305: /* stream_options */ + case 307: /* query_expression */ + case 310: /* explain_options */ + case 314: /* into_opt */ + case 316: /* where_clause_opt */ + case 317: /* signed */ + case 318: /* literal_func */ + case 321: /* expression */ + case 322: /* pseudo_column */ + case 323: /* column_reference */ + case 324: /* function_expression */ + case 325: /* subquery */ + case 330: /* star_func_para */ + case 331: /* predicate */ + case 334: /* in_predicate_value */ + case 335: /* boolean_value_expression */ + case 336: /* boolean_primary */ + case 337: /* common_expression */ + case 338: /* from_clause_opt */ + case 339: /* table_reference_list */ + case 340: /* table_reference */ + case 341: /* table_primary */ + case 342: /* joined_table */ + case 344: /* parenthesized_joined_table */ + case 346: /* search_condition */ + case 347: /* query_specification */ + case 351: /* range_opt */ + case 352: /* every_opt */ + case 353: /* fill_opt */ + case 354: /* twindow_clause_opt */ + case 356: /* having_clause_opt */ + case 358: /* select_item */ + case 361: /* query_expression_body */ + case 363: /* slimit_clause_opt */ + case 364: /* limit_clause_opt */ + case 365: /* query_primary */ + case 367: /* sort_specification */ { - nodesDestroyNode((yypminor->yy392)); + nodesDestroyNode((yypminor->yy452)); } break; - case 243: /* account_options */ - case 244: /* alter_account_options */ - case 246: /* alter_account_option */ - case 305: /* bufsize_opt */ + case 247: /* account_options */ + case 248: /* alter_account_options */ + case 250: /* alter_account_option */ + case 312: /* bufsize_opt */ { } break; - case 247: /* user_name */ - case 249: /* priv_level */ - case 252: /* db_name */ - case 253: /* dnode_endpoint */ - case 272: /* column_name */ - case 280: /* table_name */ - case 287: /* function_name */ - case 293: /* index_name */ - case 299: /* topic_name */ - case 301: /* cgroup_name */ - case 306: /* stream_name */ - case 313: /* table_alias */ - case 314: /* column_alias */ - case 320: /* star_func */ - case 322: /* noarg_func */ - case 337: /* alias_opt */ + case 251: /* user_name */ + case 254: /* priv_level */ + case 257: /* db_name */ + case 258: /* dnode_endpoint */ + case 277: /* column_name */ + case 285: /* table_name */ + case 292: /* function_name */ + case 298: /* index_name */ + case 306: /* topic_name */ + case 308: /* cgroup_name */ + case 313: /* stream_name */ + case 319: /* table_alias */ + case 320: /* column_alias */ + case 326: /* star_func */ + case 328: /* noarg_func */ + case 343: /* alias_opt */ { } break; - case 248: /* privileges */ - case 250: /* priv_type_list */ - case 251: /* priv_type */ + case 252: /* sysinfo_opt */ { } break; - case 254: /* not_exists_opt */ - case 256: /* exists_opt */ - case 302: /* analyze_opt */ - case 304: /* agg_func_opt */ - case 342: /* set_quantifier_opt */ + case 253: /* privileges */ + case 255: /* priv_type_list */ + case 256: /* priv_type */ { } break; - case 258: /* integer_list */ - case 259: /* variable_list */ - case 260: /* retention_list */ - case 264: /* column_def_list */ - case 265: /* tags_def_opt */ - case 267: /* multi_create_clause */ - case 268: /* tags_def */ - case 269: /* multi_drop_clause */ - case 276: /* specific_tags_opt */ - case 277: /* literal_list */ - case 279: /* col_name_list */ - case 282: /* duration_list */ - case 283: /* rollup_func_list */ - case 295: /* func_list */ - case 298: /* expression_list */ - case 309: /* dnode_list */ - case 321: /* star_func_para_list */ - case 323: /* other_para_list */ - case 343: /* select_list */ - case 344: /* partition_by_clause_opt */ - case 349: /* group_by_clause_opt */ - case 351: /* select_sublist */ - case 354: /* group_by_list */ - case 356: /* order_by_clause_opt */ - case 360: /* sort_specification_list */ -{ - nodesDestroyList((yypminor->yy600)); -} - break; - case 261: /* alter_db_option */ - case 284: /* alter_table_option */ + case 259: /* not_exists_opt */ + case 261: /* exists_opt */ + case 309: /* analyze_opt */ + case 311: /* agg_func_opt */ + case 348: /* set_quantifier_opt */ { } break; - case 273: /* type_name */ + case 263: /* integer_list */ + case 264: /* variable_list */ + case 265: /* retention_list */ + case 269: /* column_def_list */ + case 270: /* tags_def_opt */ + case 272: /* multi_create_clause */ + case 273: /* tags_def */ + case 274: /* multi_drop_clause */ + case 281: /* specific_tags_opt */ + case 282: /* literal_list */ + case 284: /* col_name_list */ + case 287: /* duration_list */ + case 288: /* rollup_func_list */ + case 300: /* func_list */ + case 304: /* expression_list */ + case 315: /* dnode_list */ + case 327: /* star_func_para_list */ + case 329: /* other_para_list */ + case 349: /* select_list */ + case 350: /* partition_by_clause_opt */ + case 355: /* group_by_clause_opt */ + case 357: /* select_sublist */ + case 360: /* group_by_list */ + case 362: /* order_by_clause_opt */ + case 366: /* sort_specification_list */ +{ + nodesDestroyList((yypminor->yy404)); +} + break; + case 266: /* alter_db_option */ + case 289: /* alter_table_option */ { } break; - case 326: /* compare_op */ - case 327: /* in_op */ + case 278: /* type_name */ { } break; - case 339: /* join_type */ + case 332: /* compare_op */ + case 333: /* in_op */ { } break; - case 353: /* fill_mode */ + case 345: /* join_type */ { } break; - case 362: /* ordering_specification_opt */ + case 359: /* fill_mode */ { } break; - case 363: /* null_ordering_opt */ + case 368: /* ordering_specification_opt */ +{ + +} + break; + case 369: /* null_ordering_opt */ { } @@ -2607,472 +2639,483 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 242, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 242, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 243, 0 }, /* (2) account_options ::= */ - { 243, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 243, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 243, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 243, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 243, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 243, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 243, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 243, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 243, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 244, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 244, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 246, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 246, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 246, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 246, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 246, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 246, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 246, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 246, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 246, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 246, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 242, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 242, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 242, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 242, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 242, -6 }, /* (28) cmd ::= GRANT privileges ON priv_level TO user_name */ - { 242, -6 }, /* (29) cmd ::= REVOKE privileges ON priv_level FROM user_name */ - { 248, -1 }, /* (30) privileges ::= ALL */ - { 248, -1 }, /* (31) privileges ::= priv_type_list */ - { 250, -1 }, /* (32) priv_type_list ::= priv_type */ - { 250, -3 }, /* (33) priv_type_list ::= priv_type_list NK_COMMA priv_type */ - { 251, -1 }, /* (34) priv_type ::= READ */ - { 251, -1 }, /* (35) priv_type ::= WRITE */ - { 249, -3 }, /* (36) priv_level ::= NK_STAR NK_DOT NK_STAR */ - { 249, -3 }, /* (37) priv_level ::= db_name NK_DOT NK_STAR */ - { 242, -3 }, /* (38) cmd ::= CREATE DNODE dnode_endpoint */ - { 242, -5 }, /* (39) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ - { 242, -3 }, /* (40) cmd ::= DROP DNODE NK_INTEGER */ - { 242, -3 }, /* (41) cmd ::= DROP DNODE dnode_endpoint */ - { 242, -4 }, /* (42) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 242, -5 }, /* (43) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 242, -4 }, /* (44) cmd ::= ALTER ALL DNODES NK_STRING */ - { 242, -5 }, /* (45) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 253, -1 }, /* (46) dnode_endpoint ::= NK_STRING */ - { 253, -1 }, /* (47) dnode_endpoint ::= NK_ID */ - { 253, -1 }, /* (48) dnode_endpoint ::= NK_IPTOKEN */ - { 242, -3 }, /* (49) cmd ::= ALTER LOCAL NK_STRING */ - { 242, -4 }, /* (50) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 242, -5 }, /* (51) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (52) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (53) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (54) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (55) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (56) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (57) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (58) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 242, -5 }, /* (59) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 242, -4 }, /* (60) cmd ::= DROP DATABASE exists_opt db_name */ - { 242, -2 }, /* (61) cmd ::= USE db_name */ - { 242, -4 }, /* (62) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 254, -3 }, /* (63) not_exists_opt ::= IF NOT EXISTS */ - { 254, 0 }, /* (64) not_exists_opt ::= */ - { 256, -2 }, /* (65) exists_opt ::= IF EXISTS */ - { 256, 0 }, /* (66) exists_opt ::= */ - { 255, 0 }, /* (67) db_options ::= */ - { 255, -3 }, /* (68) db_options ::= db_options BUFFER NK_INTEGER */ - { 255, -3 }, /* (69) db_options ::= db_options CACHELAST NK_INTEGER */ - { 255, -3 }, /* (70) db_options ::= db_options COMP NK_INTEGER */ - { 255, -3 }, /* (71) db_options ::= db_options DURATION NK_INTEGER */ - { 255, -3 }, /* (72) db_options ::= db_options DURATION NK_VARIABLE */ - { 255, -3 }, /* (73) db_options ::= db_options FSYNC NK_INTEGER */ - { 255, -3 }, /* (74) db_options ::= db_options MAXROWS NK_INTEGER */ - { 255, -3 }, /* (75) db_options ::= db_options MINROWS NK_INTEGER */ - { 255, -3 }, /* (76) db_options ::= db_options KEEP integer_list */ - { 255, -3 }, /* (77) db_options ::= db_options KEEP variable_list */ - { 255, -3 }, /* (78) db_options ::= db_options PAGES NK_INTEGER */ - { 255, -3 }, /* (79) db_options ::= db_options PAGESIZE NK_INTEGER */ - { 255, -3 }, /* (80) db_options ::= db_options PRECISION NK_STRING */ - { 255, -3 }, /* (81) db_options ::= db_options REPLICA NK_INTEGER */ - { 255, -3 }, /* (82) db_options ::= db_options STRICT NK_INTEGER */ - { 255, -3 }, /* (83) db_options ::= db_options WAL NK_INTEGER */ - { 255, -3 }, /* (84) db_options ::= db_options VGROUPS NK_INTEGER */ - { 255, -3 }, /* (85) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 255, -3 }, /* (86) db_options ::= db_options RETENTIONS retention_list */ - { 255, -3 }, /* (87) db_options ::= db_options SCHEMALESS NK_INTEGER */ - { 257, -1 }, /* (88) alter_db_options ::= alter_db_option */ - { 257, -2 }, /* (89) alter_db_options ::= alter_db_options alter_db_option */ - { 261, -2 }, /* (90) alter_db_option ::= BUFFER NK_INTEGER */ - { 261, -2 }, /* (91) alter_db_option ::= CACHELAST NK_INTEGER */ - { 261, -2 }, /* (92) alter_db_option ::= FSYNC NK_INTEGER */ - { 261, -2 }, /* (93) alter_db_option ::= KEEP integer_list */ - { 261, -2 }, /* (94) alter_db_option ::= KEEP variable_list */ - { 261, -2 }, /* (95) alter_db_option ::= PAGES NK_INTEGER */ - { 261, -2 }, /* (96) alter_db_option ::= REPLICA NK_INTEGER */ - { 261, -2 }, /* (97) alter_db_option ::= STRICT NK_INTEGER */ - { 261, -2 }, /* (98) alter_db_option ::= WAL NK_INTEGER */ - { 258, -1 }, /* (99) integer_list ::= NK_INTEGER */ - { 258, -3 }, /* (100) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 259, -1 }, /* (101) variable_list ::= NK_VARIABLE */ - { 259, -3 }, /* (102) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 260, -1 }, /* (103) retention_list ::= retention */ - { 260, -3 }, /* (104) retention_list ::= retention_list NK_COMMA retention */ - { 262, -3 }, /* (105) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 242, -9 }, /* (106) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 242, -3 }, /* (107) cmd ::= CREATE TABLE multi_create_clause */ - { 242, -9 }, /* (108) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 242, -3 }, /* (109) cmd ::= DROP TABLE multi_drop_clause */ - { 242, -4 }, /* (110) cmd ::= DROP STABLE exists_opt full_table_name */ - { 242, -3 }, /* (111) cmd ::= ALTER TABLE alter_table_clause */ - { 242, -3 }, /* (112) cmd ::= ALTER STABLE alter_table_clause */ - { 270, -2 }, /* (113) alter_table_clause ::= full_table_name alter_table_options */ - { 270, -5 }, /* (114) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 270, -4 }, /* (115) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 270, -5 }, /* (116) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 270, -5 }, /* (117) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 270, -5 }, /* (118) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 270, -4 }, /* (119) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 270, -5 }, /* (120) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 270, -5 }, /* (121) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 270, -6 }, /* (122) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 267, -1 }, /* (123) multi_create_clause ::= create_subtable_clause */ - { 267, -2 }, /* (124) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 275, -10 }, /* (125) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ - { 269, -1 }, /* (126) multi_drop_clause ::= drop_table_clause */ - { 269, -2 }, /* (127) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 278, -2 }, /* (128) drop_table_clause ::= exists_opt full_table_name */ - { 276, 0 }, /* (129) specific_tags_opt ::= */ - { 276, -3 }, /* (130) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 263, -1 }, /* (131) full_table_name ::= table_name */ - { 263, -3 }, /* (132) full_table_name ::= db_name NK_DOT table_name */ - { 264, -1 }, /* (133) column_def_list ::= column_def */ - { 264, -3 }, /* (134) column_def_list ::= column_def_list NK_COMMA column_def */ - { 281, -2 }, /* (135) column_def ::= column_name type_name */ - { 281, -4 }, /* (136) column_def ::= column_name type_name COMMENT NK_STRING */ - { 273, -1 }, /* (137) type_name ::= BOOL */ - { 273, -1 }, /* (138) type_name ::= TINYINT */ - { 273, -1 }, /* (139) type_name ::= SMALLINT */ - { 273, -1 }, /* (140) type_name ::= INT */ - { 273, -1 }, /* (141) type_name ::= INTEGER */ - { 273, -1 }, /* (142) type_name ::= BIGINT */ - { 273, -1 }, /* (143) type_name ::= FLOAT */ - { 273, -1 }, /* (144) type_name ::= DOUBLE */ - { 273, -4 }, /* (145) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 273, -1 }, /* (146) type_name ::= TIMESTAMP */ - { 273, -4 }, /* (147) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 273, -2 }, /* (148) type_name ::= TINYINT UNSIGNED */ - { 273, -2 }, /* (149) type_name ::= SMALLINT UNSIGNED */ - { 273, -2 }, /* (150) type_name ::= INT UNSIGNED */ - { 273, -2 }, /* (151) type_name ::= BIGINT UNSIGNED */ - { 273, -1 }, /* (152) type_name ::= JSON */ - { 273, -4 }, /* (153) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 273, -1 }, /* (154) type_name ::= MEDIUMBLOB */ - { 273, -1 }, /* (155) type_name ::= BLOB */ - { 273, -4 }, /* (156) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 273, -1 }, /* (157) type_name ::= DECIMAL */ - { 273, -4 }, /* (158) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 273, -6 }, /* (159) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 265, 0 }, /* (160) tags_def_opt ::= */ - { 265, -1 }, /* (161) tags_def_opt ::= tags_def */ - { 268, -4 }, /* (162) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 266, 0 }, /* (163) table_options ::= */ - { 266, -3 }, /* (164) table_options ::= table_options COMMENT NK_STRING */ - { 266, -3 }, /* (165) table_options ::= table_options MAX_DELAY duration_list */ - { 266, -3 }, /* (166) table_options ::= table_options WATERMARK duration_list */ - { 266, -5 }, /* (167) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 266, -3 }, /* (168) table_options ::= table_options TTL NK_INTEGER */ - { 266, -5 }, /* (169) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 271, -1 }, /* (170) alter_table_options ::= alter_table_option */ - { 271, -2 }, /* (171) alter_table_options ::= alter_table_options alter_table_option */ - { 284, -2 }, /* (172) alter_table_option ::= COMMENT NK_STRING */ - { 284, -2 }, /* (173) alter_table_option ::= TTL NK_INTEGER */ - { 282, -1 }, /* (174) duration_list ::= duration_literal */ - { 282, -3 }, /* (175) duration_list ::= duration_list NK_COMMA duration_literal */ - { 283, -1 }, /* (176) rollup_func_list ::= rollup_func_name */ - { 283, -3 }, /* (177) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 286, -1 }, /* (178) rollup_func_name ::= function_name */ - { 286, -1 }, /* (179) rollup_func_name ::= FIRST */ - { 286, -1 }, /* (180) rollup_func_name ::= LAST */ - { 279, -1 }, /* (181) col_name_list ::= col_name */ - { 279, -3 }, /* (182) col_name_list ::= col_name_list NK_COMMA col_name */ - { 288, -1 }, /* (183) col_name ::= column_name */ - { 242, -2 }, /* (184) cmd ::= SHOW DNODES */ - { 242, -2 }, /* (185) cmd ::= SHOW USERS */ - { 242, -2 }, /* (186) cmd ::= SHOW DATABASES */ - { 242, -4 }, /* (187) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 242, -4 }, /* (188) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 242, -3 }, /* (189) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 242, -2 }, /* (190) cmd ::= SHOW MNODES */ - { 242, -2 }, /* (191) cmd ::= SHOW MODULES */ - { 242, -2 }, /* (192) cmd ::= SHOW QNODES */ - { 242, -2 }, /* (193) cmd ::= SHOW FUNCTIONS */ - { 242, -5 }, /* (194) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 242, -2 }, /* (195) cmd ::= SHOW STREAMS */ - { 242, -2 }, /* (196) cmd ::= SHOW ACCOUNTS */ - { 242, -2 }, /* (197) cmd ::= SHOW APPS */ - { 242, -2 }, /* (198) cmd ::= SHOW CONNECTIONS */ - { 242, -2 }, /* (199) cmd ::= SHOW LICENCE */ - { 242, -2 }, /* (200) cmd ::= SHOW GRANTS */ - { 242, -4 }, /* (201) cmd ::= SHOW CREATE DATABASE db_name */ - { 242, -4 }, /* (202) cmd ::= SHOW CREATE TABLE full_table_name */ - { 242, -4 }, /* (203) cmd ::= SHOW CREATE STABLE full_table_name */ - { 242, -2 }, /* (204) cmd ::= SHOW QUERIES */ - { 242, -2 }, /* (205) cmd ::= SHOW SCORES */ - { 242, -2 }, /* (206) cmd ::= SHOW TOPICS */ - { 242, -2 }, /* (207) cmd ::= SHOW VARIABLES */ - { 242, -3 }, /* (208) cmd ::= SHOW LOCAL VARIABLES */ - { 242, -4 }, /* (209) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ - { 242, -2 }, /* (210) cmd ::= SHOW BNODES */ - { 242, -2 }, /* (211) cmd ::= SHOW SNODES */ - { 242, -2 }, /* (212) cmd ::= SHOW CLUSTER */ - { 242, -2 }, /* (213) cmd ::= SHOW TRANSACTIONS */ - { 242, -4 }, /* (214) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ - { 289, 0 }, /* (215) db_name_cond_opt ::= */ - { 289, -2 }, /* (216) db_name_cond_opt ::= db_name NK_DOT */ - { 290, 0 }, /* (217) like_pattern_opt ::= */ - { 290, -2 }, /* (218) like_pattern_opt ::= LIKE NK_STRING */ - { 291, -1 }, /* (219) table_name_cond ::= table_name */ - { 292, 0 }, /* (220) from_db_opt ::= */ - { 292, -2 }, /* (221) from_db_opt ::= FROM db_name */ - { 242, -8 }, /* (222) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 242, -10 }, /* (223) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 242, -6 }, /* (224) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 294, 0 }, /* (225) index_options ::= */ - { 294, -9 }, /* (226) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 294, -11 }, /* (227) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 295, -1 }, /* (228) func_list ::= func */ - { 295, -3 }, /* (229) func_list ::= func_list NK_COMMA func */ - { 297, -4 }, /* (230) func ::= function_name NK_LP expression_list NK_RP */ - { 242, -6 }, /* (231) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 242, -7 }, /* (232) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 242, -7 }, /* (233) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 242, -4 }, /* (234) cmd ::= DROP TOPIC exists_opt topic_name */ - { 242, -7 }, /* (235) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 242, -2 }, /* (236) cmd ::= DESC full_table_name */ - { 242, -2 }, /* (237) cmd ::= DESCRIBE full_table_name */ - { 242, -3 }, /* (238) cmd ::= RESET QUERY CACHE */ - { 242, -4 }, /* (239) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 302, 0 }, /* (240) analyze_opt ::= */ - { 302, -1 }, /* (241) analyze_opt ::= ANALYZE */ - { 303, 0 }, /* (242) explain_options ::= */ - { 303, -3 }, /* (243) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 303, -3 }, /* (244) explain_options ::= explain_options RATIO NK_FLOAT */ - { 242, -6 }, /* (245) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 242, -10 }, /* (246) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 242, -4 }, /* (247) cmd ::= DROP FUNCTION exists_opt function_name */ - { 304, 0 }, /* (248) agg_func_opt ::= */ - { 304, -1 }, /* (249) agg_func_opt ::= AGGREGATE */ - { 305, 0 }, /* (250) bufsize_opt ::= */ - { 305, -2 }, /* (251) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 242, -8 }, /* (252) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 242, -4 }, /* (253) cmd ::= DROP STREAM exists_opt stream_name */ - { 308, 0 }, /* (254) into_opt ::= */ - { 308, -2 }, /* (255) into_opt ::= INTO full_table_name */ - { 307, 0 }, /* (256) stream_options ::= */ - { 307, -3 }, /* (257) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 307, -3 }, /* (258) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 307, -4 }, /* (259) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 307, -3 }, /* (260) stream_options ::= stream_options WATERMARK duration_literal */ - { 242, -3 }, /* (261) cmd ::= KILL CONNECTION NK_INTEGER */ - { 242, -3 }, /* (262) cmd ::= KILL QUERY NK_STRING */ - { 242, -3 }, /* (263) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 242, -2 }, /* (264) cmd ::= BALANCE VGROUP */ - { 242, -4 }, /* (265) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 242, -4 }, /* (266) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 242, -3 }, /* (267) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 309, -2 }, /* (268) dnode_list ::= DNODE NK_INTEGER */ - { 309, -3 }, /* (269) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 242, -3 }, /* (270) cmd ::= SYNCDB db_name REPLICA */ - { 242, -4 }, /* (271) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 242, -1 }, /* (272) cmd ::= query_expression */ - { 245, -1 }, /* (273) literal ::= NK_INTEGER */ - { 245, -1 }, /* (274) literal ::= NK_FLOAT */ - { 245, -1 }, /* (275) literal ::= NK_STRING */ - { 245, -1 }, /* (276) literal ::= NK_BOOL */ - { 245, -2 }, /* (277) literal ::= TIMESTAMP NK_STRING */ - { 245, -1 }, /* (278) literal ::= duration_literal */ - { 245, -1 }, /* (279) literal ::= NULL */ - { 245, -1 }, /* (280) literal ::= NK_QUESTION */ - { 285, -1 }, /* (281) duration_literal ::= NK_VARIABLE */ - { 311, -1 }, /* (282) signed ::= NK_INTEGER */ - { 311, -2 }, /* (283) signed ::= NK_PLUS NK_INTEGER */ - { 311, -2 }, /* (284) signed ::= NK_MINUS NK_INTEGER */ - { 311, -1 }, /* (285) signed ::= NK_FLOAT */ - { 311, -2 }, /* (286) signed ::= NK_PLUS NK_FLOAT */ - { 311, -2 }, /* (287) signed ::= NK_MINUS NK_FLOAT */ - { 274, -1 }, /* (288) signed_literal ::= signed */ - { 274, -1 }, /* (289) signed_literal ::= NK_STRING */ - { 274, -1 }, /* (290) signed_literal ::= NK_BOOL */ - { 274, -2 }, /* (291) signed_literal ::= TIMESTAMP NK_STRING */ - { 274, -1 }, /* (292) signed_literal ::= duration_literal */ - { 274, -1 }, /* (293) signed_literal ::= NULL */ - { 274, -1 }, /* (294) signed_literal ::= literal_func */ - { 277, -1 }, /* (295) literal_list ::= signed_literal */ - { 277, -3 }, /* (296) literal_list ::= literal_list NK_COMMA signed_literal */ - { 252, -1 }, /* (297) db_name ::= NK_ID */ - { 280, -1 }, /* (298) table_name ::= NK_ID */ - { 272, -1 }, /* (299) column_name ::= NK_ID */ - { 287, -1 }, /* (300) function_name ::= NK_ID */ - { 313, -1 }, /* (301) table_alias ::= NK_ID */ - { 314, -1 }, /* (302) column_alias ::= NK_ID */ - { 247, -1 }, /* (303) user_name ::= NK_ID */ - { 293, -1 }, /* (304) index_name ::= NK_ID */ - { 299, -1 }, /* (305) topic_name ::= NK_ID */ - { 306, -1 }, /* (306) stream_name ::= NK_ID */ - { 301, -1 }, /* (307) cgroup_name ::= NK_ID */ - { 315, -1 }, /* (308) expression ::= literal */ - { 315, -1 }, /* (309) expression ::= pseudo_column */ - { 315, -1 }, /* (310) expression ::= column_reference */ - { 315, -1 }, /* (311) expression ::= function_expression */ - { 315, -1 }, /* (312) expression ::= subquery */ - { 315, -3 }, /* (313) expression ::= NK_LP expression NK_RP */ - { 315, -2 }, /* (314) expression ::= NK_PLUS expression */ - { 315, -2 }, /* (315) expression ::= NK_MINUS expression */ - { 315, -3 }, /* (316) expression ::= expression NK_PLUS expression */ - { 315, -3 }, /* (317) expression ::= expression NK_MINUS expression */ - { 315, -3 }, /* (318) expression ::= expression NK_STAR expression */ - { 315, -3 }, /* (319) expression ::= expression NK_SLASH expression */ - { 315, -3 }, /* (320) expression ::= expression NK_REM expression */ - { 315, -3 }, /* (321) expression ::= column_reference NK_ARROW NK_STRING */ - { 298, -1 }, /* (322) expression_list ::= expression */ - { 298, -3 }, /* (323) expression_list ::= expression_list NK_COMMA expression */ - { 317, -1 }, /* (324) column_reference ::= column_name */ - { 317, -3 }, /* (325) column_reference ::= table_name NK_DOT column_name */ - { 316, -1 }, /* (326) pseudo_column ::= ROWTS */ - { 316, -1 }, /* (327) pseudo_column ::= TBNAME */ - { 316, -3 }, /* (328) pseudo_column ::= table_name NK_DOT TBNAME */ - { 316, -1 }, /* (329) pseudo_column ::= QSTARTTS */ - { 316, -1 }, /* (330) pseudo_column ::= QENDTS */ - { 316, -1 }, /* (331) pseudo_column ::= WSTARTTS */ - { 316, -1 }, /* (332) pseudo_column ::= WENDTS */ - { 316, -1 }, /* (333) pseudo_column ::= WDURATION */ - { 318, -4 }, /* (334) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 318, -4 }, /* (335) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 318, -6 }, /* (336) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 318, -1 }, /* (337) function_expression ::= literal_func */ - { 312, -3 }, /* (338) literal_func ::= noarg_func NK_LP NK_RP */ - { 312, -1 }, /* (339) literal_func ::= NOW */ - { 322, -1 }, /* (340) noarg_func ::= NOW */ - { 322, -1 }, /* (341) noarg_func ::= TODAY */ - { 322, -1 }, /* (342) noarg_func ::= TIMEZONE */ - { 320, -1 }, /* (343) star_func ::= COUNT */ - { 320, -1 }, /* (344) star_func ::= FIRST */ - { 320, -1 }, /* (345) star_func ::= LAST */ - { 320, -1 }, /* (346) star_func ::= LAST_ROW */ - { 321, -1 }, /* (347) star_func_para_list ::= NK_STAR */ - { 321, -1 }, /* (348) star_func_para_list ::= other_para_list */ - { 323, -1 }, /* (349) other_para_list ::= star_func_para */ - { 323, -3 }, /* (350) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 324, -1 }, /* (351) star_func_para ::= expression */ - { 324, -3 }, /* (352) star_func_para ::= table_name NK_DOT NK_STAR */ - { 325, -3 }, /* (353) predicate ::= expression compare_op expression */ - { 325, -5 }, /* (354) predicate ::= expression BETWEEN expression AND expression */ - { 325, -6 }, /* (355) predicate ::= expression NOT BETWEEN expression AND expression */ - { 325, -3 }, /* (356) predicate ::= expression IS NULL */ - { 325, -4 }, /* (357) predicate ::= expression IS NOT NULL */ - { 325, -3 }, /* (358) predicate ::= expression in_op in_predicate_value */ - { 326, -1 }, /* (359) compare_op ::= NK_LT */ - { 326, -1 }, /* (360) compare_op ::= NK_GT */ - { 326, -1 }, /* (361) compare_op ::= NK_LE */ - { 326, -1 }, /* (362) compare_op ::= NK_GE */ - { 326, -1 }, /* (363) compare_op ::= NK_NE */ - { 326, -1 }, /* (364) compare_op ::= NK_EQ */ - { 326, -1 }, /* (365) compare_op ::= LIKE */ - { 326, -2 }, /* (366) compare_op ::= NOT LIKE */ - { 326, -1 }, /* (367) compare_op ::= MATCH */ - { 326, -1 }, /* (368) compare_op ::= NMATCH */ - { 326, -1 }, /* (369) compare_op ::= CONTAINS */ - { 327, -1 }, /* (370) in_op ::= IN */ - { 327, -2 }, /* (371) in_op ::= NOT IN */ - { 328, -3 }, /* (372) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 329, -1 }, /* (373) boolean_value_expression ::= boolean_primary */ - { 329, -2 }, /* (374) boolean_value_expression ::= NOT boolean_primary */ - { 329, -3 }, /* (375) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 329, -3 }, /* (376) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 330, -1 }, /* (377) boolean_primary ::= predicate */ - { 330, -3 }, /* (378) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 331, -1 }, /* (379) common_expression ::= expression */ - { 331, -1 }, /* (380) common_expression ::= boolean_value_expression */ - { 332, -2 }, /* (381) from_clause ::= FROM table_reference_list */ - { 333, -1 }, /* (382) table_reference_list ::= table_reference */ - { 333, -3 }, /* (383) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 334, -1 }, /* (384) table_reference ::= table_primary */ - { 334, -1 }, /* (385) table_reference ::= joined_table */ - { 335, -2 }, /* (386) table_primary ::= table_name alias_opt */ - { 335, -4 }, /* (387) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 335, -2 }, /* (388) table_primary ::= subquery alias_opt */ - { 335, -1 }, /* (389) table_primary ::= parenthesized_joined_table */ - { 337, 0 }, /* (390) alias_opt ::= */ - { 337, -1 }, /* (391) alias_opt ::= table_alias */ - { 337, -2 }, /* (392) alias_opt ::= AS table_alias */ - { 338, -3 }, /* (393) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 338, -3 }, /* (394) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 336, -6 }, /* (395) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 339, 0 }, /* (396) join_type ::= */ - { 339, -1 }, /* (397) join_type ::= INNER */ - { 341, -12 }, /* (398) query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 342, 0 }, /* (399) set_quantifier_opt ::= */ - { 342, -1 }, /* (400) set_quantifier_opt ::= DISTINCT */ - { 342, -1 }, /* (401) set_quantifier_opt ::= ALL */ - { 343, -1 }, /* (402) select_list ::= NK_STAR */ - { 343, -1 }, /* (403) select_list ::= select_sublist */ - { 351, -1 }, /* (404) select_sublist ::= select_item */ - { 351, -3 }, /* (405) select_sublist ::= select_sublist NK_COMMA select_item */ - { 352, -1 }, /* (406) select_item ::= common_expression */ - { 352, -2 }, /* (407) select_item ::= common_expression column_alias */ - { 352, -3 }, /* (408) select_item ::= common_expression AS column_alias */ - { 352, -3 }, /* (409) select_item ::= table_name NK_DOT NK_STAR */ - { 310, 0 }, /* (410) where_clause_opt ::= */ - { 310, -2 }, /* (411) where_clause_opt ::= WHERE search_condition */ - { 344, 0 }, /* (412) partition_by_clause_opt ::= */ - { 344, -3 }, /* (413) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 348, 0 }, /* (414) twindow_clause_opt ::= */ - { 348, -6 }, /* (415) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 348, -4 }, /* (416) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 348, -6 }, /* (417) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 348, -8 }, /* (418) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 296, 0 }, /* (419) sliding_opt ::= */ - { 296, -4 }, /* (420) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 347, 0 }, /* (421) fill_opt ::= */ - { 347, -4 }, /* (422) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 347, -6 }, /* (423) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 353, -1 }, /* (424) fill_mode ::= NONE */ - { 353, -1 }, /* (425) fill_mode ::= PREV */ - { 353, -1 }, /* (426) fill_mode ::= NULL */ - { 353, -1 }, /* (427) fill_mode ::= LINEAR */ - { 353, -1 }, /* (428) fill_mode ::= NEXT */ - { 349, 0 }, /* (429) group_by_clause_opt ::= */ - { 349, -3 }, /* (430) group_by_clause_opt ::= GROUP BY group_by_list */ - { 354, -1 }, /* (431) group_by_list ::= expression */ - { 354, -3 }, /* (432) group_by_list ::= group_by_list NK_COMMA expression */ - { 350, 0 }, /* (433) having_clause_opt ::= */ - { 350, -2 }, /* (434) having_clause_opt ::= HAVING search_condition */ - { 345, 0 }, /* (435) range_opt ::= */ - { 345, -6 }, /* (436) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ - { 346, 0 }, /* (437) every_opt ::= */ - { 346, -4 }, /* (438) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 300, -4 }, /* (439) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 355, -1 }, /* (440) query_expression_body ::= query_primary */ - { 355, -4 }, /* (441) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 355, -3 }, /* (442) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 359, -1 }, /* (443) query_primary ::= query_specification */ - { 359, -6 }, /* (444) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 356, 0 }, /* (445) order_by_clause_opt ::= */ - { 356, -3 }, /* (446) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 357, 0 }, /* (447) slimit_clause_opt ::= */ - { 357, -2 }, /* (448) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 357, -4 }, /* (449) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 357, -4 }, /* (450) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 358, 0 }, /* (451) limit_clause_opt ::= */ - { 358, -2 }, /* (452) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 358, -4 }, /* (453) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 358, -4 }, /* (454) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 319, -3 }, /* (455) subquery ::= NK_LP query_expression NK_RP */ - { 340, -1 }, /* (456) search_condition ::= common_expression */ - { 360, -1 }, /* (457) sort_specification_list ::= sort_specification */ - { 360, -3 }, /* (458) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 361, -3 }, /* (459) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 362, 0 }, /* (460) ordering_specification_opt ::= */ - { 362, -1 }, /* (461) ordering_specification_opt ::= ASC */ - { 362, -1 }, /* (462) ordering_specification_opt ::= DESC */ - { 363, 0 }, /* (463) null_ordering_opt ::= */ - { 363, -2 }, /* (464) null_ordering_opt ::= NULLS FIRST */ - { 363, -2 }, /* (465) null_ordering_opt ::= NULLS LAST */ + { 246, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 246, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 247, 0 }, /* (2) account_options ::= */ + { 247, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 247, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 247, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 247, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 247, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 247, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 247, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 247, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 247, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 248, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 248, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 250, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 250, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 250, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 250, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 250, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 250, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 250, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 250, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 250, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 250, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 246, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ + { 246, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 246, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ + { 246, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ + { 246, -3 }, /* (28) cmd ::= DROP USER user_name */ + { 252, 0 }, /* (29) sysinfo_opt ::= */ + { 252, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ + { 246, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ + { 246, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ + { 253, -1 }, /* (33) privileges ::= ALL */ + { 253, -1 }, /* (34) privileges ::= priv_type_list */ + { 255, -1 }, /* (35) priv_type_list ::= priv_type */ + { 255, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ + { 256, -1 }, /* (37) priv_type ::= READ */ + { 256, -1 }, /* (38) priv_type ::= WRITE */ + { 254, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ + { 254, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ + { 246, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ + { 246, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ + { 246, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ + { 246, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ + { 246, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 246, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 246, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ + { 246, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 258, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ + { 258, -1 }, /* (50) dnode_endpoint ::= NK_ID */ + { 258, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ + { 246, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ + { 246, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 246, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 246, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 246, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ + { 246, -2 }, /* (64) cmd ::= USE db_name */ + { 246, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 259, -3 }, /* (66) not_exists_opt ::= IF NOT EXISTS */ + { 259, 0 }, /* (67) not_exists_opt ::= */ + { 261, -2 }, /* (68) exists_opt ::= IF EXISTS */ + { 261, 0 }, /* (69) exists_opt ::= */ + { 260, 0 }, /* (70) db_options ::= */ + { 260, -3 }, /* (71) db_options ::= db_options BUFFER NK_INTEGER */ + { 260, -3 }, /* (72) db_options ::= db_options CACHELAST NK_INTEGER */ + { 260, -3 }, /* (73) db_options ::= db_options COMP NK_INTEGER */ + { 260, -3 }, /* (74) db_options ::= db_options DURATION NK_INTEGER */ + { 260, -3 }, /* (75) db_options ::= db_options DURATION NK_VARIABLE */ + { 260, -3 }, /* (76) db_options ::= db_options FSYNC NK_INTEGER */ + { 260, -3 }, /* (77) db_options ::= db_options MAXROWS NK_INTEGER */ + { 260, -3 }, /* (78) db_options ::= db_options MINROWS NK_INTEGER */ + { 260, -3 }, /* (79) db_options ::= db_options KEEP integer_list */ + { 260, -3 }, /* (80) db_options ::= db_options KEEP variable_list */ + { 260, -3 }, /* (81) db_options ::= db_options PAGES NK_INTEGER */ + { 260, -3 }, /* (82) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 260, -3 }, /* (83) db_options ::= db_options PRECISION NK_STRING */ + { 260, -3 }, /* (84) db_options ::= db_options REPLICA NK_INTEGER */ + { 260, -3 }, /* (85) db_options ::= db_options STRICT NK_INTEGER */ + { 260, -3 }, /* (86) db_options ::= db_options WAL NK_INTEGER */ + { 260, -3 }, /* (87) db_options ::= db_options VGROUPS NK_INTEGER */ + { 260, -3 }, /* (88) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 260, -3 }, /* (89) db_options ::= db_options RETENTIONS retention_list */ + { 260, -3 }, /* (90) db_options ::= db_options SCHEMALESS NK_INTEGER */ + { 262, -1 }, /* (91) alter_db_options ::= alter_db_option */ + { 262, -2 }, /* (92) alter_db_options ::= alter_db_options alter_db_option */ + { 266, -2 }, /* (93) alter_db_option ::= BUFFER NK_INTEGER */ + { 266, -2 }, /* (94) alter_db_option ::= CACHELAST NK_INTEGER */ + { 266, -2 }, /* (95) alter_db_option ::= FSYNC NK_INTEGER */ + { 266, -2 }, /* (96) alter_db_option ::= KEEP integer_list */ + { 266, -2 }, /* (97) alter_db_option ::= KEEP variable_list */ + { 266, -2 }, /* (98) alter_db_option ::= PAGES NK_INTEGER */ + { 266, -2 }, /* (99) alter_db_option ::= REPLICA NK_INTEGER */ + { 266, -2 }, /* (100) alter_db_option ::= STRICT NK_INTEGER */ + { 266, -2 }, /* (101) alter_db_option ::= WAL NK_INTEGER */ + { 263, -1 }, /* (102) integer_list ::= NK_INTEGER */ + { 263, -3 }, /* (103) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 264, -1 }, /* (104) variable_list ::= NK_VARIABLE */ + { 264, -3 }, /* (105) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 265, -1 }, /* (106) retention_list ::= retention */ + { 265, -3 }, /* (107) retention_list ::= retention_list NK_COMMA retention */ + { 267, -3 }, /* (108) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 246, -9 }, /* (109) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 246, -3 }, /* (110) cmd ::= CREATE TABLE multi_create_clause */ + { 246, -9 }, /* (111) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 246, -3 }, /* (112) cmd ::= DROP TABLE multi_drop_clause */ + { 246, -4 }, /* (113) cmd ::= DROP STABLE exists_opt full_table_name */ + { 246, -3 }, /* (114) cmd ::= ALTER TABLE alter_table_clause */ + { 246, -3 }, /* (115) cmd ::= ALTER STABLE alter_table_clause */ + { 275, -2 }, /* (116) alter_table_clause ::= full_table_name alter_table_options */ + { 275, -5 }, /* (117) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 275, -4 }, /* (118) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 275, -5 }, /* (119) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 275, -5 }, /* (120) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 275, -5 }, /* (121) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 275, -4 }, /* (122) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 275, -5 }, /* (123) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 275, -5 }, /* (124) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 275, -6 }, /* (125) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 272, -1 }, /* (126) multi_create_clause ::= create_subtable_clause */ + { 272, -2 }, /* (127) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 280, -10 }, /* (128) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ + { 274, -1 }, /* (129) multi_drop_clause ::= drop_table_clause */ + { 274, -2 }, /* (130) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 283, -2 }, /* (131) drop_table_clause ::= exists_opt full_table_name */ + { 281, 0 }, /* (132) specific_tags_opt ::= */ + { 281, -3 }, /* (133) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 268, -1 }, /* (134) full_table_name ::= table_name */ + { 268, -3 }, /* (135) full_table_name ::= db_name NK_DOT table_name */ + { 269, -1 }, /* (136) column_def_list ::= column_def */ + { 269, -3 }, /* (137) column_def_list ::= column_def_list NK_COMMA column_def */ + { 286, -2 }, /* (138) column_def ::= column_name type_name */ + { 286, -4 }, /* (139) column_def ::= column_name type_name COMMENT NK_STRING */ + { 278, -1 }, /* (140) type_name ::= BOOL */ + { 278, -1 }, /* (141) type_name ::= TINYINT */ + { 278, -1 }, /* (142) type_name ::= SMALLINT */ + { 278, -1 }, /* (143) type_name ::= INT */ + { 278, -1 }, /* (144) type_name ::= INTEGER */ + { 278, -1 }, /* (145) type_name ::= BIGINT */ + { 278, -1 }, /* (146) type_name ::= FLOAT */ + { 278, -1 }, /* (147) type_name ::= DOUBLE */ + { 278, -4 }, /* (148) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 278, -1 }, /* (149) type_name ::= TIMESTAMP */ + { 278, -4 }, /* (150) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 278, -2 }, /* (151) type_name ::= TINYINT UNSIGNED */ + { 278, -2 }, /* (152) type_name ::= SMALLINT UNSIGNED */ + { 278, -2 }, /* (153) type_name ::= INT UNSIGNED */ + { 278, -2 }, /* (154) type_name ::= BIGINT UNSIGNED */ + { 278, -1 }, /* (155) type_name ::= JSON */ + { 278, -4 }, /* (156) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 278, -1 }, /* (157) type_name ::= MEDIUMBLOB */ + { 278, -1 }, /* (158) type_name ::= BLOB */ + { 278, -4 }, /* (159) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 278, -1 }, /* (160) type_name ::= DECIMAL */ + { 278, -4 }, /* (161) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 278, -6 }, /* (162) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 270, 0 }, /* (163) tags_def_opt ::= */ + { 270, -1 }, /* (164) tags_def_opt ::= tags_def */ + { 273, -4 }, /* (165) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 271, 0 }, /* (166) table_options ::= */ + { 271, -3 }, /* (167) table_options ::= table_options COMMENT NK_STRING */ + { 271, -3 }, /* (168) table_options ::= table_options MAX_DELAY duration_list */ + { 271, -3 }, /* (169) table_options ::= table_options WATERMARK duration_list */ + { 271, -5 }, /* (170) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 271, -3 }, /* (171) table_options ::= table_options TTL NK_INTEGER */ + { 271, -5 }, /* (172) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 276, -1 }, /* (173) alter_table_options ::= alter_table_option */ + { 276, -2 }, /* (174) alter_table_options ::= alter_table_options alter_table_option */ + { 289, -2 }, /* (175) alter_table_option ::= COMMENT NK_STRING */ + { 289, -2 }, /* (176) alter_table_option ::= TTL NK_INTEGER */ + { 287, -1 }, /* (177) duration_list ::= duration_literal */ + { 287, -3 }, /* (178) duration_list ::= duration_list NK_COMMA duration_literal */ + { 288, -1 }, /* (179) rollup_func_list ::= rollup_func_name */ + { 288, -3 }, /* (180) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 291, -1 }, /* (181) rollup_func_name ::= function_name */ + { 291, -1 }, /* (182) rollup_func_name ::= FIRST */ + { 291, -1 }, /* (183) rollup_func_name ::= LAST */ + { 284, -1 }, /* (184) col_name_list ::= col_name */ + { 284, -3 }, /* (185) col_name_list ::= col_name_list NK_COMMA col_name */ + { 293, -1 }, /* (186) col_name ::= column_name */ + { 246, -2 }, /* (187) cmd ::= SHOW DNODES */ + { 246, -2 }, /* (188) cmd ::= SHOW USERS */ + { 246, -2 }, /* (189) cmd ::= SHOW DATABASES */ + { 246, -4 }, /* (190) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 246, -4 }, /* (191) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 246, -3 }, /* (192) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 246, -2 }, /* (193) cmd ::= SHOW MNODES */ + { 246, -2 }, /* (194) cmd ::= SHOW MODULES */ + { 246, -2 }, /* (195) cmd ::= SHOW QNODES */ + { 246, -2 }, /* (196) cmd ::= SHOW FUNCTIONS */ + { 246, -5 }, /* (197) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 246, -2 }, /* (198) cmd ::= SHOW STREAMS */ + { 246, -2 }, /* (199) cmd ::= SHOW ACCOUNTS */ + { 246, -2 }, /* (200) cmd ::= SHOW APPS */ + { 246, -2 }, /* (201) cmd ::= SHOW CONNECTIONS */ + { 246, -2 }, /* (202) cmd ::= SHOW LICENCE */ + { 246, -2 }, /* (203) cmd ::= SHOW GRANTS */ + { 246, -4 }, /* (204) cmd ::= SHOW CREATE DATABASE db_name */ + { 246, -4 }, /* (205) cmd ::= SHOW CREATE TABLE full_table_name */ + { 246, -4 }, /* (206) cmd ::= SHOW CREATE STABLE full_table_name */ + { 246, -2 }, /* (207) cmd ::= SHOW QUERIES */ + { 246, -2 }, /* (208) cmd ::= SHOW SCORES */ + { 246, -2 }, /* (209) cmd ::= SHOW TOPICS */ + { 246, -2 }, /* (210) cmd ::= SHOW VARIABLES */ + { 246, -3 }, /* (211) cmd ::= SHOW LOCAL VARIABLES */ + { 246, -4 }, /* (212) cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + { 246, -2 }, /* (213) cmd ::= SHOW BNODES */ + { 246, -2 }, /* (214) cmd ::= SHOW SNODES */ + { 246, -2 }, /* (215) cmd ::= SHOW CLUSTER */ + { 246, -2 }, /* (216) cmd ::= SHOW TRANSACTIONS */ + { 246, -4 }, /* (217) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 246, -2 }, /* (218) cmd ::= SHOW CONSUMERS */ + { 246, -2 }, /* (219) cmd ::= SHOW SUBSCRIPTIONS */ + { 294, 0 }, /* (220) db_name_cond_opt ::= */ + { 294, -2 }, /* (221) db_name_cond_opt ::= db_name NK_DOT */ + { 295, 0 }, /* (222) like_pattern_opt ::= */ + { 295, -2 }, /* (223) like_pattern_opt ::= LIKE NK_STRING */ + { 296, -1 }, /* (224) table_name_cond ::= table_name */ + { 297, 0 }, /* (225) from_db_opt ::= */ + { 297, -2 }, /* (226) from_db_opt ::= FROM db_name */ + { 246, -8 }, /* (227) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 246, -4 }, /* (228) cmd ::= DROP INDEX exists_opt index_name */ + { 299, -10 }, /* (229) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + { 299, -12 }, /* (230) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + { 300, -1 }, /* (231) func_list ::= func */ + { 300, -3 }, /* (232) func_list ::= func_list NK_COMMA func */ + { 303, -4 }, /* (233) func ::= function_name NK_LP expression_list NK_RP */ + { 302, 0 }, /* (234) sma_stream_opt ::= */ + { 302, -3 }, /* (235) sma_stream_opt ::= stream_options WATERMARK duration_literal */ + { 302, -3 }, /* (236) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + { 246, -6 }, /* (237) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 246, -7 }, /* (238) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 246, -9 }, /* (239) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + { 246, -7 }, /* (240) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 246, -9 }, /* (241) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + { 246, -4 }, /* (242) cmd ::= DROP TOPIC exists_opt topic_name */ + { 246, -7 }, /* (243) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 246, -2 }, /* (244) cmd ::= DESC full_table_name */ + { 246, -2 }, /* (245) cmd ::= DESCRIBE full_table_name */ + { 246, -3 }, /* (246) cmd ::= RESET QUERY CACHE */ + { 246, -4 }, /* (247) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 309, 0 }, /* (248) analyze_opt ::= */ + { 309, -1 }, /* (249) analyze_opt ::= ANALYZE */ + { 310, 0 }, /* (250) explain_options ::= */ + { 310, -3 }, /* (251) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 310, -3 }, /* (252) explain_options ::= explain_options RATIO NK_FLOAT */ + { 246, -6 }, /* (253) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 246, -10 }, /* (254) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 246, -4 }, /* (255) cmd ::= DROP FUNCTION exists_opt function_name */ + { 311, 0 }, /* (256) agg_func_opt ::= */ + { 311, -1 }, /* (257) agg_func_opt ::= AGGREGATE */ + { 312, 0 }, /* (258) bufsize_opt ::= */ + { 312, -2 }, /* (259) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 246, -8 }, /* (260) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 246, -4 }, /* (261) cmd ::= DROP STREAM exists_opt stream_name */ + { 314, 0 }, /* (262) into_opt ::= */ + { 314, -2 }, /* (263) into_opt ::= INTO full_table_name */ + { 305, 0 }, /* (264) stream_options ::= */ + { 305, -3 }, /* (265) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 305, -3 }, /* (266) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 305, -4 }, /* (267) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 305, -3 }, /* (268) stream_options ::= stream_options WATERMARK duration_literal */ + { 246, -3 }, /* (269) cmd ::= KILL CONNECTION NK_INTEGER */ + { 246, -3 }, /* (270) cmd ::= KILL QUERY NK_STRING */ + { 246, -3 }, /* (271) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 246, -2 }, /* (272) cmd ::= BALANCE VGROUP */ + { 246, -4 }, /* (273) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 246, -4 }, /* (274) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 246, -3 }, /* (275) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 315, -2 }, /* (276) dnode_list ::= DNODE NK_INTEGER */ + { 315, -3 }, /* (277) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 246, -3 }, /* (278) cmd ::= SYNCDB db_name REPLICA */ + { 246, -4 }, /* (279) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 246, -1 }, /* (280) cmd ::= query_expression */ + { 249, -1 }, /* (281) literal ::= NK_INTEGER */ + { 249, -1 }, /* (282) literal ::= NK_FLOAT */ + { 249, -1 }, /* (283) literal ::= NK_STRING */ + { 249, -1 }, /* (284) literal ::= NK_BOOL */ + { 249, -2 }, /* (285) literal ::= TIMESTAMP NK_STRING */ + { 249, -1 }, /* (286) literal ::= duration_literal */ + { 249, -1 }, /* (287) literal ::= NULL */ + { 249, -1 }, /* (288) literal ::= NK_QUESTION */ + { 290, -1 }, /* (289) duration_literal ::= NK_VARIABLE */ + { 317, -1 }, /* (290) signed ::= NK_INTEGER */ + { 317, -2 }, /* (291) signed ::= NK_PLUS NK_INTEGER */ + { 317, -2 }, /* (292) signed ::= NK_MINUS NK_INTEGER */ + { 317, -1 }, /* (293) signed ::= NK_FLOAT */ + { 317, -2 }, /* (294) signed ::= NK_PLUS NK_FLOAT */ + { 317, -2 }, /* (295) signed ::= NK_MINUS NK_FLOAT */ + { 279, -1 }, /* (296) signed_literal ::= signed */ + { 279, -1 }, /* (297) signed_literal ::= NK_STRING */ + { 279, -1 }, /* (298) signed_literal ::= NK_BOOL */ + { 279, -2 }, /* (299) signed_literal ::= TIMESTAMP NK_STRING */ + { 279, -1 }, /* (300) signed_literal ::= duration_literal */ + { 279, -1 }, /* (301) signed_literal ::= NULL */ + { 279, -1 }, /* (302) signed_literal ::= literal_func */ + { 282, -1 }, /* (303) literal_list ::= signed_literal */ + { 282, -3 }, /* (304) literal_list ::= literal_list NK_COMMA signed_literal */ + { 257, -1 }, /* (305) db_name ::= NK_ID */ + { 285, -1 }, /* (306) table_name ::= NK_ID */ + { 277, -1 }, /* (307) column_name ::= NK_ID */ + { 292, -1 }, /* (308) function_name ::= NK_ID */ + { 319, -1 }, /* (309) table_alias ::= NK_ID */ + { 320, -1 }, /* (310) column_alias ::= NK_ID */ + { 251, -1 }, /* (311) user_name ::= NK_ID */ + { 298, -1 }, /* (312) index_name ::= NK_ID */ + { 306, -1 }, /* (313) topic_name ::= NK_ID */ + { 313, -1 }, /* (314) stream_name ::= NK_ID */ + { 308, -1 }, /* (315) cgroup_name ::= NK_ID */ + { 321, -1 }, /* (316) expression ::= literal */ + { 321, -1 }, /* (317) expression ::= pseudo_column */ + { 321, -1 }, /* (318) expression ::= column_reference */ + { 321, -1 }, /* (319) expression ::= function_expression */ + { 321, -1 }, /* (320) expression ::= subquery */ + { 321, -3 }, /* (321) expression ::= NK_LP expression NK_RP */ + { 321, -2 }, /* (322) expression ::= NK_PLUS expression */ + { 321, -2 }, /* (323) expression ::= NK_MINUS expression */ + { 321, -3 }, /* (324) expression ::= expression NK_PLUS expression */ + { 321, -3 }, /* (325) expression ::= expression NK_MINUS expression */ + { 321, -3 }, /* (326) expression ::= expression NK_STAR expression */ + { 321, -3 }, /* (327) expression ::= expression NK_SLASH expression */ + { 321, -3 }, /* (328) expression ::= expression NK_REM expression */ + { 321, -3 }, /* (329) expression ::= column_reference NK_ARROW NK_STRING */ + { 321, -3 }, /* (330) expression ::= expression NK_BITAND expression */ + { 321, -3 }, /* (331) expression ::= expression NK_BITOR expression */ + { 304, -1 }, /* (332) expression_list ::= expression */ + { 304, -3 }, /* (333) expression_list ::= expression_list NK_COMMA expression */ + { 323, -1 }, /* (334) column_reference ::= column_name */ + { 323, -3 }, /* (335) column_reference ::= table_name NK_DOT column_name */ + { 322, -1 }, /* (336) pseudo_column ::= ROWTS */ + { 322, -1 }, /* (337) pseudo_column ::= TBNAME */ + { 322, -3 }, /* (338) pseudo_column ::= table_name NK_DOT TBNAME */ + { 322, -1 }, /* (339) pseudo_column ::= QSTARTTS */ + { 322, -1 }, /* (340) pseudo_column ::= QENDTS */ + { 322, -1 }, /* (341) pseudo_column ::= WSTARTTS */ + { 322, -1 }, /* (342) pseudo_column ::= WENDTS */ + { 322, -1 }, /* (343) pseudo_column ::= WDURATION */ + { 324, -4 }, /* (344) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 324, -4 }, /* (345) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 324, -6 }, /* (346) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 324, -1 }, /* (347) function_expression ::= literal_func */ + { 318, -3 }, /* (348) literal_func ::= noarg_func NK_LP NK_RP */ + { 318, -1 }, /* (349) literal_func ::= NOW */ + { 328, -1 }, /* (350) noarg_func ::= NOW */ + { 328, -1 }, /* (351) noarg_func ::= TODAY */ + { 328, -1 }, /* (352) noarg_func ::= TIMEZONE */ + { 326, -1 }, /* (353) star_func ::= COUNT */ + { 326, -1 }, /* (354) star_func ::= FIRST */ + { 326, -1 }, /* (355) star_func ::= LAST */ + { 326, -1 }, /* (356) star_func ::= LAST_ROW */ + { 327, -1 }, /* (357) star_func_para_list ::= NK_STAR */ + { 327, -1 }, /* (358) star_func_para_list ::= other_para_list */ + { 329, -1 }, /* (359) other_para_list ::= star_func_para */ + { 329, -3 }, /* (360) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 330, -1 }, /* (361) star_func_para ::= expression */ + { 330, -3 }, /* (362) star_func_para ::= table_name NK_DOT NK_STAR */ + { 331, -3 }, /* (363) predicate ::= expression compare_op expression */ + { 331, -5 }, /* (364) predicate ::= expression BETWEEN expression AND expression */ + { 331, -6 }, /* (365) predicate ::= expression NOT BETWEEN expression AND expression */ + { 331, -3 }, /* (366) predicate ::= expression IS NULL */ + { 331, -4 }, /* (367) predicate ::= expression IS NOT NULL */ + { 331, -3 }, /* (368) predicate ::= expression in_op in_predicate_value */ + { 332, -1 }, /* (369) compare_op ::= NK_LT */ + { 332, -1 }, /* (370) compare_op ::= NK_GT */ + { 332, -1 }, /* (371) compare_op ::= NK_LE */ + { 332, -1 }, /* (372) compare_op ::= NK_GE */ + { 332, -1 }, /* (373) compare_op ::= NK_NE */ + { 332, -1 }, /* (374) compare_op ::= NK_EQ */ + { 332, -1 }, /* (375) compare_op ::= LIKE */ + { 332, -2 }, /* (376) compare_op ::= NOT LIKE */ + { 332, -1 }, /* (377) compare_op ::= MATCH */ + { 332, -1 }, /* (378) compare_op ::= NMATCH */ + { 332, -1 }, /* (379) compare_op ::= CONTAINS */ + { 333, -1 }, /* (380) in_op ::= IN */ + { 333, -2 }, /* (381) in_op ::= NOT IN */ + { 334, -3 }, /* (382) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 335, -1 }, /* (383) boolean_value_expression ::= boolean_primary */ + { 335, -2 }, /* (384) boolean_value_expression ::= NOT boolean_primary */ + { 335, -3 }, /* (385) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 335, -3 }, /* (386) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 336, -1 }, /* (387) boolean_primary ::= predicate */ + { 336, -3 }, /* (388) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 337, -1 }, /* (389) common_expression ::= expression */ + { 337, -1 }, /* (390) common_expression ::= boolean_value_expression */ + { 338, 0 }, /* (391) from_clause_opt ::= */ + { 338, -2 }, /* (392) from_clause_opt ::= FROM table_reference_list */ + { 339, -1 }, /* (393) table_reference_list ::= table_reference */ + { 339, -3 }, /* (394) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 340, -1 }, /* (395) table_reference ::= table_primary */ + { 340, -1 }, /* (396) table_reference ::= joined_table */ + { 341, -2 }, /* (397) table_primary ::= table_name alias_opt */ + { 341, -4 }, /* (398) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 341, -2 }, /* (399) table_primary ::= subquery alias_opt */ + { 341, -1 }, /* (400) table_primary ::= parenthesized_joined_table */ + { 343, 0 }, /* (401) alias_opt ::= */ + { 343, -1 }, /* (402) alias_opt ::= table_alias */ + { 343, -2 }, /* (403) alias_opt ::= AS table_alias */ + { 344, -3 }, /* (404) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 344, -3 }, /* (405) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 342, -6 }, /* (406) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 345, 0 }, /* (407) join_type ::= */ + { 345, -1 }, /* (408) join_type ::= INNER */ + { 347, -12 }, /* (409) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 348, 0 }, /* (410) set_quantifier_opt ::= */ + { 348, -1 }, /* (411) set_quantifier_opt ::= DISTINCT */ + { 348, -1 }, /* (412) set_quantifier_opt ::= ALL */ + { 349, -1 }, /* (413) select_list ::= NK_STAR */ + { 349, -1 }, /* (414) select_list ::= select_sublist */ + { 357, -1 }, /* (415) select_sublist ::= select_item */ + { 357, -3 }, /* (416) select_sublist ::= select_sublist NK_COMMA select_item */ + { 358, -1 }, /* (417) select_item ::= common_expression */ + { 358, -2 }, /* (418) select_item ::= common_expression column_alias */ + { 358, -3 }, /* (419) select_item ::= common_expression AS column_alias */ + { 358, -3 }, /* (420) select_item ::= table_name NK_DOT NK_STAR */ + { 316, 0 }, /* (421) where_clause_opt ::= */ + { 316, -2 }, /* (422) where_clause_opt ::= WHERE search_condition */ + { 350, 0 }, /* (423) partition_by_clause_opt ::= */ + { 350, -3 }, /* (424) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 354, 0 }, /* (425) twindow_clause_opt ::= */ + { 354, -6 }, /* (426) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 354, -4 }, /* (427) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 354, -6 }, /* (428) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 354, -8 }, /* (429) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 301, 0 }, /* (430) sliding_opt ::= */ + { 301, -4 }, /* (431) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 353, 0 }, /* (432) fill_opt ::= */ + { 353, -4 }, /* (433) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 353, -6 }, /* (434) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 359, -1 }, /* (435) fill_mode ::= NONE */ + { 359, -1 }, /* (436) fill_mode ::= PREV */ + { 359, -1 }, /* (437) fill_mode ::= NULL */ + { 359, -1 }, /* (438) fill_mode ::= LINEAR */ + { 359, -1 }, /* (439) fill_mode ::= NEXT */ + { 355, 0 }, /* (440) group_by_clause_opt ::= */ + { 355, -3 }, /* (441) group_by_clause_opt ::= GROUP BY group_by_list */ + { 360, -1 }, /* (442) group_by_list ::= expression */ + { 360, -3 }, /* (443) group_by_list ::= group_by_list NK_COMMA expression */ + { 356, 0 }, /* (444) having_clause_opt ::= */ + { 356, -2 }, /* (445) having_clause_opt ::= HAVING search_condition */ + { 351, 0 }, /* (446) range_opt ::= */ + { 351, -6 }, /* (447) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ + { 352, 0 }, /* (448) every_opt ::= */ + { 352, -4 }, /* (449) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 307, -4 }, /* (450) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 361, -1 }, /* (451) query_expression_body ::= query_primary */ + { 361, -4 }, /* (452) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 361, -3 }, /* (453) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 365, -1 }, /* (454) query_primary ::= query_specification */ + { 365, -6 }, /* (455) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ + { 362, 0 }, /* (456) order_by_clause_opt ::= */ + { 362, -3 }, /* (457) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 363, 0 }, /* (458) slimit_clause_opt ::= */ + { 363, -2 }, /* (459) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 363, -4 }, /* (460) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 363, -4 }, /* (461) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 364, 0 }, /* (462) limit_clause_opt ::= */ + { 364, -2 }, /* (463) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 364, -4 }, /* (464) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 364, -4 }, /* (465) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 325, -3 }, /* (466) subquery ::= NK_LP query_expression NK_RP */ + { 346, -1 }, /* (467) search_condition ::= common_expression */ + { 366, -1 }, /* (468) sort_specification_list ::= sort_specification */ + { 366, -3 }, /* (469) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 367, -3 }, /* (470) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 368, 0 }, /* (471) ordering_specification_opt ::= */ + { 368, -1 }, /* (472) ordering_specification_opt ::= ASC */ + { 368, -1 }, /* (473) ordering_specification_opt ::= DESC */ + { 369, 0 }, /* (474) null_ordering_opt ::= */ + { 369, -2 }, /* (475) null_ordering_opt ::= NULLS FIRST */ + { 369, -2 }, /* (476) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3161,11 +3204,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,243,&yymsp[0].minor); + yy_destructor(yypParser,247,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,244,&yymsp[0].minor); + yy_destructor(yypParser,248,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3179,20 +3222,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,243,&yymsp[-2].minor); +{ yy_destructor(yypParser,247,&yymsp[-2].minor); { } - yy_destructor(yypParser,245,&yymsp[0].minor); + yy_destructor(yypParser,249,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,246,&yymsp[0].minor); +{ yy_destructor(yypParser,250,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,244,&yymsp[-1].minor); +{ yy_destructor(yypParser,248,&yymsp[-1].minor); { } - yy_destructor(yypParser,246,&yymsp[0].minor); + yy_destructor(yypParser,250,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3206,1309 +3249,1349 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,245,&yymsp[0].minor); + yy_destructor(yypParser,249,&yymsp[0].minor); break; - case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } + case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy109, &yymsp[-1].minor.yy0, yymsp[0].minor.yy323); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy57, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy109, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; - case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy57, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } + case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy109, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } break; - case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy57); } + case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy109, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } break; - case 28: /* cmd ::= GRANT privileges ON priv_level TO user_name */ -{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy389, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } + case 28: /* cmd ::= DROP USER user_name */ +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy109); } break; - case 29: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ -{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy389, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } + case 29: /* sysinfo_opt ::= */ +{ yymsp[1].minor.yy323 = 1; } break; - case 30: /* privileges ::= ALL */ -{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_ALL; } + case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */ +{ yymsp[-1].minor.yy323 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 31: /* privileges ::= priv_type_list */ - case 32: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==32); -{ yylhsminor.yy389 = yymsp[0].minor.yy389; } - yymsp[0].minor.yy389 = yylhsminor.yy389; + case 31: /* cmd ::= GRANT privileges ON priv_level TO user_name */ +{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy209, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109); } break; - case 33: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -{ yylhsminor.yy389 = yymsp[-2].minor.yy389 | yymsp[0].minor.yy389; } - yymsp[-2].minor.yy389 = yylhsminor.yy389; + case 32: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ +{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy209, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109); } break; - case 34: /* priv_type ::= READ */ -{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_READ; } + case 33: /* privileges ::= ALL */ +{ yymsp[0].minor.yy209 = PRIVILEGE_TYPE_ALL; } break; - case 35: /* priv_type ::= WRITE */ -{ yymsp[0].minor.yy389 = PRIVILEGE_TYPE_WRITE; } + case 34: /* privileges ::= priv_type_list */ + case 35: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==35); +{ yylhsminor.yy209 = yymsp[0].minor.yy209; } + yymsp[0].minor.yy209 = yylhsminor.yy209; break; - case 36: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -{ yylhsminor.yy57 = yymsp[-2].minor.yy0; } - yymsp[-2].minor.yy57 = yylhsminor.yy57; + case 36: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ +{ yylhsminor.yy209 = yymsp[-2].minor.yy209 | yymsp[0].minor.yy209; } + yymsp[-2].minor.yy209 = yylhsminor.yy209; break; - case 37: /* priv_level ::= db_name NK_DOT NK_STAR */ -{ yylhsminor.yy57 = yymsp[-2].minor.yy57; } - yymsp[-2].minor.yy57 = yylhsminor.yy57; + case 37: /* priv_type ::= READ */ +{ yymsp[0].minor.yy209 = PRIVILEGE_TYPE_READ; } break; - case 38: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy57, NULL); } + case 38: /* priv_type ::= WRITE */ +{ yymsp[0].minor.yy209 = PRIVILEGE_TYPE_WRITE; } break; - case 39: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } + case 39: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ +{ yylhsminor.yy109 = yymsp[-2].minor.yy0; } + yymsp[-2].minor.yy109 = yylhsminor.yy109; break; - case 40: /* cmd ::= DROP DNODE NK_INTEGER */ + case 40: /* priv_level ::= db_name NK_DOT NK_STAR */ +{ yylhsminor.yy109 = yymsp[-2].minor.yy109; } + yymsp[-2].minor.yy109 = yylhsminor.yy109; + break; + case 41: /* cmd ::= CREATE DNODE dnode_endpoint */ +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy109, NULL); } + break; + case 42: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy0); } + break; + case 43: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 41: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy57); } + case 44: /* cmd ::= DROP DNODE dnode_endpoint */ +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy109); } break; - case 42: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + case 45: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } break; - case 43: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + case 46: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 44: /* cmd ::= ALTER ALL DNODES NK_STRING */ + case 47: /* cmd ::= ALTER ALL DNODES NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[0].minor.yy0, NULL); } break; - case 45: /* cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + case 48: /* cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 46: /* dnode_endpoint ::= NK_STRING */ - case 47: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==47); - case 48: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==48); - case 297: /* db_name ::= NK_ID */ yytestcase(yyruleno==297); - case 298: /* table_name ::= NK_ID */ yytestcase(yyruleno==298); - case 299: /* column_name ::= NK_ID */ yytestcase(yyruleno==299); - case 300: /* function_name ::= NK_ID */ yytestcase(yyruleno==300); - case 301: /* table_alias ::= NK_ID */ yytestcase(yyruleno==301); - case 302: /* column_alias ::= NK_ID */ yytestcase(yyruleno==302); - case 303: /* user_name ::= NK_ID */ yytestcase(yyruleno==303); - case 304: /* index_name ::= NK_ID */ yytestcase(yyruleno==304); - case 305: /* topic_name ::= NK_ID */ yytestcase(yyruleno==305); - case 306: /* stream_name ::= NK_ID */ yytestcase(yyruleno==306); - case 307: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==307); - case 340: /* noarg_func ::= NOW */ yytestcase(yyruleno==340); - case 341: /* noarg_func ::= TODAY */ yytestcase(yyruleno==341); - case 342: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==342); - case 343: /* star_func ::= COUNT */ yytestcase(yyruleno==343); - case 344: /* star_func ::= FIRST */ yytestcase(yyruleno==344); - case 345: /* star_func ::= LAST */ yytestcase(yyruleno==345); - case 346: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==346); -{ yylhsminor.yy57 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy57 = yylhsminor.yy57; + case 49: /* dnode_endpoint ::= NK_STRING */ + case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); + case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); + case 305: /* db_name ::= NK_ID */ yytestcase(yyruleno==305); + case 306: /* table_name ::= NK_ID */ yytestcase(yyruleno==306); + case 307: /* column_name ::= NK_ID */ yytestcase(yyruleno==307); + case 308: /* function_name ::= NK_ID */ yytestcase(yyruleno==308); + case 309: /* table_alias ::= NK_ID */ yytestcase(yyruleno==309); + case 310: /* column_alias ::= NK_ID */ yytestcase(yyruleno==310); + case 311: /* user_name ::= NK_ID */ yytestcase(yyruleno==311); + case 312: /* index_name ::= NK_ID */ yytestcase(yyruleno==312); + case 313: /* topic_name ::= NK_ID */ yytestcase(yyruleno==313); + case 314: /* stream_name ::= NK_ID */ yytestcase(yyruleno==314); + case 315: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==315); + case 350: /* noarg_func ::= NOW */ yytestcase(yyruleno==350); + case 351: /* noarg_func ::= TODAY */ yytestcase(yyruleno==351); + case 352: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==352); + case 353: /* star_func ::= COUNT */ yytestcase(yyruleno==353); + case 354: /* star_func ::= FIRST */ yytestcase(yyruleno==354); + case 355: /* star_func ::= LAST */ yytestcase(yyruleno==355); + case 356: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==356); +{ yylhsminor.yy109 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy109 = yylhsminor.yy109; break; - case 49: /* cmd ::= ALTER LOCAL NK_STRING */ + case 52: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 50: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + case 53: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 51: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + case 54: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_QNODE_STMT, &yymsp[0].minor.yy0); } break; - case 52: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + case 55: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_QNODE_STMT, &yymsp[0].minor.yy0); } break; - case 53: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + case 56: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_BNODE_STMT, &yymsp[0].minor.yy0); } break; - case 54: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + case 57: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_BNODE_STMT, &yymsp[0].minor.yy0); } break; - case 55: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + case 58: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_SNODE_STMT, &yymsp[0].minor.yy0); } break; - case 56: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + case 59: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_SNODE_STMT, &yymsp[0].minor.yy0); } break; - case 57: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + case 60: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &yymsp[0].minor.yy0); } break; - case 58: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + case 61: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; - case 59: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy481, &yymsp[-1].minor.yy57, yymsp[0].minor.yy392); } + case 62: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy437, &yymsp[-1].minor.yy109, yymsp[0].minor.yy452); } break; - case 60: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } + case 63: /* cmd ::= DROP DATABASE exists_opt db_name */ +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy437, &yymsp[0].minor.yy109); } break; - case 61: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy57); } + case 64: /* cmd ::= USE db_name */ +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy109); } break; - case 62: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy57, yymsp[0].minor.yy392); } + case 65: /* cmd ::= ALTER DATABASE db_name alter_db_options */ +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy109, yymsp[0].minor.yy452); } break; - case 63: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy481 = true; } + case 66: /* not_exists_opt ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy437 = true; } break; - case 64: /* not_exists_opt ::= */ - case 66: /* exists_opt ::= */ yytestcase(yyruleno==66); - case 240: /* analyze_opt ::= */ yytestcase(yyruleno==240); - case 248: /* agg_func_opt ::= */ yytestcase(yyruleno==248); - case 399: /* set_quantifier_opt ::= */ yytestcase(yyruleno==399); -{ yymsp[1].minor.yy481 = false; } + case 67: /* not_exists_opt ::= */ + case 69: /* exists_opt ::= */ yytestcase(yyruleno==69); + case 248: /* analyze_opt ::= */ yytestcase(yyruleno==248); + case 256: /* agg_func_opt ::= */ yytestcase(yyruleno==256); + case 410: /* set_quantifier_opt ::= */ yytestcase(yyruleno==410); +{ yymsp[1].minor.yy437 = false; } break; - case 65: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy481 = true; } + case 68: /* exists_opt ::= IF EXISTS */ +{ yymsp[-1].minor.yy437 = true; } break; - case 67: /* db_options ::= */ -{ yymsp[1].minor.yy392 = createDefaultDatabaseOptions(pCxt); } + case 70: /* db_options ::= */ +{ yymsp[1].minor.yy452 = createDefaultDatabaseOptions(pCxt); } break; - case 68: /* db_options ::= db_options BUFFER NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 71: /* db_options ::= db_options BUFFER NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 69: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 72: /* db_options ::= db_options CACHELAST NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_CACHELAST, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 70: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 73: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 71: /* db_options ::= db_options DURATION NK_INTEGER */ - case 72: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==72); -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 74: /* db_options ::= db_options DURATION NK_INTEGER */ + case 75: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==75); +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 73: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 76: /* db_options ::= db_options FSYNC NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 74: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 77: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 75: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 78: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 76: /* db_options ::= db_options KEEP integer_list */ - case 77: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==77); -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_KEEP, yymsp[0].minor.yy600); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 79: /* db_options ::= db_options KEEP integer_list */ + case 80: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==80); +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_KEEP, yymsp[0].minor.yy404); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 78: /* db_options ::= db_options PAGES NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 81: /* db_options ::= db_options PAGES NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 79: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 80: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 81: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 82: /* db_options ::= db_options STRICT NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 83: /* db_options ::= db_options WAL NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 84: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 85: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 86: /* db_options ::= db_options RETENTIONS retention_list */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_RETENTIONS, yymsp[0].minor.yy600); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 87: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -{ yylhsminor.yy392 = setDatabaseOption(pCxt, yymsp[-2].minor.yy392, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 88: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy392 = createAlterDatabaseOptions(pCxt); yylhsminor.yy392 = setAlterDatabaseOption(pCxt, yylhsminor.yy392, &yymsp[0].minor.yy221); } - yymsp[0].minor.yy392 = yylhsminor.yy392; - break; - case 89: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy392 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy392, &yymsp[0].minor.yy221); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; - break; - case 90: /* alter_db_option ::= BUFFER NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 91: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 92: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 93: /* alter_db_option ::= KEEP integer_list */ - case 94: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==94); -{ yymsp[-1].minor.yy221.type = DB_OPTION_KEEP; yymsp[-1].minor.yy221.pList = yymsp[0].minor.yy600; } - break; - case 95: /* alter_db_option ::= PAGES NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_PAGES; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 96: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 97: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_STRICT; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 98: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = DB_OPTION_WAL; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } - break; - case 99: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy600 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy600 = yylhsminor.yy600; - break; - case 100: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 269: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==269); -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy600 = yylhsminor.yy600; - break; - case 101: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy600 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy600 = yylhsminor.yy600; - break; - case 102: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy600 = yylhsminor.yy600; - break; - case 103: /* retention_list ::= retention */ - case 123: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==123); - case 126: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==126); - case 133: /* column_def_list ::= column_def */ yytestcase(yyruleno==133); - case 176: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==176); - case 181: /* col_name_list ::= col_name */ yytestcase(yyruleno==181); - case 228: /* func_list ::= func */ yytestcase(yyruleno==228); - case 295: /* literal_list ::= signed_literal */ yytestcase(yyruleno==295); - case 349: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==349); - case 404: /* select_sublist ::= select_item */ yytestcase(yyruleno==404); - case 457: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==457); -{ yylhsminor.yy600 = createNodeList(pCxt, yymsp[0].minor.yy392); } - yymsp[0].minor.yy600 = yylhsminor.yy600; - break; - case 104: /* retention_list ::= retention_list NK_COMMA retention */ - case 134: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==134); - case 177: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==177); - case 182: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==182); - case 229: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==229); - case 296: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==296); - case 350: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==350); - case 405: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==405); - case 458: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==458); -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, yymsp[0].minor.yy392); } - yymsp[-2].minor.yy600 = yylhsminor.yy600; - break; - case 105: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy392 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 106: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 108: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==108); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy481, yymsp[-5].minor.yy392, yymsp[-3].minor.yy600, yymsp[-1].minor.yy600, yymsp[0].minor.yy392); } - break; - case 107: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy600); } - break; - case 109: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy600); } - break; - case 110: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy481, yymsp[0].minor.yy392); } - break; - case 111: /* cmd ::= ALTER TABLE alter_table_clause */ - case 112: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==112); - case 272: /* cmd ::= query_expression */ yytestcase(yyruleno==272); -{ pCxt->pRootNode = yymsp[0].minor.yy392; } - break; - case 113: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy392 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; - break; - case 114: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; - break; - case 115: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy57); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; - break; - case 116: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + case 82: /* db_options ::= db_options PAGESIZE NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 83: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 84: /* db_options ::= db_options REPLICA NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 85: /* db_options ::= db_options STRICT NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 86: /* db_options ::= db_options WAL NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 87: /* db_options ::= db_options VGROUPS NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 88: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 89: /* db_options ::= db_options RETENTIONS retention_list */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_RETENTIONS, yymsp[0].minor.yy404); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 90: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ +{ yylhsminor.yy452 = setDatabaseOption(pCxt, yymsp[-2].minor.yy452, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 91: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy452 = createAlterDatabaseOptions(pCxt); yylhsminor.yy452 = setAlterDatabaseOption(pCxt, yylhsminor.yy452, &yymsp[0].minor.yy85); } + yymsp[0].minor.yy452 = yylhsminor.yy452; + break; + case 92: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy452 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy452, &yymsp[0].minor.yy85); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; + break; + case 93: /* alter_db_option ::= BUFFER NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 94: /* alter_db_option ::= CACHELAST NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 95: /* alter_db_option ::= FSYNC NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 96: /* alter_db_option ::= KEEP integer_list */ + case 97: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==97); +{ yymsp[-1].minor.yy85.type = DB_OPTION_KEEP; yymsp[-1].minor.yy85.pList = yymsp[0].minor.yy404; } + break; + case 98: /* alter_db_option ::= PAGES NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_PAGES; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 99: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 100: /* alter_db_option ::= STRICT NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_STRICT; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 101: /* alter_db_option ::= WAL NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = DB_OPTION_WAL; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } + break; + case 102: /* integer_list ::= NK_INTEGER */ +{ yylhsminor.yy404 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy404 = yylhsminor.yy404; + break; + case 103: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 277: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==277); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; + break; + case 104: /* variable_list ::= NK_VARIABLE */ +{ yylhsminor.yy404 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy404 = yylhsminor.yy404; + break; + case 105: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; + break; + case 106: /* retention_list ::= retention */ + case 126: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==126); + case 129: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==129); + case 136: /* column_def_list ::= column_def */ yytestcase(yyruleno==136); + case 179: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==179); + case 184: /* col_name_list ::= col_name */ yytestcase(yyruleno==184); + case 231: /* func_list ::= func */ yytestcase(yyruleno==231); + case 303: /* literal_list ::= signed_literal */ yytestcase(yyruleno==303); + case 359: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==359); + case 415: /* select_sublist ::= select_item */ yytestcase(yyruleno==415); + case 468: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==468); +{ yylhsminor.yy404 = createNodeList(pCxt, yymsp[0].minor.yy452); } + yymsp[0].minor.yy404 = yylhsminor.yy404; + break; + case 107: /* retention_list ::= retention_list NK_COMMA retention */ + case 137: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==137); + case 180: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==180); + case 185: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==185); + case 232: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==232); + case 304: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==304); + case 360: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==360); + case 416: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==416); + case 469: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==469); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, yymsp[0].minor.yy452); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; + break; + case 108: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ +{ yylhsminor.yy452 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 109: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 111: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==111); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy437, yymsp[-5].minor.yy452, yymsp[-3].minor.yy404, yymsp[-1].minor.yy404, yymsp[0].minor.yy452); } + break; + case 110: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy404); } + break; + case 112: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy404); } + break; + case 113: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy437, yymsp[0].minor.yy452); } + break; + case 114: /* cmd ::= ALTER TABLE alter_table_clause */ + case 115: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==115); + case 280: /* cmd ::= query_expression */ yytestcase(yyruleno==280); +{ pCxt->pRootNode = yymsp[0].minor.yy452; } + break; + case 116: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy452 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; + break; + case 117: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy452 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy109, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; + break; + case 118: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy452 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy452, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy109); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; + break; + case 119: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy452 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy109, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; break; - case 117: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; - break; - case 118: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; - break; - case 119: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy57); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 120: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy452 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy109, &yymsp[0].minor.yy109); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; + break; + case 121: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy452 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy109, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; + break; + case 122: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy452 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy452, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy109); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 120: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + case 123: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy452 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy109, yymsp[0].minor.yy504); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; break; - case 121: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; - break; - case 122: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -{ yylhsminor.yy392 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy392, &yymsp[-2].minor.yy57, yymsp[0].minor.yy392); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; + case 124: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy452 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy452, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy109, &yymsp[0].minor.yy109); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; + break; + case 125: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ +{ yylhsminor.yy452 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy452, &yymsp[-2].minor.yy109, yymsp[0].minor.yy452); } + yymsp[-5].minor.yy452 = yylhsminor.yy452; break; - case 124: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 127: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==127); -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-1].minor.yy600, yymsp[0].minor.yy392); } - yymsp[-1].minor.yy600 = yylhsminor.yy600; + case 127: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 130: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==130); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-1].minor.yy404, yymsp[0].minor.yy452); } + yymsp[-1].minor.yy404 = yylhsminor.yy404; break; - case 125: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ -{ yylhsminor.yy392 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy481, yymsp[-8].minor.yy392, yymsp[-6].minor.yy392, yymsp[-5].minor.yy600, yymsp[-2].minor.yy600, yymsp[0].minor.yy392); } - yymsp[-9].minor.yy392 = yylhsminor.yy392; + case 128: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP table_options */ +{ yylhsminor.yy452 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy437, yymsp[-8].minor.yy452, yymsp[-6].minor.yy452, yymsp[-5].minor.yy404, yymsp[-2].minor.yy404, yymsp[0].minor.yy452); } + yymsp[-9].minor.yy452 = yylhsminor.yy452; break; - case 128: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy392 = createDropTableClause(pCxt, yymsp[-1].minor.yy481, yymsp[0].minor.yy392); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 131: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy452 = createDropTableClause(pCxt, yymsp[-1].minor.yy437, yymsp[0].minor.yy452); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 129: /* specific_tags_opt ::= */ - case 160: /* tags_def_opt ::= */ yytestcase(yyruleno==160); - case 412: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==412); - case 429: /* group_by_clause_opt ::= */ yytestcase(yyruleno==429); - case 445: /* order_by_clause_opt ::= */ yytestcase(yyruleno==445); -{ yymsp[1].minor.yy600 = NULL; } + case 132: /* specific_tags_opt ::= */ + case 163: /* tags_def_opt ::= */ yytestcase(yyruleno==163); + case 423: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==423); + case 440: /* group_by_clause_opt ::= */ yytestcase(yyruleno==440); + case 456: /* order_by_clause_opt ::= */ yytestcase(yyruleno==456); +{ yymsp[1].minor.yy404 = NULL; } break; - case 130: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy600 = yymsp[-1].minor.yy600; } + case 133: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy404 = yymsp[-1].minor.yy404; } break; - case 131: /* full_table_name ::= table_name */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy57, NULL); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 134: /* full_table_name ::= table_name */ +{ yylhsminor.yy452 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy109, NULL); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 132: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57, NULL); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 135: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy452 = createRealTableNode(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109, NULL); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 135: /* column_def ::= column_name type_name */ -{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy57, yymsp[0].minor.yy448, NULL); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 138: /* column_def ::= column_name type_name */ +{ yylhsminor.yy452 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy109, yymsp[0].minor.yy504, NULL); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 136: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-2].minor.yy448, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 139: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy452 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy109, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 137: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 140: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 138: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 141: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 139: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 142: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 140: /* type_name ::= INT */ - case 141: /* type_name ::= INTEGER */ yytestcase(yyruleno==141); -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_INT); } + case 143: /* type_name ::= INT */ + case 144: /* type_name ::= INTEGER */ yytestcase(yyruleno==144); +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 142: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 145: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 143: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 146: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 144: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 147: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 145: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 148: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 146: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 149: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 147: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 150: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 148: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 151: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 149: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 152: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 150: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UINT); } + case 153: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 151: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy448 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 154: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy504 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 152: /* type_name ::= JSON */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_JSON); } + case 155: /* type_name ::= JSON */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 153: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 156: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 154: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 157: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 155: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 158: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 156: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy448 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 159: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 157: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 160: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 158: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 161: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 159: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy448 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 162: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy504 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 161: /* tags_def_opt ::= tags_def */ - case 348: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==348); - case 403: /* select_list ::= select_sublist */ yytestcase(yyruleno==403); -{ yylhsminor.yy600 = yymsp[0].minor.yy600; } - yymsp[0].minor.yy600 = yylhsminor.yy600; + case 164: /* tags_def_opt ::= tags_def */ + case 358: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==358); + case 414: /* select_list ::= select_sublist */ yytestcase(yyruleno==414); +{ yylhsminor.yy404 = yymsp[0].minor.yy404; } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 162: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy600 = yymsp[-1].minor.yy600; } + case 165: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy404 = yymsp[-1].minor.yy404; } break; - case 163: /* table_options ::= */ -{ yymsp[1].minor.yy392 = createDefaultTableOptions(pCxt); } + case 166: /* table_options ::= */ +{ yymsp[1].minor.yy452 = createDefaultTableOptions(pCxt); } break; - case 164: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 167: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-2].minor.yy452, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 165: /* table_options ::= table_options MAX_DELAY duration_list */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy600); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 168: /* table_options ::= table_options MAX_DELAY duration_list */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-2].minor.yy452, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy404); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 166: /* table_options ::= table_options WATERMARK duration_list */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy600); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 169: /* table_options ::= table_options WATERMARK duration_list */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-2].minor.yy452, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy404); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 167: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-4].minor.yy392, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy600); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + case 170: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-4].minor.yy452, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy404); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; break; - case 168: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-2].minor.yy392, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 171: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-2].minor.yy452, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 169: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-4].minor.yy392, TABLE_OPTION_SMA, yymsp[-1].minor.yy600); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + case 172: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-4].minor.yy452, TABLE_OPTION_SMA, yymsp[-1].minor.yy404); } + yymsp[-4].minor.yy452 = yylhsminor.yy452; break; - case 170: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy392 = createAlterTableOptions(pCxt); yylhsminor.yy392 = setTableOption(pCxt, yylhsminor.yy392, yymsp[0].minor.yy221.type, &yymsp[0].minor.yy221.val); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 173: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy452 = createAlterTableOptions(pCxt); yylhsminor.yy452 = setTableOption(pCxt, yylhsminor.yy452, yymsp[0].minor.yy85.type, &yymsp[0].minor.yy85.val); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 171: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy392 = setTableOption(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy221.type, &yymsp[0].minor.yy221.val); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 174: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy452 = setTableOption(pCxt, yymsp[-1].minor.yy452, yymsp[0].minor.yy85.type, &yymsp[0].minor.yy85.val); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 172: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy221.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } + case 175: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy85.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } break; - case 173: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy221.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy221.val = yymsp[0].minor.yy0; } + case 176: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy85.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy85.val = yymsp[0].minor.yy0; } break; - case 174: /* duration_list ::= duration_literal */ - case 322: /* expression_list ::= expression */ yytestcase(yyruleno==322); -{ yylhsminor.yy600 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[0].minor.yy600 = yylhsminor.yy600; + case 177: /* duration_list ::= duration_literal */ + case 332: /* expression_list ::= expression */ yytestcase(yyruleno==332); +{ yylhsminor.yy404 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy452)); } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 175: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 323: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==323); -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[-2].minor.yy600 = yylhsminor.yy600; + case 178: /* duration_list ::= duration_list NK_COMMA duration_literal */ + case 333: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==333); +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, releaseRawExprNode(pCxt, yymsp[0].minor.yy452)); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; break; - case 178: /* rollup_func_name ::= function_name */ -{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[0].minor.yy57, NULL); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 181: /* rollup_func_name ::= function_name */ +{ yylhsminor.yy452 = createFunctionNode(pCxt, &yymsp[0].minor.yy109, NULL); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 179: /* rollup_func_name ::= FIRST */ - case 180: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==180); -{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 182: /* rollup_func_name ::= FIRST */ + case 183: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==183); +{ yylhsminor.yy452 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 183: /* col_name ::= column_name */ -{ yylhsminor.yy392 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy57); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 186: /* col_name ::= column_name */ +{ yylhsminor.yy452 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy109); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 184: /* cmd ::= SHOW DNODES */ + case 187: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; - case 185: /* cmd ::= SHOW USERS */ + case 188: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; - case 186: /* cmd ::= SHOW DATABASES */ + case 189: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; - case 187: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, OP_TYPE_LIKE); } + case 190: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy452, yymsp[0].minor.yy452, OP_TYPE_LIKE); } break; - case 188: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, OP_TYPE_LIKE); } + case 191: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy452, yymsp[0].minor.yy452, OP_TYPE_LIKE); } break; - case 189: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy392, NULL, OP_TYPE_LIKE); } + case 192: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy452, NULL, OP_TYPE_LIKE); } break; - case 190: /* cmd ::= SHOW MNODES */ + case 193: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; - case 191: /* cmd ::= SHOW MODULES */ + case 194: /* cmd ::= SHOW MODULES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); } break; - case 192: /* cmd ::= SHOW QNODES */ + case 195: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; - case 193: /* cmd ::= SHOW FUNCTIONS */ + case 196: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; - case 194: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy392, yymsp[-1].minor.yy392, OP_TYPE_EQUAL); } + case 197: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy452, yymsp[-1].minor.yy452, OP_TYPE_EQUAL); } break; - case 195: /* cmd ::= SHOW STREAMS */ + case 198: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; - case 196: /* cmd ::= SHOW ACCOUNTS */ + case 199: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 197: /* cmd ::= SHOW APPS */ + case 200: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; - case 198: /* cmd ::= SHOW CONNECTIONS */ + case 201: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; - case 199: /* cmd ::= SHOW LICENCE */ - case 200: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==200); + case 202: /* cmd ::= SHOW LICENCE */ + case 203: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==203); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT); } break; - case 201: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy57); } + case 204: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy109); } break; - case 202: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy392); } + case 205: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy452); } break; - case 203: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy392); } + case 206: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy452); } break; - case 204: /* cmd ::= SHOW QUERIES */ + case 207: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; - case 205: /* cmd ::= SHOW SCORES */ + case 208: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; - case 206: /* cmd ::= SHOW TOPICS */ + case 209: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; - case 207: /* cmd ::= SHOW VARIABLES */ + case 210: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 208: /* cmd ::= SHOW LOCAL VARIABLES */ + case 211: /* cmd ::= SHOW LOCAL VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 209: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ + case 212: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES */ { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-1].minor.yy0)); } break; - case 210: /* cmd ::= SHOW BNODES */ + case 213: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 211: /* cmd ::= SHOW SNODES */ + case 214: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 212: /* cmd ::= SHOW CLUSTER */ + case 215: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 213: /* cmd ::= SHOW TRANSACTIONS */ + case 216: /* cmd ::= SHOW TRANSACTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 214: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ -{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy392); } + case 217: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ +{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy452); } break; - case 215: /* db_name_cond_opt ::= */ - case 220: /* from_db_opt ::= */ yytestcase(yyruleno==220); -{ yymsp[1].minor.yy392 = createDefaultDatabaseCondValue(pCxt); } + case 218: /* cmd ::= SHOW CONSUMERS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } break; - case 216: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy57); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 219: /* cmd ::= SHOW SUBSCRIPTIONS */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } break; - case 217: /* like_pattern_opt ::= */ - case 225: /* index_options ::= */ yytestcase(yyruleno==225); - case 254: /* into_opt ::= */ yytestcase(yyruleno==254); - case 410: /* where_clause_opt ::= */ yytestcase(yyruleno==410); - case 414: /* twindow_clause_opt ::= */ yytestcase(yyruleno==414); - case 419: /* sliding_opt ::= */ yytestcase(yyruleno==419); - case 421: /* fill_opt ::= */ yytestcase(yyruleno==421); - case 433: /* having_clause_opt ::= */ yytestcase(yyruleno==433); - case 435: /* range_opt ::= */ yytestcase(yyruleno==435); - case 437: /* every_opt ::= */ yytestcase(yyruleno==437); - case 447: /* slimit_clause_opt ::= */ yytestcase(yyruleno==447); - case 451: /* limit_clause_opt ::= */ yytestcase(yyruleno==451); -{ yymsp[1].minor.yy392 = NULL; } + case 220: /* db_name_cond_opt ::= */ + case 225: /* from_db_opt ::= */ yytestcase(yyruleno==225); +{ yymsp[1].minor.yy452 = createDefaultDatabaseCondValue(pCxt); } break; - case 218: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 221: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy109); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 219: /* table_name_cond ::= table_name */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy57); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 222: /* like_pattern_opt ::= */ + case 262: /* into_opt ::= */ yytestcase(yyruleno==262); + case 391: /* from_clause_opt ::= */ yytestcase(yyruleno==391); + case 421: /* where_clause_opt ::= */ yytestcase(yyruleno==421); + case 425: /* twindow_clause_opt ::= */ yytestcase(yyruleno==425); + case 430: /* sliding_opt ::= */ yytestcase(yyruleno==430); + case 432: /* fill_opt ::= */ yytestcase(yyruleno==432); + case 444: /* having_clause_opt ::= */ yytestcase(yyruleno==444); + case 446: /* range_opt ::= */ yytestcase(yyruleno==446); + case 448: /* every_opt ::= */ yytestcase(yyruleno==448); + case 458: /* slimit_clause_opt ::= */ yytestcase(yyruleno==458); + case 462: /* limit_clause_opt ::= */ yytestcase(yyruleno==462); +{ yymsp[1].minor.yy452 = NULL; } break; - case 221: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy57); } + case 223: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 222: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, &yymsp[-1].minor.yy57, NULL, yymsp[0].minor.yy392); } + case 224: /* table_name_cond ::= table_name */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy109); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 223: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy481, &yymsp[-5].minor.yy57, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600, NULL); } + case 226: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy109); } break; - case 224: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } + case 227: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy437, &yymsp[-3].minor.yy109, &yymsp[-1].minor.yy109, NULL, yymsp[0].minor.yy452); } break; - case 226: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy392 = createIndexOption(pCxt, yymsp[-6].minor.yy600, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL, yymsp[0].minor.yy392); } + case 228: /* cmd ::= DROP INDEX exists_opt index_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy437, &yymsp[0].minor.yy109); } break; - case 227: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy392 = createIndexOption(pCxt, yymsp[-8].minor.yy600, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[0].minor.yy392); } + case 229: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-9].minor.yy452 = createIndexOption(pCxt, yymsp[-7].minor.yy404, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), NULL, yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 230: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 230: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-11].minor.yy452 = createIndexOption(pCxt, yymsp[-9].minor.yy404, releaseRawExprNode(pCxt, yymsp[-5].minor.yy452), releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 231: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, yymsp[0].minor.yy392, NULL, NULL); } + case 233: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy452 = createFunctionNode(pCxt, &yymsp[-3].minor.yy109, yymsp[-1].minor.yy404); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 232: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, NULL, &yymsp[0].minor.yy57, NULL); } + case 234: /* sma_stream_opt ::= */ + case 264: /* stream_options ::= */ yytestcase(yyruleno==264); +{ yymsp[1].minor.yy452 = createStreamOptions(pCxt); } break; - case 233: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-4].minor.yy481, &yymsp[-3].minor.yy57, NULL, NULL, yymsp[0].minor.yy392); } + case 235: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ + case 268: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==268); +{ ((SStreamOptions*)yymsp[-2].minor.yy452)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy452); yylhsminor.yy452 = yymsp[-2].minor.yy452; } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 234: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } + case 236: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy452)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy452); yylhsminor.yy452 = yymsp[-2].minor.yy452; } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 235: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy481, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57); } + case 237: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy437, &yymsp[-2].minor.yy109, yymsp[0].minor.yy452); } break; - case 236: /* cmd ::= DESC full_table_name */ - case 237: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==237); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy392); } + case 238: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy437, &yymsp[-3].minor.yy109, &yymsp[0].minor.yy109, false); } break; - case 238: /* cmd ::= RESET QUERY CACHE */ + case 239: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy437, &yymsp[-5].minor.yy109, &yymsp[0].minor.yy109, true); } + break; + case 240: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy437, &yymsp[-3].minor.yy109, yymsp[0].minor.yy452, false); } + break; + case 241: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy437, &yymsp[-5].minor.yy109, yymsp[0].minor.yy452, true); } + break; + case 242: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy437, &yymsp[0].minor.yy109); } + break; + case 243: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ +{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy437, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109); } + break; + case 244: /* cmd ::= DESC full_table_name */ + case 245: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==245); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy452); } + break; + case 246: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 239: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy481, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 247: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy437, yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 241: /* analyze_opt ::= ANALYZE */ - case 249: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==249); - case 400: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==400); -{ yymsp[0].minor.yy481 = true; } + case 249: /* analyze_opt ::= ANALYZE */ + case 257: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==257); + case 411: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==411); +{ yymsp[0].minor.yy437 = true; } break; - case 242: /* explain_options ::= */ -{ yymsp[1].minor.yy392 = createDefaultExplainOptions(pCxt); } + case 250: /* explain_options ::= */ +{ yymsp[1].minor.yy452 = createDefaultExplainOptions(pCxt); } break; - case 243: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy392 = setExplainVerbose(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 251: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy452 = setExplainVerbose(pCxt, yymsp[-2].minor.yy452, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 244: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy392 = setExplainRatio(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 252: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy452 = setExplainRatio(pCxt, yymsp[-2].minor.yy452, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 245: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy600); } + case 253: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy404); } break; - case 246: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy481, yymsp[-8].minor.yy481, &yymsp[-5].minor.yy57, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy448, yymsp[0].minor.yy228); } + case 254: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy437, yymsp[-8].minor.yy437, &yymsp[-5].minor.yy109, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy504, yymsp[0].minor.yy100); } break; - case 247: /* cmd ::= DROP FUNCTION exists_opt function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } + case 255: /* cmd ::= DROP FUNCTION exists_opt function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy437, &yymsp[0].minor.yy109); } break; - case 250: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy228 = 0; } + case 258: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy100 = 0; } break; - case 251: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy228 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } + case 259: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy100 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 252: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy481, &yymsp[-4].minor.yy57, yymsp[-2].minor.yy392, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } + case 260: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy437, &yymsp[-4].minor.yy109, yymsp[-2].minor.yy452, yymsp[-3].minor.yy452, yymsp[0].minor.yy452); } break; - case 253: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy481, &yymsp[0].minor.yy57); } + case 261: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy437, &yymsp[0].minor.yy109); } break; - case 255: /* into_opt ::= INTO full_table_name */ - case 381: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==381); - case 411: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==411); - case 434: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==434); -{ yymsp[-1].minor.yy392 = yymsp[0].minor.yy392; } + case 263: /* into_opt ::= INTO full_table_name */ + case 392: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==392); + case 422: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==422); + case 445: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==445); +{ yymsp[-1].minor.yy452 = yymsp[0].minor.yy452; } break; - case 256: /* stream_options ::= */ -{ yymsp[1].minor.yy392 = createStreamOptions(pCxt); } + case 265: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy452)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy452 = yymsp[-2].minor.yy452; } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 257: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 266: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy452)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy452 = yymsp[-2].minor.yy452; } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 258: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 267: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-3].minor.yy452)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy452)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy452); yylhsminor.yy452 = yymsp[-3].minor.yy452; } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 259: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-3].minor.yy392)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy392)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); yylhsminor.yy392 = yymsp[-3].minor.yy392; } - yymsp[-3].minor.yy392 = yylhsminor.yy392; - break; - case 260: /* stream_options ::= stream_options WATERMARK duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy392)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); yylhsminor.yy392 = yymsp[-2].minor.yy392; } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 261: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 269: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 262: /* cmd ::= KILL QUERY NK_STRING */ + case 270: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 263: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 271: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 264: /* cmd ::= BALANCE VGROUP */ + case 272: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 265: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 273: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 266: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy600); } + case 274: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy404); } break; - case 267: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 275: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 268: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy600 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + case 276: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy404 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 270: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy57); } + case 278: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy109); } break; - case 271: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 279: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ +{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 273: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 281: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 274: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 282: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 275: /* literal ::= NK_STRING */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 283: /* literal ::= NK_STRING */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 276: /* literal ::= NK_BOOL */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 284: /* literal ::= NK_BOOL */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 277: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 285: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 278: /* literal ::= duration_literal */ - case 288: /* signed_literal ::= signed */ yytestcase(yyruleno==288); - case 308: /* expression ::= literal */ yytestcase(yyruleno==308); - case 309: /* expression ::= pseudo_column */ yytestcase(yyruleno==309); - case 310: /* expression ::= column_reference */ yytestcase(yyruleno==310); - case 311: /* expression ::= function_expression */ yytestcase(yyruleno==311); - case 312: /* expression ::= subquery */ yytestcase(yyruleno==312); - case 337: /* function_expression ::= literal_func */ yytestcase(yyruleno==337); - case 373: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==373); - case 377: /* boolean_primary ::= predicate */ yytestcase(yyruleno==377); - case 379: /* common_expression ::= expression */ yytestcase(yyruleno==379); - case 380: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==380); - case 382: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==382); - case 384: /* table_reference ::= table_primary */ yytestcase(yyruleno==384); - case 385: /* table_reference ::= joined_table */ yytestcase(yyruleno==385); - case 389: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==389); - case 440: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==440); - case 443: /* query_primary ::= query_specification */ yytestcase(yyruleno==443); -{ yylhsminor.yy392 = yymsp[0].minor.yy392; } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 286: /* literal ::= duration_literal */ + case 296: /* signed_literal ::= signed */ yytestcase(yyruleno==296); + case 316: /* expression ::= literal */ yytestcase(yyruleno==316); + case 317: /* expression ::= pseudo_column */ yytestcase(yyruleno==317); + case 318: /* expression ::= column_reference */ yytestcase(yyruleno==318); + case 319: /* expression ::= function_expression */ yytestcase(yyruleno==319); + case 320: /* expression ::= subquery */ yytestcase(yyruleno==320); + case 347: /* function_expression ::= literal_func */ yytestcase(yyruleno==347); + case 383: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==383); + case 387: /* boolean_primary ::= predicate */ yytestcase(yyruleno==387); + case 389: /* common_expression ::= expression */ yytestcase(yyruleno==389); + case 390: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==390); + case 393: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==393); + case 395: /* table_reference ::= table_primary */ yytestcase(yyruleno==395); + case 396: /* table_reference ::= joined_table */ yytestcase(yyruleno==396); + case 400: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==400); + case 451: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==451); + case 454: /* query_primary ::= query_specification */ yytestcase(yyruleno==454); +{ yylhsminor.yy452 = yymsp[0].minor.yy452; } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 279: /* literal ::= NULL */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 287: /* literal ::= NULL */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 280: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 288: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 281: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 289: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 282: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 290: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 283: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 291: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 284: /* signed ::= NK_MINUS NK_INTEGER */ + case 292: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 285: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 293: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 286: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 294: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 287: /* signed ::= NK_MINUS NK_FLOAT */ + case 295: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 289: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 297: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 290: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 298: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 291: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 299: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 292: /* signed_literal ::= duration_literal */ - case 294: /* signed_literal ::= literal_func */ yytestcase(yyruleno==294); - case 351: /* star_func_para ::= expression */ yytestcase(yyruleno==351); - case 406: /* select_item ::= common_expression */ yytestcase(yyruleno==406); - case 456: /* search_condition ::= common_expression */ yytestcase(yyruleno==456); -{ yylhsminor.yy392 = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 300: /* signed_literal ::= duration_literal */ + case 302: /* signed_literal ::= literal_func */ yytestcase(yyruleno==302); + case 361: /* star_func_para ::= expression */ yytestcase(yyruleno==361); + case 417: /* select_item ::= common_expression */ yytestcase(yyruleno==417); + case 467: /* search_condition ::= common_expression */ yytestcase(yyruleno==467); +{ yylhsminor.yy452 = releaseRawExprNode(pCxt, yymsp[0].minor.yy452); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 293: /* signed_literal ::= NULL */ -{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy392 = yylhsminor.yy392; + case 301: /* signed_literal ::= NULL */ +{ yylhsminor.yy452 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy452 = yylhsminor.yy452; break; - case 313: /* expression ::= NK_LP expression NK_RP */ - case 378: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==378); -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 321: /* expression ::= NK_LP expression NK_RP */ + case 388: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==388); +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy452)); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 314: /* expression ::= NK_PLUS expression */ + case 322: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy452)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 315: /* expression ::= NK_MINUS expression */ + case 323: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy452), NULL)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 316: /* expression ::= expression NK_PLUS expression */ + case 324: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 317: /* expression ::= expression NK_MINUS expression */ + case 325: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 318: /* expression ::= expression NK_STAR expression */ + case 326: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 319: /* expression ::= expression NK_SLASH expression */ + case 327: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 320: /* expression ::= expression NK_REM expression */ + case 328: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 321: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 329: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 324: /* column_reference ::= column_name */ -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy57, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy57)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; - break; - case 325: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57, createColumnNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy57)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 326: /* pseudo_column ::= ROWTS */ - case 327: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==327); - case 329: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==329); - case 330: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==330); - case 331: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==331); - case 332: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==332); - case 333: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==333); - case 339: /* literal_func ::= NOW */ yytestcase(yyruleno==339); -{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy392 = yylhsminor.yy392; - break; - case 328: /* pseudo_column ::= table_name NK_DOT TBNAME */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy57)))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 334: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 335: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==335); -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy57, yymsp[-1].minor.yy600)); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; - break; - case 336: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy448)); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; - break; - case 338: /* literal_func ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy57, NULL)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 347: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy600 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy600 = yylhsminor.yy600; - break; - case 352: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 409: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==409); -{ yylhsminor.yy392 = createColumnNode(pCxt, &yymsp[-2].minor.yy57, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 353: /* predicate ::= expression compare_op expression */ - case 358: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==358); + case 330: /* expression ::= expression NK_BITAND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy324, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 354: /* predicate ::= expression BETWEEN expression AND expression */ + case 331: /* expression ::= expression NK_BITOR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-4].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 355: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 334: /* column_reference ::= column_name */ +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy109, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy109)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; + break; + case 335: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109, createColumnNode(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy109)); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 336: /* pseudo_column ::= ROWTS */ + case 337: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==337); + case 339: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==339); + case 340: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==340); + case 341: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==341); + case 342: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==342); + case 343: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==343); + case 349: /* literal_func ::= NOW */ yytestcase(yyruleno==349); +{ yylhsminor.yy452 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy452 = yylhsminor.yy452; + break; + case 338: /* pseudo_column ::= table_name NK_DOT TBNAME */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy109)))); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 344: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 345: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==345); +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy109, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy109, yymsp[-1].minor.yy404)); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; + break; + case 346: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), yymsp[-1].minor.yy504)); } + yymsp[-5].minor.yy452 = yylhsminor.yy452; + break; + case 348: /* literal_func ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy109, NULL)); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 357: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy404 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy404 = yylhsminor.yy404; + break; + case 362: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 420: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==420); +{ yylhsminor.yy452 = createColumnNode(pCxt, &yymsp[-2].minor.yy109, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 363: /* predicate ::= expression compare_op expression */ + case 368: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==368); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy440, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 356: /* predicate ::= expression IS NULL */ + case 364: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy452), releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-4].minor.yy452 = yylhsminor.yy452; break; - case 357: /* predicate ::= expression IS NOT NULL */ + case 365: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy452), releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + yymsp[-5].minor.yy452 = yylhsminor.yy452; break; - case 359: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy324 = OP_TYPE_LOWER_THAN; } - break; - case 360: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy324 = OP_TYPE_GREATER_THAN; } - break; - case 361: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy324 = OP_TYPE_LOWER_EQUAL; } - break; - case 362: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy324 = OP_TYPE_GREATER_EQUAL; } - break; - case 363: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy324 = OP_TYPE_NOT_EQUAL; } - break; - case 364: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy324 = OP_TYPE_EQUAL; } - break; - case 365: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy324 = OP_TYPE_LIKE; } - break; - case 366: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy324 = OP_TYPE_NOT_LIKE; } - break; - case 367: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy324 = OP_TYPE_MATCH; } - break; - case 368: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy324 = OP_TYPE_NMATCH; } - break; - case 369: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy324 = OP_TYPE_JSON_CONTAINS; } - break; - case 370: /* in_op ::= IN */ -{ yymsp[0].minor.yy324 = OP_TYPE_IN; } - break; - case 371: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy324 = OP_TYPE_NOT_IN; } - break; - case 372: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy600)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; - break; - case 374: /* boolean_value_expression ::= NOT boolean_primary */ + case 366: /* predicate ::= expression IS NULL */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), NULL)); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 375: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 367: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), NULL)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 376: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 369: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy440 = OP_TYPE_LOWER_THAN; } + break; + case 370: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy440 = OP_TYPE_GREATER_THAN; } + break; + case 371: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy440 = OP_TYPE_LOWER_EQUAL; } + break; + case 372: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy440 = OP_TYPE_GREATER_EQUAL; } + break; + case 373: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy440 = OP_TYPE_NOT_EQUAL; } + break; + case 374: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy440 = OP_TYPE_EQUAL; } + break; + case 375: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy440 = OP_TYPE_LIKE; } + break; + case 376: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy440 = OP_TYPE_NOT_LIKE; } + break; + case 377: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy440 = OP_TYPE_MATCH; } + break; + case 378: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy440 = OP_TYPE_NMATCH; } + break; + case 379: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy440 = OP_TYPE_JSON_CONTAINS; } + break; + case 380: /* in_op ::= IN */ +{ yymsp[0].minor.yy440 = OP_TYPE_IN; } + break; + case 381: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy440 = OP_TYPE_NOT_IN; } + break; + case 382: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; + break; + case 384: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); - yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy452), NULL)); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 383: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy392 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, NULL); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 385: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); + } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 386: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 386: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ +{ + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy452); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy452); + yylhsminor.yy452 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); + } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 387: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-3].minor.yy57, &yymsp[-1].minor.yy57, &yymsp[0].minor.yy57); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 394: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy452 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy452, yymsp[0].minor.yy452, NULL); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 388: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy392 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy57); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 397: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy452 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy109, &yymsp[0].minor.yy109); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 390: /* alias_opt ::= */ -{ yymsp[1].minor.yy57 = nil_token; } + case 398: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy452 = createRealTableNode(pCxt, &yymsp[-3].minor.yy109, &yymsp[-1].minor.yy109, &yymsp[0].minor.yy109); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 391: /* alias_opt ::= table_alias */ -{ yylhsminor.yy57 = yymsp[0].minor.yy57; } - yymsp[0].minor.yy57 = yylhsminor.yy57; + case 399: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy452 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy452), &yymsp[0].minor.yy109); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 392: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy57 = yymsp[0].minor.yy57; } + case 401: /* alias_opt ::= */ +{ yymsp[1].minor.yy109 = nil_token; } break; - case 393: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 394: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==394); -{ yymsp[-2].minor.yy392 = yymsp[-1].minor.yy392; } + case 402: /* alias_opt ::= table_alias */ +{ yylhsminor.yy109 = yymsp[0].minor.yy109; } + yymsp[0].minor.yy109 = yylhsminor.yy109; break; - case 395: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy392 = createJoinTableNode(pCxt, yymsp[-4].minor.yy204, yymsp[-5].minor.yy392, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-5].minor.yy392 = yylhsminor.yy392; + case 403: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy109 = yymsp[0].minor.yy109; } break; - case 396: /* join_type ::= */ -{ yymsp[1].minor.yy204 = JOIN_TYPE_INNER; } + case 404: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 405: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==405); +{ yymsp[-2].minor.yy452 = yymsp[-1].minor.yy452; } break; - case 397: /* join_type ::= INNER */ -{ yymsp[0].minor.yy204 = JOIN_TYPE_INNER; } + case 406: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy452 = createJoinTableNode(pCxt, yymsp[-4].minor.yy532, yymsp[-5].minor.yy452, yymsp[-2].minor.yy452, yymsp[0].minor.yy452); } + yymsp[-5].minor.yy452 = yylhsminor.yy452; break; - case 398: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 407: /* join_type ::= */ +{ yymsp[1].minor.yy532 = JOIN_TYPE_INNER; } + break; + case 408: /* join_type ::= INNER */ +{ yymsp[0].minor.yy532 = JOIN_TYPE_INNER; } + break; + case 409: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-11].minor.yy392 = createSelectStmt(pCxt, yymsp[-10].minor.yy481, yymsp[-9].minor.yy600, yymsp[-8].minor.yy392); - yymsp[-11].minor.yy392 = addWhereClause(pCxt, yymsp[-11].minor.yy392, yymsp[-7].minor.yy392); - yymsp[-11].minor.yy392 = addPartitionByClause(pCxt, yymsp[-11].minor.yy392, yymsp[-6].minor.yy600); - yymsp[-11].minor.yy392 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy392, yymsp[-2].minor.yy392); - yymsp[-11].minor.yy392 = addGroupByClause(pCxt, yymsp[-11].minor.yy392, yymsp[-1].minor.yy600); - yymsp[-11].minor.yy392 = addHavingClause(pCxt, yymsp[-11].minor.yy392, yymsp[0].minor.yy392); - yymsp[-11].minor.yy392 = addRangeClause(pCxt, yymsp[-11].minor.yy392, yymsp[-5].minor.yy392); - yymsp[-11].minor.yy392 = addEveryClause(pCxt, yymsp[-11].minor.yy392, yymsp[-4].minor.yy392); - yymsp[-11].minor.yy392 = addFillClause(pCxt, yymsp[-11].minor.yy392, yymsp[-3].minor.yy392); + yymsp[-11].minor.yy452 = createSelectStmt(pCxt, yymsp[-10].minor.yy437, yymsp[-9].minor.yy404, yymsp[-8].minor.yy452); + yymsp[-11].minor.yy452 = addWhereClause(pCxt, yymsp[-11].minor.yy452, yymsp[-7].minor.yy452); + yymsp[-11].minor.yy452 = addPartitionByClause(pCxt, yymsp[-11].minor.yy452, yymsp[-6].minor.yy404); + yymsp[-11].minor.yy452 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy452, yymsp[-2].minor.yy452); + yymsp[-11].minor.yy452 = addGroupByClause(pCxt, yymsp[-11].minor.yy452, yymsp[-1].minor.yy404); + yymsp[-11].minor.yy452 = addHavingClause(pCxt, yymsp[-11].minor.yy452, yymsp[0].minor.yy452); + yymsp[-11].minor.yy452 = addRangeClause(pCxt, yymsp[-11].minor.yy452, yymsp[-5].minor.yy452); + yymsp[-11].minor.yy452 = addEveryClause(pCxt, yymsp[-11].minor.yy452, yymsp[-4].minor.yy452); + yymsp[-11].minor.yy452 = addFillClause(pCxt, yymsp[-11].minor.yy452, yymsp[-3].minor.yy452); } break; - case 401: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy481 = false; } + case 412: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy437 = false; } break; - case 402: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy600 = NULL; } + case 413: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy404 = NULL; } break; - case 407: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy57); } - yymsp[-1].minor.yy392 = yylhsminor.yy392; + case 418: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy452 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy452), &yymsp[0].minor.yy109); } + yymsp[-1].minor.yy452 = yylhsminor.yy452; break; - case 408: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), &yymsp[0].minor.yy57); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 419: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy452 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), &yymsp[0].minor.yy109); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 413: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 430: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==430); - case 446: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==446); -{ yymsp[-2].minor.yy600 = yymsp[0].minor.yy600; } + case 424: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 441: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==441); + case 457: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==457); +{ yymsp[-2].minor.yy404 = yymsp[0].minor.yy404; } break; - case 415: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy392 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + case 426: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy452 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), releaseRawExprNode(pCxt, yymsp[-1].minor.yy452)); } break; - case 416: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy392 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + case 427: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy452 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy452)); } break; - case 417: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 428: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy452 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), NULL, yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 418: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + case 429: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy452 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy452), releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), yymsp[-1].minor.yy452, yymsp[0].minor.yy452); } break; - case 420: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - case 438: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==438); -{ yymsp[-3].minor.yy392 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy392); } + case 431: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + case 449: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==449); +{ yymsp[-3].minor.yy452 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy452); } break; - case 422: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy392 = createFillNode(pCxt, yymsp[-1].minor.yy270, NULL); } + case 433: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy452 = createFillNode(pCxt, yymsp[-1].minor.yy614, NULL); } break; - case 423: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy392 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy600)); } + case 434: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy452 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy404)); } break; - case 424: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy270 = FILL_MODE_NONE; } + case 435: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy614 = FILL_MODE_NONE; } break; - case 425: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy270 = FILL_MODE_PREV; } + case 436: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy614 = FILL_MODE_PREV; } break; - case 426: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy270 = FILL_MODE_NULL; } + case 437: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy614 = FILL_MODE_NULL; } break; - case 427: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy270 = FILL_MODE_LINEAR; } + case 438: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy614 = FILL_MODE_LINEAR; } break; - case 428: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy270 = FILL_MODE_NEXT; } + case 439: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy614 = FILL_MODE_NEXT; } break; - case 431: /* group_by_list ::= expression */ -{ yylhsminor.yy600 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[0].minor.yy600 = yylhsminor.yy600; + case 442: /* group_by_list ::= expression */ +{ yylhsminor.yy404 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } + yymsp[0].minor.yy404 = yylhsminor.yy404; break; - case 432: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy600 = addNodeToList(pCxt, yymsp[-2].minor.yy600, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy600 = yylhsminor.yy600; + case 443: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy404 = addNodeToList(pCxt, yymsp[-2].minor.yy404, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy452))); } + yymsp[-2].minor.yy404 = yylhsminor.yy404; break; - case 436: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ -{ yymsp[-5].minor.yy392 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + case 447: /* range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ +{ yymsp[-5].minor.yy452 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy452), releaseRawExprNode(pCxt, yymsp[-1].minor.yy452)); } break; - case 439: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 450: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy392 = addOrderByClause(pCxt, yymsp[-3].minor.yy392, yymsp[-2].minor.yy600); - yylhsminor.yy392 = addSlimitClause(pCxt, yylhsminor.yy392, yymsp[-1].minor.yy392); - yylhsminor.yy392 = addLimitClause(pCxt, yylhsminor.yy392, yymsp[0].minor.yy392); + yylhsminor.yy452 = addOrderByClause(pCxt, yymsp[-3].minor.yy452, yymsp[-2].minor.yy404); + yylhsminor.yy452 = addSlimitClause(pCxt, yylhsminor.yy452, yymsp[-1].minor.yy452); + yylhsminor.yy452 = addLimitClause(pCxt, yylhsminor.yy452, yymsp[0].minor.yy452); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 441: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-3].minor.yy392 = yylhsminor.yy392; + case 452: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy452 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy452, yymsp[0].minor.yy452); } + yymsp[-3].minor.yy452 = yylhsminor.yy452; break; - case 442: /* query_expression_body ::= query_expression_body UNION query_expression_body */ -{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 453: /* query_expression_body ::= query_expression_body UNION query_expression_body */ +{ yylhsminor.yy452 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy452, yymsp[0].minor.yy452); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 444: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ -{ yymsp[-5].minor.yy392 = yymsp[-4].minor.yy392; } - yy_destructor(yypParser,356,&yymsp[-3].minor); - yy_destructor(yypParser,357,&yymsp[-2].minor); - yy_destructor(yypParser,358,&yymsp[-1].minor); + case 455: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ +{ yymsp[-5].minor.yy452 = yymsp[-4].minor.yy452; } + yy_destructor(yypParser,362,&yymsp[-3].minor); + yy_destructor(yypParser,363,&yymsp[-2].minor); + yy_destructor(yypParser,364,&yymsp[-1].minor); break; - case 448: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 452: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==452); -{ yymsp[-1].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 459: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 463: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==463); +{ yymsp[-1].minor.yy452 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 449: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 453: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==453); -{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 460: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 464: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==464); +{ yymsp[-3].minor.yy452 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 450: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 454: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==454); -{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 461: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 465: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==465); +{ yymsp[-3].minor.yy452 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 455: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy392); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 466: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy452 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy452); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 459: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy392 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[-1].minor.yy162, yymsp[0].minor.yy529); } - yymsp[-2].minor.yy392 = yylhsminor.yy392; + case 470: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy452 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy452), yymsp[-1].minor.yy178, yymsp[0].minor.yy77); } + yymsp[-2].minor.yy452 = yylhsminor.yy452; break; - case 460: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy162 = ORDER_ASC; } + case 471: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy178 = ORDER_ASC; } break; - case 461: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy162 = ORDER_ASC; } + case 472: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy178 = ORDER_ASC; } break; - case 462: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy162 = ORDER_DESC; } + case 473: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy178 = ORDER_DESC; } break; - case 463: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy529 = NULL_ORDER_DEFAULT; } + case 474: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy77 = NULL_ORDER_DEFAULT; } break; - case 464: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy529 = NULL_ORDER_FIRST; } + case 475: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy77 = NULL_ORDER_FIRST; } break; - case 465: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy529 = NULL_ORDER_LAST; } + case 476: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy77 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 8802f91bdf..36a2eb3808 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -25,95 +25,125 @@ #ifdef WINDOWS #define TD_USE_WINSOCK #endif + #include "mockCatalog.h" + +#include "systable.h" namespace { void generateInformationSchema(MockCatalogService* mcs) { { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1) - .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1) - .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) - .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) - .addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); - builder.done(); - } - { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) - .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODES, TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { ITableBuilder& builder = - mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1) + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MNODES, TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_MODULES, TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_QNODES, TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_DATABASES, TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_FUNCTIONS, TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_INDEXES, TSDB_SYSTEM_TABLE, 2) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_STABLES, TSDB_SYSTEM_TABLE, 2) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_TABLES, TSDB_SYSTEM_TABLE, 2) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN) + .addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, TSDB_SYSTEM_TABLE, 1) .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1) - .addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_USER_USERS, TSDB_SYSTEM_TABLE, 1) + .addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1) - .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, TSDB_SYSTEM_TABLE, 1) + .addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "configs", TSDB_SYSTEM_TABLE, 1) - .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS, TSDB_SYSTEM_TABLE, 1) + .addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_CONFIG_OPTION_LEN); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnode_variables", TSDB_SYSTEM_TABLE, 1) - .addColumn("dnode_id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_DNODE_VARIABLES, TSDB_SYSTEM_TABLE, 1) + .addColumn("dnode_id", TSDB_DATA_TYPE_INT); builder.done(); } } void generatePerformanceSchema(MockCatalogService* mcs) { { - ITableBuilder& builder = mcs->createTableBuilder("performance_schema", "trans", TSDB_SYSTEM_TABLE, 1) - .addColumn("id", TSDB_DATA_TYPE_INT); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_TRANS, TSDB_SYSTEM_TABLE, 1) + .addColumn("id", TSDB_DATA_TYPE_INT); builder.done(); } { - ITableBuilder& builder = mcs->createTableBuilder("performance_schema", "streams", TSDB_SYSTEM_TABLE, 1) - .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_STREAMS, TSDB_SYSTEM_TABLE, 1) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_CONSUMERS, TSDB_SYSTEM_TABLE, 1) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); + builder.done(); + } + { + ITableBuilder& builder = + mcs->createTableBuilder(TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_SUBSCRIPTIONS, TSDB_SYSTEM_TABLE, 1) + .addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN); builder.done(); } } @@ -261,7 +291,8 @@ int32_t __catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArra return g_mockCatalogService->catalogGetDnodeList(pDnodeList); } -int32_t __catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableCfg** pCfg) { +int32_t __catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, + STableCfg** pCfg) { *pCfg = (STableCfg*)taosMemoryCalloc(1, sizeof(STableCfg)); return 0; } diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 1f7657146b..8830bc7cb3 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -197,7 +197,7 @@ class MockCatalogServiceImpl { code = getAllTableIndex(pCatalogReq->pTableIndex, &pMetaData->pTableIndex); } if (TSDB_CODE_SUCCESS == code && pCatalogReq->dNodeRequired) { - code = catalogGetDnodeList(&pMetaData->pDnodeList); + code = getAllDnodeList(&pMetaData->pDnodeList); } if (TSDB_CODE_SUCCESS == code) { code = getAllTableCfg(pCatalogReq->pTableCfg, &pMetaData->pTableCfg); @@ -562,6 +562,14 @@ class MockCatalogServiceImpl { return TSDB_CODE_SUCCESS; } + int32_t getAllDnodeList(SArray** pDnodes) const { + SMetaRes res = {0}; + catalogGetDnodeList((SArray**)&res.pRes); + *pDnodes = taosArrayInit(1, sizeof(SMetaRes)); + taosArrayPush(*pDnodes, &res); + return TSDB_CODE_SUCCESS; + } + uint64_t id_; std::unique_ptr builder_; DbMetaCache meta_; diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index 021348dcc7..ee9dae2a01 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -121,7 +121,7 @@ TEST_F(ParserInitialATest, alterSTable) { int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname); expect.name[len] = '\0'; expect.alterType = alterType; -// expect.ttl = ttl; + // expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); expect.commentLen = strlen(pComment); @@ -180,9 +180,9 @@ TEST_F(ParserInitialATest, alterSTable) { tFreeSMAltertbReq(&req); }); -// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); -// run("ALTER TABLE st1 TTL 10"); -// clearAlterStbReq(); + // setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); + // run("ALTER TABLE st1 TTL 10"); + // clearAlterStbReq(); setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test"); run("ALTER TABLE st1 COMMENT 'test'"); @@ -381,9 +381,48 @@ TEST_F(ParserInitialATest, alterTableSemanticCheck) { TEST_F(ParserInitialATest, alterUser) { useDb("root", "test"); - run("ALTER user wxy PASS '123456'"); + SAlterUserReq expect = {0}; - run("ALTER user wxy privilege 'write'"); + auto clearAlterUserReq = [&]() { memset(&expect, 0, sizeof(SAlterUserReq)); }; + + auto setAlterUserReq = [&](const char* pUser, int8_t alterType, const char* pPass = nullptr, int8_t sysInfo = 0, + int8_t enable = 0) { + strcpy(expect.user, pUser); + expect.alterType = alterType; + expect.superUser = 0; + expect.sysInfo = sysInfo; + expect.enable = enable; + if (nullptr != pPass) { + strcpy(expect.pass, pPass); + } + strcpy(expect.dbname, "test"); + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_ALTER_USER_STMT); + SAlterUserReq req = {0}; + ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSAlterUserReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req)); + + ASSERT_EQ(req.alterType, expect.alterType); + ASSERT_EQ(req.superUser, expect.superUser); + ASSERT_EQ(req.sysInfo, expect.sysInfo); + ASSERT_EQ(req.enable, expect.enable); + ASSERT_EQ(std::string(req.user), std::string(expect.user)); + ASSERT_EQ(std::string(req.pass), std::string(expect.pass)); + ASSERT_EQ(std::string(req.dbname), std::string(expect.dbname)); + }); + + setAlterUserReq("wxy", TSDB_ALTER_USER_PASSWD, "123456"); + run("ALTER USER wxy PASS '123456'"); + clearAlterUserReq(); + + setAlterUserReq("wxy", TSDB_ALTER_USER_ENABLE, nullptr, 0, 1); + run("ALTER USER wxy ENABLE 1"); + clearAlterUserReq(); + + setAlterUserReq("wxy", TSDB_ALTER_USER_SYSINFO, nullptr, 1); + run("ALTER USER wxy SYSINFO 1"); + clearAlterUserReq(); } TEST_F(ParserInitialATest, balanceVgroup) { diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index d188744adf..7de92bba0c 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -370,7 +370,7 @@ TEST_F(ParserInitialCTest, createStable) { expect.delay2 = delay2; expect.watermark1 = watermark1; expect.watermark2 = watermark2; -// expect.ttl = ttl; + // expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); expect.commentLen = strlen(pComment); @@ -414,7 +414,7 @@ TEST_F(ParserInitialCTest, createStable) { ASSERT_EQ(req.ttl, expect.ttl); ASSERT_EQ(req.numOfColumns, expect.numOfColumns); ASSERT_EQ(req.numOfTags, expect.numOfTags); -// ASSERT_EQ(req.commentLen, expect.commentLen); + // ASSERT_EQ(req.commentLen, expect.commentLen); ASSERT_EQ(req.ast1Len, expect.ast1Len); ASSERT_EQ(req.ast2Len, expect.ast2Len); @@ -621,10 +621,11 @@ TEST_F(ParserInitialCTest, createTopic) { auto clearCreateTopicReq = [&]() { memset(&expect, 0, sizeof(SCMCreateTopicReq)); }; auto setCreateTopicReqFunc = [&](const char* pTopicName, int8_t igExists, const char* pSql, const char* pAst, - const char* pDbName = nullptr, const char* pTbname = nullptr) { + const char* pDbName = nullptr, const char* pTbname = nullptr, int8_t withMeta = 0) { snprintf(expect.name, sizeof(expect.name), "0.%s", pTopicName); expect.igExists = igExists; expect.sql = (char*)pSql; + expect.withMeta = withMeta; if (nullptr != pTbname) { expect.subType = TOPIC_SUB_TYPE__TABLE; snprintf(expect.subStbName, sizeof(expect.subStbName), "0.%s.%s", pDbName, pTbname); @@ -647,6 +648,7 @@ TEST_F(ParserInitialCTest, createTopic) { ASSERT_EQ(req.igExists, expect.igExists); ASSERT_EQ(req.subType, expect.subType); ASSERT_EQ(std::string(req.sql), std::string(expect.sql)); + ASSERT_EQ(req.withMeta, expect.withMeta); switch (expect.subType) { case TOPIC_SUB_TYPE__DB: ASSERT_EQ(std::string(req.subDbName), std::string(expect.subDbName)); @@ -675,15 +677,55 @@ TEST_F(ParserInitialCTest, createTopic) { run("CREATE TOPIC tp1 AS DATABASE test"); clearCreateTopicReq(); + setCreateTopicReqFunc("tp1", 0, "create topic tp1 with meta as database test", nullptr, "test", nullptr, 1); + run("CREATE TOPIC tp1 WITH META AS DATABASE test"); + clearCreateTopicReq(); + setCreateTopicReqFunc("tp1", 1, "create topic if not exists tp1 as stable st1", nullptr, "test", "st1"); run("CREATE TOPIC IF NOT EXISTS tp1 AS STABLE st1"); clearCreateTopicReq(); + + setCreateTopicReqFunc("tp1", 1, "create topic if not exists tp1 with meta as stable st1", nullptr, "test", "st1", 1); + run("CREATE TOPIC IF NOT EXISTS tp1 WITH META AS STABLE st1"); + clearCreateTopicReq(); } TEST_F(ParserInitialCTest, createUser) { useDb("root", "test"); + SCreateUserReq expect = {0}; + + auto clearCreateUserReq = [&]() { memset(&expect, 0, sizeof(SCreateUserReq)); }; + + auto setCreateUserReq = [&](const char* pUser, const char* pPass, int8_t sysInfo = 1) { + strcpy(expect.user, pUser); + strcpy(expect.pass, pPass); + expect.createType = 0; + expect.superUser = 0; + expect.sysInfo = sysInfo; + expect.enable = 1; + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_CREATE_USER_STMT); + SCreateUserReq req = {0}; + ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSCreateUserReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req)); + + ASSERT_EQ(req.createType, expect.createType); + ASSERT_EQ(req.superUser, expect.superUser); + ASSERT_EQ(req.sysInfo, expect.sysInfo); + ASSERT_EQ(req.enable, expect.enable); + ASSERT_EQ(std::string(req.user), std::string(expect.user)); + ASSERT_EQ(std::string(req.pass), std::string(expect.pass)); + }); + + setCreateUserReq("wxy", "123456"); run("CREATE USER wxy PASS '123456'"); + clearCreateUserReq(); + + setCreateUserReq("wxy1", "a123456", 1); + run("CREATE USER wxy1 PASS 'a123456' SYSINFO 1"); + clearCreateUserReq(); } } // namespace ParserTest diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp index c2039718d0..870afa694a 100644 --- a/source/libs/parser/test/parInitialDTest.cpp +++ b/source/libs/parser/test/parInitialDTest.cpp @@ -132,7 +132,31 @@ TEST_F(ParserInitialDTest, dropDnode) { TEST_F(ParserInitialDTest, dropIndex) { useDb("root", "test"); - run("DROP index index1 on t1"); + SMDropSmaReq expect = {0}; + + auto clearDropSmaReq = [&]() { memset(&expect, 0, sizeof(SMDropSmaReq)); }; + + auto setDropSmaReq = [&](const char* pName, int8_t igNotExists = 0) { + sprintf(expect.name, "0.test.%s", pName); + expect.igNotExists = igNotExists; + }; + + setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { + ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_DROP_INDEX_STMT); + SMDropSmaReq req = {0}; + ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSMDropSmaReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req)); + + ASSERT_EQ(std::string(req.name), std::string(expect.name)); + ASSERT_EQ(req.igNotExists, expect.igNotExists); + }); + + setDropSmaReq("index1"); + run("DROP INDEX index1"); + clearDropSmaReq(); + + setDropSmaReq("index2", 1); + run("DROP INDEX IF EXISTS index2"); + clearDropSmaReq(); } TEST_F(ParserInitialDTest, dropMnode) { diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index 11e09cd83d..5c8439f846 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -58,6 +58,8 @@ TEST_F(ParserSelectTest, expression) { run("SELECT ts > 0, c1 < 20 and c2 = 'qaz' FROM t1"); run("SELECT ts > 0, c1 between 10 and 20 and c2 = 'qaz' FROM t1"); + + run("SELECT c1 | 10, c2 & 20, c4 | c5 FROM t1"); } TEST_F(ParserSelectTest, condition) { @@ -142,15 +144,17 @@ TEST_F(ParserSelectTest, IndefiniteRowsFunc) { TEST_F(ParserSelectTest, IndefiniteRowsFuncSemanticCheck) { useDb("root", "test"); - run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE); + run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); - run("SELECT DIFF(c1), tbname FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE); + run("SELECT DIFF(c1), tbname FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); - run("SELECT DIFF(c1), count(*) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE); + run("SELECT DIFF(c1), count(*) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); - run("SELECT DIFF(c1), CSUM(c1) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE); + run("SELECT DIFF(c1), CSUM(c1) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC); - // run("SELECT DIFF(c1) FROM t1 INTERVAL(10s)"); + run("SELECT CSUM(c3) FROM t1 STATE_WINDOW(c1)", TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC); + + run("SELECT DIFF(c1) FROM t1 INTERVAL(10s)", TSDB_CODE_PAR_WINDOW_NOT_ALLOWED_FUNC); } TEST_F(ParserSelectTest, useDefinedFunc) { @@ -382,10 +386,22 @@ TEST_F(ParserSelectTest, setOperator) { run("SELECT c1, c2 FROM t1 UNION ALL SELECT c1 as a, c2 as b FROM t1 ORDER BY c1"); } +TEST_F(ParserSelectTest, setOperatorSemanticCheck) { + useDb("root", "test"); + + run("SELECT c1, c2 FROM t1 UNION ALL SELECT c1, c2 FROM t1 ORDER BY ts", TSDB_CODE_PAR_INVALID_COLUMN); +} + TEST_F(ParserSelectTest, informationSchema) { useDb("root", "test"); run("SELECT * FROM information_schema.user_databases WHERE name = 'information_schema'"); } +TEST_F(ParserSelectTest, withoutFrom) { + useDb("root", "test"); + + run("SELECT 1"); +} + } // namespace ParserTest diff --git a/source/libs/parser/test/parShowToUse.cpp b/source/libs/parser/test/parShowToUse.cpp index 81a09114e3..e109781169 100644 --- a/source/libs/parser/test/parShowToUse.cpp +++ b/source/libs/parser/test/parShowToUse.cpp @@ -25,6 +25,15 @@ class ParserShowToUseTest : public ParserDdlTest {}; // todo SHOW apps // todo SHOW connections +TEST_F(ParserShowToUseTest, showConsumers) { + useDb("root", "test"); + + setCheckDdlFunc( + [&](const SQuery* pQuery, ParserStage stage) { ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SELECT_STMT); }); + + run("SHOW CONSUMERS"); +} + TEST_F(ParserShowToUseTest, showCreateDatabase) { useDb("root", "test"); @@ -143,6 +152,15 @@ TEST_F(ParserShowToUseTest, showStreams) { run("SHOW streams"); } +TEST_F(ParserShowToUseTest, showSubscriptions) { + useDb("root", "test"); + + setCheckDdlFunc( + [&](const SQuery* pQuery, ParserStage stage) { ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SELECT_STMT); }); + + run("SHOW SUBSCRIPTIONS"); +} + TEST_F(ParserShowToUseTest, showTransactions) { useDb("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 36d2efc13f..ffb97bcc04 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -19,6 +19,7 @@ typedef struct SLogicPlanContext { SPlanContext* pPlanCxt; + SLogicNode* pCurrRoot; } SLogicPlanContext; typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, void*, SLogicNode**); @@ -140,6 +141,7 @@ static int32_t createRootLogicNode(SLogicPlanContext* pCxt, void* pStmt, uint8_t if (TSDB_CODE_SUCCESS == code && NULL != pNode) { pNode->precision = precision; code = pushLogicNode(pCxt, pRoot, pNode); + pCxt->pCurrRoot = pNode; } if (TSDB_CODE_SUCCESS != code) { nodesDestroyNode((SNode*)pNode); @@ -152,12 +154,16 @@ static int32_t createSelectRootLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p return createRootLogicNode(pCxt, pSelect, pSelect->precision, (FCreateLogicNode)func, pRoot); } -static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols, SNodeList* pScanCols, - int8_t tableType) { +static EScanType getScanType(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNodeList* pScanPseudoCols, + SNodeList* pScanCols, int8_t tableType) { if (pCxt->pPlanCxt->topicQuery || pCxt->pPlanCxt->streamQuery) { return SCAN_TYPE_STREAM; } + if (pSelect->hasLastRowFunc) { + return SCAN_TYPE_LAST_ROW; + } + if (NULL == pScanCols) { // select count(*) from t return NULL == pScanPseudoCols @@ -273,7 +279,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect code = rewriteExprsForSelect(pScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM); } - pScan->scanType = getScanType(pCxt, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType); + pScan->scanType = getScanType(pCxt, pSelect, pScan->pScanPseudoCols, pScan->pScanCols, pScan->tableType); if (TSDB_CODE_SUCCESS == code) { code = addPrimaryKeyCol(pScan->tableId, &pScan->pScanCols); @@ -296,6 +302,29 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } +static int32_t createColumnByLastRow(SNodeList* pFuncs, SNodeList** pOutput) { + int32_t code = TSDB_CODE_SUCCESS; + SNodeList* pCols = NULL; + SNode* pFunc = NULL; + FOREACH(pFunc, pFuncs) { + SFunctionNode* pLastRow = (SFunctionNode*)pFunc; + SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pLastRow->pParameterList, 0); + snprintf(pCol->colName, sizeof(pCol->colName), "%s", pLastRow->node.aliasName); + snprintf(pCol->node.aliasName, sizeof(pCol->colName), "%s", pLastRow->node.aliasName); + NODES_CLEAR_LIST(pLastRow->pParameterList); + code = nodesListMakeStrictAppend(&pCols, (SNode*)pCol); + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + if (TSDB_CODE_SUCCESS == code) { + *pOutput = pCols; + } else { + nodesDestroyList(pCols); + } + return code; +} + static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) { return createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode); @@ -390,6 +419,7 @@ static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSel } pNode->precision = pSelect->precision; *pLogicNode = pNode; + pCxt->pCurrRoot = pNode; } return code; } @@ -671,6 +701,10 @@ static int32_t createFillLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_WINDOW, NULL, COLLECT_COL_TYPE_ALL, &pFill->node.pTargets); + if (TSDB_CODE_SUCCESS == code && NULL == pFill->node.pTargets) { + code = nodesListMakeStrictAppend(&pFill->node.pTargets, + nodesCloneNode(nodesListGetNode(pCxt->pCurrRoot->pTargets, 0))); + } pFill->mode = pFillNode->mode; pFill->timeRange = pFillNode->timeRange; @@ -700,6 +734,10 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect } int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, COLLECT_COL_TYPE_ALL, &pSort->node.pTargets); + if (TSDB_CODE_SUCCESS == code && NULL == pSort->node.pTargets) { + code = nodesListMakeStrictAppend(&pSort->node.pTargets, + nodesCloneNode(nodesListGetNode(pCxt->pCurrRoot->pTargets, 0))); + } if (TSDB_CODE_SUCCESS == code) { pSort->pSortKeys = nodesCloneList(pSelect->pOrderByList); @@ -742,21 +780,8 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel return TSDB_CODE_OUT_OF_MEMORY; } - if (NULL != pSelect->pLimit) { - pProject->limit = pSelect->pLimit->limit; - pProject->offset = pSelect->pLimit->offset; - } else { - pProject->limit = -1; - pProject->offset = -1; - } - - if (NULL != pSelect->pSlimit) { - pProject->slimit = ((SLimitNode*)pSelect->pSlimit)->limit; - pProject->soffset = ((SLimitNode*)pSelect->pSlimit)->offset; - } else { - pProject->slimit = -1; - pProject->soffset = -1; - } + pProject->node.pLimit = (SNode*)pSelect->pLimit; + pProject->node.pSlimit = (SNode*)pSelect->pSlimit; int32_t code = TSDB_CODE_SUCCESS; @@ -791,6 +816,9 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_PARTITION_BY, NULL, COLLECT_COL_TYPE_ALL, &pPartition->node.pTargets); + if (TSDB_CODE_SUCCESS == code && NULL == pPartition->node.pTargets) { + code = nodesListMakeStrictAppend(&pPartition->node.pTargets, nodesListGetNode(pCxt->pCurrRoot->pTargets, 0)); + } if (TSDB_CODE_SUCCESS == code) { pPartition->pPartitionKeys = nodesCloneList(pSelect->pPartitionByList); @@ -844,7 +872,12 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe return code; } -static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { +static int32_t createSelectWithoutFromLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, + SLogicNode** pLogicNode) { + return createProjectLogicNode(pCxt, pSelect, pLogicNode); +} + +static int32_t createSelectFromLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { SLogicNode* pRoot = NULL; int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot); if (TSDB_CODE_SUCCESS == code) { @@ -884,6 +917,14 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele return code; } +static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { + if (NULL == pSelect->pFromTable) { + return createSelectWithoutFromLogicNode(pCxt, pSelect, pLogicNode); + } else { + return createSelectFromLogicNode(pCxt, pSelect, pLogicNode); + } +} + static int32_t createSetOpRootLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) { return createRootLogicNode(pCxt, pSetOperator, pSetOperator->precision, (FCreateLogicNode)func, pRoot); @@ -899,6 +940,8 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p return TSDB_CODE_OUT_OF_MEMORY; } + pSort->node.pLimit = pSetOperator->pLimit; + int32_t code = TSDB_CODE_SUCCESS; pSort->node.pTargets = nodesCloneList(pSetOperator->pProjectionList); @@ -929,12 +972,8 @@ static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator return TSDB_CODE_OUT_OF_MEMORY; } - if (NULL != pSetOperator->pLimit) { - pProject->limit = ((SLimitNode*)pSetOperator->pLimit)->limit; - pProject->offset = ((SLimitNode*)pSetOperator->pLimit)->offset; - } else { - pProject->limit = -1; - pProject->offset = -1; + if (NULL == pSetOperator->pOrderByList) { + pProject->node.pLimit = pSetOperator->pLimit; } int32_t code = TSDB_CODE_SUCCESS; @@ -964,6 +1003,10 @@ static int32_t createSetOpAggLogicNode(SLogicPlanContext* pCxt, SSetOperator* pS return TSDB_CODE_OUT_OF_MEMORY; } + if (NULL == pSetOperator->pOrderByList) { + pAgg->node.pLimit = pSetOperator->pLimit; + } + int32_t code = TSDB_CODE_SUCCESS; pAgg->pGroupKeys = nodesCloneList(pSetOperator->pProjectionList); if (NULL == pAgg->pGroupKeys) { @@ -1090,8 +1133,8 @@ static int32_t createDeleteScanLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* p } } - if (TSDB_CODE_SUCCESS == code && NULL != pDelete->pTagIndexCond) { - pScan->pTagCond = nodesCloneNode(pDelete->pTagIndexCond); + if (TSDB_CODE_SUCCESS == code && NULL != pDelete->pTagCond) { + pScan->pTagCond = nodesCloneNode(pDelete->pTagCond); if (NULL == pScan->pTagCond) { code = TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index cd3218cf94..7862ad5445 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -15,7 +15,6 @@ #include "filter.h" #include "functionMgt.h" -#include "index.h" #include "planInt.h" #include "ttime.h" @@ -79,7 +78,8 @@ static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func) EDealRes osdHaveNormalColImpl(SNode* pNode, void* pContext) { if (QUERY_NODE_COLUMN == nodeType(pNode)) { - *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType); + // *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType); + *((bool*)pContext) = true; return *((bool*)pContext) ? DEAL_RES_END : DEAL_RES_IGNORE_CHILD; } return DEAL_RES_CONTINUE; @@ -98,11 +98,6 @@ static bool osdMayBeOptimized(SLogicNode* pNode) { if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { return false; } - // todo: release after function splitting - if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->tableType && - SCAN_TYPE_STREAM != ((SScanLogicNode*)pNode)->scanType) { - return false; - } if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_PARTITION != nodeType(pNode->pParent))) { @@ -293,42 +288,22 @@ static int32_t cpdCondAppend(SNode** pCond, SNode** pAdditionalCond) { return code; } -static int32_t cpdCalcTimeRange(SScanLogicNode* pScan, SNode** pPrimaryKeyCond, SNode** pOtherCond) { - bool isStrict = false; - int32_t code = filterGetTimeRange(*pPrimaryKeyCond, &pScan->scanRange, &isStrict); - if (TSDB_CODE_SUCCESS == code) { - if (isStrict) { - nodesDestroyNode(*pPrimaryKeyCond); - } else { - code = cpdCondAppend(pOtherCond, pPrimaryKeyCond); - } - *pPrimaryKeyCond = NULL; - } - return code; -} - -static int32_t cpdApplyTagIndex(SScanLogicNode* pScan, SNode** pTagCond, SNode** pOtherCond) { - int32_t code = TSDB_CODE_SUCCESS; - SIdxFltStatus idxStatus = idxGetFltStatus(*pTagCond); - switch (idxStatus) { - case SFLT_NOT_INDEX: - code = cpdCondAppend(pOtherCond, pTagCond); - break; - case SFLT_COARSE_INDEX: - pScan->pTagCond = nodesCloneNode(*pTagCond); - if (NULL == pScan->pTagCond) { - code = TSDB_CODE_OUT_OF_MEMORY; - break; +static int32_t cpdCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNode* pScan, SNode** pPrimaryKeyCond, + SNode** pOtherCond) { + int32_t code = TSDB_CODE_SUCCESS; + if (pCxt->pPlanCxt->topicQuery || pCxt->pPlanCxt->streamQuery) { + code = cpdCondAppend(pOtherCond, pPrimaryKeyCond); + } else { + bool isStrict = false; + code = filterGetTimeRange(*pPrimaryKeyCond, &pScan->scanRange, &isStrict); + if (TSDB_CODE_SUCCESS == code) { + if (isStrict) { + nodesDestroyNode(*pPrimaryKeyCond); + } else { + code = cpdCondAppend(pOtherCond, pPrimaryKeyCond); } - code = cpdCondAppend(pOtherCond, pTagCond); - break; - case SFLT_ACCURATE_INDEX: - pScan->pTagCond = *pTagCond; - *pTagCond = NULL; - break; - default: - code = TSDB_CODE_FAILED; - break; + *pPrimaryKeyCond = NULL; + } } return code; } @@ -340,14 +315,11 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* } SNode* pPrimaryKeyCond = NULL; - SNode* pTagCond = NULL; SNode* pOtherCond = NULL; - int32_t code = nodesPartitionCond(&pScan->node.pConditions, &pPrimaryKeyCond, &pTagCond, &pOtherCond); + int32_t code = nodesPartitionCond(&pScan->node.pConditions, &pPrimaryKeyCond, &pScan->pTagIndexCond, &pScan->pTagCond, + &pOtherCond); if (TSDB_CODE_SUCCESS == code && NULL != pPrimaryKeyCond) { - code = cpdCalcTimeRange(pScan, &pPrimaryKeyCond, &pOtherCond); - } - if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) { - code = cpdApplyTagIndex(pScan, &pTagCond, &pOtherCond); + code = cpdCalcTimeRange(pCxt, pScan, &pPrimaryKeyCond, &pOtherCond); } if (TSDB_CODE_SUCCESS == code) { pScan->node.pConditions = pOtherCond; @@ -769,7 +741,7 @@ static bool smaOptMayBeOptimized(SLogicNode* pNode) { } SScanLogicNode* pScan = (SScanLogicNode*)pNode; - if (0 == pScan->interval || NULL == pScan->pSmaIndexes || NULL != pScan->node.pConditions) { + if (NULL == pScan->pSmaIndexes || NULL != pScan->node.pConditions) { return false; } @@ -1126,7 +1098,7 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub break; } } - DESTORY_LIST(((SAggLogicNode*)pNode)->pGroupKeys); + NODES_DESTORY_LIST(((SAggLogicNode*)pNode)->pGroupKeys); } if (TSDB_CODE_SUCCESS == code) { code = partTagsOptRebuildTbanme(pScan->pPartTags); @@ -1145,8 +1117,7 @@ static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode) { } SProjectLogicNode* pProjectNode = (SProjectLogicNode*)pNode; - if (-1 != pProjectNode->limit || -1 != pProjectNode->slimit || -1 != pProjectNode->offset || - -1 != pProjectNode->soffset) { + if (NULL != pProjectNode->node.pLimit || NULL != pProjectNode->node.pSlimit) { return false; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index adc613e63a..efb0f790e1 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -348,6 +348,9 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode return NULL; } + pPhysiNode->pLimit = pLogicNode->pLimit; + pPhysiNode->pSlimit = pLogicNode->pSlimit; + int32_t code = createDataBlockDesc(pCxt, pLogicNode->pTargets, &pPhysiNode->pOutputDataBlockDesc); if (TSDB_CODE_SUCCESS != code) { nodesDestroyNode((SNode*)pPhysiNode); @@ -436,6 +439,15 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS } } + if (TSDB_CODE_SUCCESS == code) { + if (NULL != pScanLogicNode->pTagIndexCond) { + pSubplan->pTagIndexCond = nodesCloneNode(pScanLogicNode->pTagIndexCond); + if (NULL == pSubplan->pTagIndexCond) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + } + if (TSDB_CODE_SUCCESS == code) { *pPhyNode = (SPhysiNode*)pScanPhysiNode; } else { @@ -462,6 +474,8 @@ static ENodeType getScanOperatorType(EScanType scanType) { return QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN; case SCAN_TYPE_BLOCK_INFO: return QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; + case SCAN_TYPE_LAST_ROW: + return QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN; default: break; } @@ -559,6 +573,7 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, switch (pScanLogicNode->scanType) { case SCAN_TYPE_TAG: case SCAN_TYPE_BLOCK_INFO: + case SCAN_TYPE_LAST_ROW: return createSimpleScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); case SCAN_TYPE_TABLE: return createTableScanPhysiNode(pCxt, pSubplan, pScanLogicNode, pPhyNode); @@ -732,7 +747,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN SRewritePrecalcExprsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs}; nodesRewriteExprs(*pRewrittenList, doRewritePrecalcExprs, &cxt); if (0 == LIST_LENGTH(cxt.pPrecalcExprs) || TSDB_CODE_SUCCESS != cxt.errCode) { - DESTORY_LIST(*pPrecalcExprs); + NODES_DESTORY_LIST(*pPrecalcExprs); } return cxt.errCode; } @@ -909,13 +924,16 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild return TSDB_CODE_OUT_OF_MEMORY; } - pProject->limit = pProjectLogicNode->limit; - pProject->offset = pProjectLogicNode->offset; - pProject->slimit = pProjectLogicNode->slimit; - pProject->soffset = pProjectLogicNode->soffset; - - int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, - -1, pProjectLogicNode->pProjections, &pProject->pProjections); + int32_t code = TSDB_CODE_SUCCESS; + if (0 == LIST_LENGTH(pChildren)) { + pProject->pProjections = nodesCloneList(pProjectLogicNode->pProjections); + if (NULL == pProject->pProjections) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } else { + code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, + pProjectLogicNode->pProjections, &pProject->pProjections); + } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc); @@ -1179,6 +1197,9 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren nodesDestroyNode((SNode*)pSort); } + nodesDestroyList(pPrecalcExprs); + nodesDestroyList(pSortKeys); + return code; } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 29119bf1d2..0e35239621 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -166,6 +166,31 @@ static bool stbSplHasMultiTbScan(bool streamQuery, SLogicNode* pNode) { return (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pChild) && stbSplIsMultiTbScan(streamQuery, (SScanLogicNode*)pChild)); } +static bool stbSplNeedSplitWindow(bool streamQuery, SLogicNode* pNode) { + SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode; + if (WINDOW_TYPE_INTERVAL == pWindow->winType) { + return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); + } + + if (WINDOW_TYPE_SESSION == pWindow->winType) { + if (!streamQuery) { + return stbSplHasMultiTbScan(streamQuery, pNode); + } else { + return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); + } + } + + if (WINDOW_TYPE_STATE == pWindow->winType) { + if (!streamQuery) { + return stbSplHasMultiTbScan(streamQuery, pNode); + } else { + return false; + } + } + + return false; +} + static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) { switch (nodeType(pNode)) { case QUERY_NODE_LOGIC_PLAN_SCAN: @@ -174,13 +199,8 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) { return !(((SJoinLogicNode*)pNode)->isSingleTableJoin); case QUERY_NODE_LOGIC_PLAN_AGG: return !stbSplHasGatherExecFunc(((SAggLogicNode*)pNode)->pAggFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); - case QUERY_NODE_LOGIC_PLAN_WINDOW: { - SWindowLogicNode* pWindow = (SWindowLogicNode*)pNode; - if (WINDOW_TYPE_STATE == pWindow->winType || (!streamQuery && WINDOW_TYPE_SESSION == pWindow->winType)) { - return false; - } - return !stbSplHasGatherExecFunc(pWindow->pFuncs) && stbSplHasMultiTbScan(streamQuery, pNode); - } + case QUERY_NODE_LOGIC_PLAN_WINDOW: + return stbSplNeedSplitWindow(streamQuery, pNode); case QUERY_NODE_LOGIC_PLAN_SORT: return stbSplHasMultiTbScan(streamQuery, pNode); default: @@ -477,11 +497,64 @@ static int32_t stbSplSplitSessionForStream(SSplitContext* pCxt, SStableSplitInfo return code; } +static void splSetTableScanType(SLogicNode* pNode, EScanType scanType) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) { + ((SScanLogicNode*)pNode)->scanType = scanType; + } else { + if (1 == LIST_LENGTH(pNode->pChildren)) { + splSetTableScanType((SLogicNode*)nodesListGetNode(pNode->pChildren, 0), scanType); + } + } +} + +static int32_t stbSplSplitSessionOrStateForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + SLogicNode* pWindow = pInfo->pSplitNode; + SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pWindow->pChildren, 0); + + SNodeList* pMergeKeys = NULL; + int32_t code = stbSplCreateMergeKeysByPrimaryKey(((SWindowLogicNode*)pWindow)->pTspk, &pMergeKeys); + + if (TSDB_CODE_SUCCESS == code) { + code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pChild, pMergeKeys, (SLogicNode*)pChild); + } + + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren, + (SNode*)splCreateScanSubplan(pCxt, pChild, SPLIT_FLAG_STABLE_SPLIT)); + } + + if (TSDB_CODE_SUCCESS == code) { + splSetTableScanType(pChild, SCAN_TYPE_TABLE_MERGE); + ++(pCxt->groupId); + } + + if (TSDB_CODE_SUCCESS == code) { + pInfo->pSubplan->subplanType = SUBPLAN_TYPE_MERGE; + SPLIT_FLAG_SET_MASK(pInfo->pSubplan->splitFlag, SPLIT_FLAG_STABLE_SPLIT); + } else { + nodesDestroyList(pMergeKeys); + } + + return code; +} + static int32_t stbSplSplitSession(SSplitContext* pCxt, SStableSplitInfo* pInfo) { if (pCxt->pPlanCxt->streamQuery) { return stbSplSplitSessionForStream(pCxt, pInfo); } else { - return TSDB_CODE_PLAN_INTERNAL_ERROR; + return stbSplSplitSessionOrStateForBatch(pCxt, pInfo); + } +} + +static int32_t stbSplSplitStateForStream(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + return TSDB_CODE_PLAN_INTERNAL_ERROR; +} + +static int32_t stbSplSplitState(SSplitContext* pCxt, SStableSplitInfo* pInfo) { + if (pCxt->pPlanCxt->streamQuery) { + return stbSplSplitStateForStream(pCxt, pInfo); + } else { + return stbSplSplitSessionOrStateForBatch(pCxt, pInfo); } } @@ -511,6 +584,8 @@ static int32_t stbSplSplitWindowForMergeTable(SSplitContext* pCxt, SStableSplitI return stbSplSplitInterval(pCxt, pInfo); case WINDOW_TYPE_SESSION: return stbSplSplitSession(pCxt, pInfo); + case WINDOW_TYPE_STATE: + return stbSplSplitState(pCxt, pInfo); default: break; } @@ -934,7 +1009,7 @@ static int32_t unionSplitSubplan(SSplitContext* pCxt, SLogicSubplan* pUnionSubpl } if (TSDB_CODE_SUCCESS == code) { nodesDestroyList(pSubplanChildren); - DESTORY_LIST(pSplitNode->pChildren); + NODES_DESTORY_LIST(pSplitNode->pChildren); } return code; } @@ -965,6 +1040,7 @@ static int32_t unAllSplCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pS if (NULL == pExchange->node.pTargets) { return TSDB_CODE_OUT_OF_MEMORY; } + TSWAP(pExchange->node.pLimit, pProject->node.pLimit); pSubplan->subplanType = SUBPLAN_TYPE_MERGE; diff --git a/source/libs/planner/test/planBasicTest.cpp b/source/libs/planner/test/planBasicTest.cpp index f74c7df355..ea40567dae 100644 --- a/source/libs/planner/test/planBasicTest.cpp +++ b/source/libs/planner/test/planBasicTest.cpp @@ -37,13 +37,6 @@ TEST_F(PlanBasicTest, whereClause) { run("SELECT * FROM t1 WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59'"); } -TEST_F(PlanBasicTest, joinClause) { - useDb("root", "test"); - - run("SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts"); - run("SELECT t1.c1, t2.c2 FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts"); -} - TEST_F(PlanBasicTest, func) { useDb("root", "test"); @@ -83,3 +76,21 @@ TEST_F(PlanBasicTest, interpFunc) { run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)"); } + +TEST_F(PlanBasicTest, lastRowFunc) { + useDb("root", "test"); + + run("SELECT LAST_ROW(c1) FROM t1"); + + run("SELECT LAST_ROW(*) FROM t1"); + + run("SELECT LAST_ROW(c1, c2) FROM t1"); + + run("SELECT LAST_ROW(c1) FROM st1"); +} + +TEST_F(PlanBasicTest, withoutFrom) { + useDb("root", "test"); + + run("SELECT 1"); +} diff --git a/source/libs/planner/test/planOptimizeTest.cpp b/source/libs/planner/test/planOptimizeTest.cpp index 1bee43aa49..8b3d263d66 100644 --- a/source/libs/planner/test/planOptimizeTest.cpp +++ b/source/libs/planner/test/planOptimizeTest.cpp @@ -40,6 +40,8 @@ TEST_F(PlanOptimizeTest, ConditionPushDown) { run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2"); run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'"); + + run("SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello' AND c1 > 10"); } TEST_F(PlanOptimizeTest, orderByPrimaryKey) { diff --git a/source/libs/planner/test/planOrderByTest.cpp b/source/libs/planner/test/planOrderByTest.cpp index 2ca662cf86..e542f4772f 100644 --- a/source/libs/planner/test/planOrderByTest.cpp +++ b/source/libs/planner/test/planOrderByTest.cpp @@ -31,6 +31,8 @@ TEST_F(PlanOrderByTest, basic) { run("SELECT c1 AS a FROM t1 ORDER BY a"); run("SELECT c1 + 10 AS a FROM t1 ORDER BY a"); + + run("SELECT 1 FROM t1 ORDER BY c1"); } TEST_F(PlanOrderByTest, expr) { diff --git a/source/libs/planner/test/planSessionTest.cpp b/source/libs/planner/test/planSessionTest.cpp index 7d5d826925..f445bb5ffc 100644 --- a/source/libs/planner/test/planSessionTest.cpp +++ b/source/libs/planner/test/planSessionTest.cpp @@ -34,3 +34,13 @@ TEST_F(PlanSessionTest, selectFunc) { // select function along with the columns of select row, and with SESSION clause run("SELECT MAX(c1), c2 FROM t1 SESSION(ts, 10s)"); } + +TEST_F(PlanSessionTest, stable) { + useDb("root", "test"); + + // select function for SESSION clause + run("SELECT MAX(c1), MIN(c1) FROM st1 SESSION(ts, 10s)"); + // select function along with the columns of select row, and with SESSION clause + run("SELECT MAX(c1), c2 FROM st1 SESSION(ts, 10s)"); + run("SELECT count(ts) FROM st1 PARTITION BY c1 SESSION(ts, 10s)"); +} diff --git a/source/libs/planner/test/planSetOpTest.cpp b/source/libs/planner/test/planSetOpTest.cpp index bf26f55c02..62e017052e 100644 --- a/source/libs/planner/test/planSetOpTest.cpp +++ b/source/libs/planner/test/planSetOpTest.cpp @@ -54,6 +54,14 @@ TEST_F(PlanSetOpTest, unionAllWithOrderBy) { run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 20 ORDER BY 1"); } +TEST_F(PlanSetOpTest, unionAllWithLimit) { + useDb("root", "test"); + + run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 20 LIMIT 10, 20"); + + run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION ALL SELECT c1, c2 FROM t1 WHERE c1 > 20 ORDER BY 1 LIMIT 10, 20"); +} + TEST_F(PlanSetOpTest, union) { useDb("root", "test"); @@ -65,6 +73,14 @@ TEST_F(PlanSetOpTest, union) { "UNION SELECT c1, c2 FROM t1 WHERE c1 > 30"); } +TEST_F(PlanSetOpTest, unionWithLimit) { + useDb("root", "test"); + + run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION SELECT c1, c2 FROM t1 WHERE c1 > 20 LIMIT 10, 20"); + + run("SELECT c1, c2 FROM t1 WHERE c1 > 10 UNION SELECT c1, c2 FROM t1 WHERE c1 > 20 ORDER BY 1 LIMIT 10, 20"); +} + TEST_F(PlanSetOpTest, unionContainJoin) { useDb("root", "test"); diff --git a/source/libs/planner/test/planStateTest.cpp b/source/libs/planner/test/planStateTest.cpp index 9ff035e148..6985bc8807 100644 --- a/source/libs/planner/test/planStateTest.cpp +++ b/source/libs/planner/test/planStateTest.cpp @@ -40,3 +40,12 @@ TEST_F(PlanStateTest, selectFunc) { // select function along with the columns of select row, and with STATE_WINDOW clause run("SELECT MAX(c1), c2 FROM t1 STATE_WINDOW(c3)"); } + +TEST_F(PlanStateTest, stable) { + useDb("root", "test"); + + // select function for STATE_WINDOW clause + run("SELECT MAX(c1), MIN(c1) FROM st1 STATE_WINDOW(c2)"); + // select function along with the columns of select row, and with STATE_WINDOW clause + run("SELECT MAX(c1), c2 FROM st1 STATE_WINDOW(c2)"); +} diff --git a/source/libs/planner/test/planSubqueryTest.cpp b/source/libs/planner/test/planSubqueryTest.cpp index 7d1ac84aea..4d4f780473 100644 --- a/source/libs/planner/test/planSubqueryTest.cpp +++ b/source/libs/planner/test/planSubqueryTest.cpp @@ -33,7 +33,9 @@ TEST_F(PlanSubqeuryTest, basic) { run("SELECT NOW() FROM (SELECT * FROM t1)"); - // run("SELECT NOW() FROM (SELECT * FROM t1) ORDER BY ts"); + run("SELECT * FROM (SELECT NOW() FROM t1)"); + + run("SELECT NOW() FROM (SELECT * FROM t1) ORDER BY ts"); } TEST_F(PlanSubqeuryTest, doubleGroupBy) { diff --git a/source/libs/planner/test/planTestMain.cpp b/source/libs/planner/test/planTestMain.cpp index acac3d5053..43b6bf5772 100644 --- a/source/libs/planner/test/planTestMain.cpp +++ b/source/libs/planner/test/planTestMain.cpp @@ -16,9 +16,11 @@ #include #include + #include "functionMgt.h" #include "getopt.h" #include "mockCatalog.h" +#include "parser.h" #include "planTestUtil.h" class PlannerEnv : public testing::Environment { @@ -30,7 +32,12 @@ class PlannerEnv : public testing::Environment { initLog(TD_TMP_DIR_PATH "td"); } - virtual void TearDown() { destroyMetaDataEnv(); } + virtual void TearDown() { + destroyMetaDataEnv(); + qCleanupKeywordsTable(); + fmFuncMgtDestroy(); + taosCloseLog(); + } PlannerEnv() {} virtual ~PlannerEnv() {} diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index 57d7cb6608..f1ab9c8196 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -102,12 +102,15 @@ class PlannerTestBaseImpl { try { SQuery* pQuery = nullptr; doParseSql(sql, &pQuery); + unique_ptr query(pQuery, qDestroyQuery); SPlanContext cxt = {0}; setPlanContext(pQuery, &cxt); SLogicSubplan* pLogicSubplan = nullptr; doCreateLogicPlan(&cxt, &pLogicSubplan); + unique_ptr logicSubplan(pLogicSubplan, + (void (*)(SLogicSubplan*))nodesDestroyNode); doOptimizeLogicPlan(&cxt, pLogicSubplan); @@ -115,9 +118,12 @@ class PlannerTestBaseImpl { SQueryLogicPlan* pLogicPlan = nullptr; doScaleOutLogicPlan(&cxt, pLogicSubplan, &pLogicPlan); + unique_ptr logicPlan(pLogicPlan, + (void (*)(SQueryLogicPlan*))nodesDestroyNode); SQueryPlan* pPlan = nullptr; doCreatePhysiPlan(&cxt, pLogicPlan, &pPlan); + unique_ptr plan(pPlan, (void (*)(SQueryPlan*))nodesDestroyNode); dump(g_dumpModule); } catch (...) { @@ -345,8 +351,9 @@ class PlannerTestBaseImpl { } void doCreatePhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan) { - SArray* pExecNodeList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr)); - DO_WITH_THROW(createPhysiPlan, pCxt, pLogicPlan, pPlan, pExecNodeList); + unique_ptr execNodeList((SArray*)taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr)), + (void (*)(SArray*))taosArrayDestroy); + DO_WITH_THROW(createPhysiPlan, pCxt, pLogicPlan, pPlan, execNodeList.get()); res_.physiPlan_ = toString((SNode*)(*pPlan)); SNode* pNode; FOREACH(pNode, (*pPlan)->pSubplans) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index e2dfd9682b..df608412b0 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -126,6 +126,25 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } +int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { + if (NULL == msg || NULL == msgLen) { + return TSDB_CODE_TSC_INVALID_INPUT; + } + + SDnodeListReq dnodeListReq = {0}; + dnodeListReq.rowNum = -1; + + int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq); + void *pBuf = (*mallcFp)(bufLen); + tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq); + + *msg = pBuf; + *msgLen = bufLen; + + return TSDB_CODE_SUCCESS; +} + + int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; @@ -428,6 +447,27 @@ int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) { return code; } +int32_t queryProcessDnodeListRsp(void *output, char *msg, int32_t msgSize) { + SDnodeListRsp out = {0}; + int32_t code = 0; + + if (NULL == output || NULL == msg || msgSize <= 0) { + code = TSDB_CODE_TSC_INVALID_INPUT; + return code; + } + + if (tDeserializeSDnodeListRsp(msg, msgSize, &out) != 0) { + qError("invalid dnode list rsp msg, msgSize:%d", msgSize); + code = TSDB_CODE_INVALID_MSG; + return code; + } + + *(SArray**)output = out.dnodeList; + + return code; +} + + int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) { SDbCfgRsp out = {0}; @@ -535,6 +575,7 @@ void initQueryModuleMsgHandle() { queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryBuildDnodeListMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryBuildGetIndexMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryBuildRetrieveFuncMsg; @@ -547,6 +588,7 @@ void initQueryModuleMsgHandle() { queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_DNODE_LIST)] = queryProcessDnodeListRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_INDEX)] = queryProcessGetIndexRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = queryProcessRetrieveFuncRsp; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 28181d7e11..4250785f7c 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -271,7 +271,7 @@ int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen SDeleterRes* pDelRes = (SDeleterRes*)output.pData; rsp.affectedRows = pDelRes->affectedRows; - pRes->uid = pDelRes->uid; + pRes->suid = pDelRes->suid; pRes->uidList = pDelRes->uidList; pRes->skey = pDelRes->skey; pRes->ekey = pDelRes->ekey; diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 4dd16098ff..c2d984c7dd 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -57,7 +57,7 @@ typedef struct SScalarCtx { #define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); -SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); +SColumnInfoData* sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows); int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode); #define GET_PARAM_TYPE(_c) ((_c)->columnData ? (_c)->columnData->info.type : (_c)->hashValueType) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index a446aa7bdb..b8bcae161b 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3821,7 +3821,7 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData SScalarParam output = {0}; SDataType type = {.type = TSDB_DATA_TYPE_BOOL, .bytes = sizeof(bool)}; - output.columnData = createColumnInfoData(&type, pSrc->info.rows); + output.columnData = sclCreateColumnInfoData(&type, pSrc->info.rows); SArray *pList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(pList, &pSrc); diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 66e4af5ded..75a9bc3809 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -36,7 +36,7 @@ int32_t sclConvertToTsValueNode(int8_t precision, SValueNode* valueNode) { } -SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { +SColumnInfoData* sclCreateColumnInfoData(SDataType* pType, int32_t numOfRows) { SColumnInfoData* pColumnData = taosMemoryCalloc(1, sizeof(SColumnInfoData)); if (pColumnData == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -48,7 +48,7 @@ SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { pColumnData->info.scale = pType->scale; pColumnData->info.precision = pType->precision; - int32_t code = colInfoDataEnsureCapacity(pColumnData, 0, numOfRows); + int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); if (code != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pColumnData); @@ -60,10 +60,10 @@ SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { SScalarParam in = {.numOfRows = 1}; - in.columnData = createColumnInfoData(&pValueNode->node.resType, 1); + in.columnData = sclCreateColumnInfoData(&pValueNode->node.resType, 1); colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); - colInfoDataEnsureCapacity(out->columnData, 0, 1); + colInfoDataEnsureCapacity(out->columnData, 1); int32_t code = vectorConvertImpl(&in, out); sclFreeParam(&in); @@ -193,7 +193,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t SValueNode *valueNode = (SValueNode *)node; param->numOfRows = 1; - param->columnData = createColumnInfoData(&valueNode->node.resType, 1); + param->columnData = sclCreateColumnInfoData(&valueNode->node.resType, 1); if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type) { colDataAppendNULL(param->columnData, 0); } else { @@ -245,7 +245,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index); - if (NULL == block || ref->slotId >= block->info.numOfCols) { + if (NULL == block || ref->slotId >= taosArrayGetSize(block->pDataBlock)) { sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -431,7 +431,7 @@ int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outp SCL_ERR_JRET(code); } - output->columnData = createColumnInfoData(&node->node.resType, rowNum); + output->columnData = sclCreateColumnInfoData(&node->node.resType, rowNum); if (output->columnData == NULL) { sclError("calloc %d failed", (int32_t)(rowNum * output->columnData->info.bytes)); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -484,7 +484,7 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o output->numOfRows = rowNum; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - output->columnData = createColumnInfoData(&t, rowNum); + output->columnData = sclCreateColumnInfoData(&t, rowNum); if (output->columnData == NULL) { sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -539,7 +539,7 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp int32_t code = 0; SCL_ERR_RET(sclInitOperatorParams(¶ms, node, ctx, &rowNum)); - output->columnData = createColumnInfoData(&node->node.resType, rowNum); + output->columnData = sclCreateColumnInfoData(&node->node.resType, rowNum); if (output->columnData == NULL) { sclError("calloc failed, size:%d", (int32_t)rowNum * node->node.resType.bytes); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -901,7 +901,7 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } - colDataAssign(col, res->columnData, res->numOfRows); + colDataAssign(col, res->columnData, res->numOfRows, NULL); block->info.rows = res->numOfRows; sclFreeParam(res); @@ -982,8 +982,9 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { sclError("no valid res in hash, node:%p, type:%d", pNode, nodeType(pNode)); SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - - colDataAssign(pDst->columnData, res->columnData, res->numOfRows); + + colInfoDataEnsureCapacity(pDst->columnData, res->numOfRows); + colDataAssign(pDst->columnData, res->columnData, res->numOfRows, NULL); pDst->numOfRows = res->numOfRows; taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index d335b04ea4..d7f0733129 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -36,9 +36,6 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu SColumnInfoData *pOutputData = pOutput->columnData; int32_t type = GET_PARAM_TYPE(pInput); - if (!IS_NUMERIC_TYPE(type)) { - return TSDB_CODE_FAILED; - } switch (type) { case TSDB_DATA_TYPE_FLOAT: { @@ -119,8 +116,15 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu break; } + case TSDB_DATA_TYPE_NULL: { + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + colDataAppendNULL(pOutputData, i); + } + break; + } + default: { - colDataAssign(pOutputData, pInputData, pInput->numOfRows); + colDataAssign(pOutputData, pInputData, pInput->numOfRows, NULL); } } @@ -130,9 +134,6 @@ int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) { int32_t type = GET_PARAM_TYPE(pInput); - if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) { - return TSDB_CODE_FAILED; - } SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; @@ -142,7 +143,7 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS double *out = (double *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_s(pInputData, i)) { + if (colDataIsNull_s(pInputData, i) || IS_NULL_TYPE(type)) { colDataAppendNULL(pOutputData, i); continue; } @@ -159,10 +160,6 @@ static int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SS } static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn_2 valFn) { - if (inputNum != 2 || !IS_NUMERIC_TYPE(GET_PARAM_TYPE(&pInput[0])) || !IS_NUMERIC_TYPE(GET_PARAM_TYPE(&pInput[1]))) { - return TSDB_CODE_FAILED; - } - SColumnInfoData *pInputData[2]; SColumnInfoData *pOutputData = pOutput->columnData; _getDoubleValue_fn_t getValueFn[2]; @@ -175,11 +172,15 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S double *out = (double *)pOutputData->pData; double result; + bool hasNullType = (IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[0])) || + IS_NULL_TYPE(GET_PARAM_TYPE(&pInput[1]))); + int32_t numOfRows = TMAX(pInput[0].numOfRows, pInput[1].numOfRows); if (pInput[0].numOfRows == pInput[1].numOfRows) { for (int32_t i = 0; i < numOfRows; ++i) { if (colDataIsNull_s(pInputData[0], i) || - colDataIsNull_s(pInputData[1], i)) { + colDataIsNull_s(pInputData[1], i) || + hasNullType) { colDataAppendNULL(pOutputData, i); continue; } @@ -191,7 +192,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S } } } else if (pInput[0].numOfRows == 1) { //left operand is constant - if (colDataIsNull_s(pInputData[0], 0)) { + if (colDataIsNull_s(pInputData[0], 0) || hasNullType) { colDataAppendNNULL(pOutputData, 0, pInput[1].numOfRows); } else { for (int32_t i = 0; i < numOfRows; ++i) { @@ -210,7 +211,7 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S } } } else if (pInput[1].numOfRows == 1) { - if (colDataIsNull_s(pInputData[1], 0)) { + if (colDataIsNull_s(pInputData[1], 0) || hasNullType) { colDataAppendNNULL(pOutputData, 0, pInput[0].numOfRows); } else { for (int32_t i = 0; i < numOfRows; ++i) { @@ -236,9 +237,6 @@ static int32_t doScalarFunctionUnique2(SScalarParam *pInput, int32_t inputNum, S static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _float_fn f1, _double_fn d1) { int32_t type = GET_PARAM_TYPE(pInput); - if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) { - return TSDB_CODE_FAILED; - } SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; @@ -272,8 +270,15 @@ static int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarP break; } + case TSDB_DATA_TYPE_NULL: { + for (int32_t i = 0; i < pInput->numOfRows; ++i) { + colDataAppendNULL(pOutputData, i); + } + break; + } + default: { - colDataAssign(pOutputData, pInputData, pInput->numOfRows); + colDataAssign(pOutputData, pInputData, pInput->numOfRows, NULL); } } @@ -856,10 +861,13 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t type = GET_PARAM_TYPE(pInput); + bool tzPresent = (inputNum == 2) ? true : false; char* tz; int32_t tzLen; - tz = varDataVal(pInput[1].columnData->pData); - tzLen = varDataLen(pInput[1].columnData->pData); + if (tzPresent) { + tz = varDataVal(pInput[1].columnData->pData); + tzLen = varDataLen(pInput[1].columnData->pData); + } for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { if (colDataIsNull_s(pInput[0].columnData, i)) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index bff49c2ca9..f9a9ec0f72 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -23,6 +23,7 @@ #include "sclvector.h" #include "tcompare.h" #include "tdatablock.h" +#include "tdataformat.h" #include "ttypes.h" #include "ttime.h" @@ -506,6 +507,16 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t } } + // if types can not comparable + if((IS_NUMERIC_TYPE(typeLeft) && !IS_NUMERIC_TYPE(typeRight)) || + (IS_NUMERIC_TYPE(typeRight) && !IS_NUMERIC_TYPE(typeLeft)) || + (IS_VAR_DATA_TYPE(typeLeft) && !IS_VAR_DATA_TYPE(typeRight)) || + (IS_VAR_DATA_TYPE(typeRight) && !IS_VAR_DATA_TYPE(typeLeft)) || + ((typeLeft == TSDB_DATA_TYPE_BOOL) && (typeRight != TSDB_DATA_TYPE_BOOL)) || + ((typeRight == TSDB_DATA_TYPE_BOOL) && (typeLeft != TSDB_DATA_TYPE_BOOL))) + return false; + + if(typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL){ *isNull = true; return true; @@ -519,24 +530,28 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t *fp = filterGetCompFunc(type, optr); - if(IS_NUMERIC_TYPE(type) || IS_FLOAT_TYPE(type)){ + if(IS_NUMERIC_TYPE(type)){ if(typeLeft == TSDB_DATA_TYPE_NCHAR) { - convertNcharToDouble(*pLeftData, pLeftOut); - *pLeftData = pLeftOut; + ASSERT(0); +// convertNcharToDouble(*pLeftData, pLeftOut); +// *pLeftData = pLeftOut; } else if(typeLeft == TSDB_DATA_TYPE_BINARY) { - convertBinaryToDouble(*pLeftData, pLeftOut); - *pLeftData = pLeftOut; + ASSERT(0); +// convertBinaryToDouble(*pLeftData, pLeftOut); +// *pLeftData = pLeftOut; } else if(typeLeft != type) { convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); *pLeftData = pLeftOut; } if(typeRight == TSDB_DATA_TYPE_NCHAR) { - convertNcharToDouble(*pRightData, pRightOut); - *pRightData = pRightOut; + ASSERT(0); +// convertNcharToDouble(*pRightData, pRightOut); +// *pRightData = pRightOut; } else if(typeRight == TSDB_DATA_TYPE_BINARY) { - convertBinaryToDouble(*pRightData, pRightOut); - *pRightData = pRightOut; + ASSERT(0); +// convertBinaryToDouble(*pRightData, pRightOut); +// *pRightData = pRightOut; } else if(typeRight != type) { convertNumberToNumber(*pRightData, pRightOut, typeRight, type); *pRightData = pRightOut; @@ -837,7 +852,7 @@ int32_t vectorConvertScalarParam(SScalarParam *input, SScalarParam *output, int3 SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; output->numOfRows = input->numOfRows; - output->columnData = createColumnInfoData(&t, input->numOfRows); + output->columnData = sclCreateColumnInfoData(&t, input->numOfRows); if (output->columnData == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -908,7 +923,7 @@ static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SSca pDest->numOfRows = pParam->numOfRows; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; - pDest->columnData = createColumnInfoData(&t, pParam->numOfRows); + pDest->columnData = sclCreateColumnInfoData(&t, pParam->numOfRows); if (pDest->columnData == NULL) { sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double))); return TSDB_CODE_OUT_OF_MEMORY; @@ -1693,6 +1708,13 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, STagVal getJsonValue(char *json, char *key, bool *isExist) { STagVal val = {.pKey = key}; + if (tTagIsJson((const STag *)json) == false){ + if(isExist){ + *isExist = false; + } + return val; + } + bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different if(isExist){ *isExist = find; diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 7fb1ffbd64..8f9332cef8 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -105,29 +105,14 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in } if (NULL == *block) { - SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = 3; - res->info.rows = rowNum; - res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); + SSDataBlock *res = createDataBlock(); for (int32_t i = 0; i < 2; ++i) { - SColumnInfoData idata = {{0}}; - idata.info.type = TSDB_DATA_TYPE_NULL; - idata.info.bytes = 10; - idata.info.colId = i + 1; - - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); + SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_NULL, 10, 1+i); + blockDataAppendColInfo(res, &idata); } - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 3; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); - + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3); + blockDataAppendColInfo(res, &idata); blockDataEnsureCapacity(res, rowNum); SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); @@ -142,23 +127,18 @@ void flttMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in rnode->slotId = 2; rnode->colId = 3; + res->info.rows = rowNum; *block = res; } else { SSDataBlock *res = *block; int32_t idx = taosArrayGetSize(res->pDataBlock); - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 1 + idx; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); - res->info.numOfCols++; + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1+idx); + blockDataAppendColInfo(res, &idata); + blockDataEnsureCapacity(res, rowNum); + SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); - - colInfoDataEnsureCapacity(pColumn, 0, rowNum); for (int32_t i = 0; i < rowNum; ++i) { colDataAppend(pColumn, i, (const char *)value, false); @@ -399,7 +379,7 @@ TEST(columnTest, smallint_column_greater_double_value) { keep = filterRangeExecute(filter, &stat, 1, rowNum); ASSERT_EQ(keep, true); - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -407,9 +387,9 @@ TEST(columnTest, smallint_column_greater_double_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -430,7 +410,7 @@ TEST(columnTest, int_column_greater_smallint_value) { flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); @@ -454,7 +434,7 @@ TEST(columnTest, int_column_greater_smallint_value) { keep = filterRangeExecute(filter, &stat, 1, rowNum); ASSERT_EQ(keep, false); - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -462,9 +442,9 @@ TEST(columnTest, int_column_greater_smallint_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -478,11 +458,11 @@ TEST(columnTest, int_column_in_double_list) { SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; int32_t leftv[5] = {1, 2, 3, 4, 5}; double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3; - bool eRes[5] = {true, true, true, false, false}; - SSDataBlock *src = NULL; + bool eRes[5] = {true, true, true, false, false}; + SSDataBlock *src = NULL; SScalarParam res = {0}; int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv); SNodeList* list = nodesMakeList(); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1); nodesListAppend(list, pRight); @@ -498,7 +478,7 @@ TEST(columnTest, int_column_in_double_list) { ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -506,9 +486,9 @@ TEST(columnTest, int_column_in_double_list) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -521,8 +501,8 @@ TEST(columnTest, int_column_in_double_list) { TEST(columnTest, binary_column_in_binary_list) { SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL; - bool eRes[5] = {true, true, false, false, false}; - SSDataBlock *src = NULL; + bool eRes[5] = {true, true, false, false, false}; + SSDataBlock *src = NULL; SScalarParam res = {0}; char leftv[5][5]= {0}; char rightv[3][5]= {0}; @@ -531,22 +511,22 @@ TEST(columnTest, binary_column_in_binary_list) { leftv[i][3] = 'b' + i; leftv[i][4] = '0' + i; varDataSetLen(leftv[i], 3); - } + } for (int32_t i = 0; i < 2; ++i) { rightv[i][2] = 'a' + i; rightv[i][3] = 'b' + i; rightv[i][4] = '0' + i; varDataSetLen(rightv[i], 3); - } + } for (int32_t i = 2; i < 3; ++i) { rightv[i][2] = 'a' + i; rightv[i][3] = 'a' + i; rightv[i][4] = 'a' + i; varDataSetLen(rightv[i], 3); } - + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); SNodeList* list = nodesMakeList(); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]); nodesListAppend(list, pRight); @@ -556,13 +536,13 @@ TEST(columnTest, binary_column_in_binary_list) { nodesListAppend(list, pRight); flttMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY); flttMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -570,9 +550,9 @@ TEST(columnTest, binary_column_in_binary_list) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -586,31 +566,31 @@ TEST(columnTest, binary_column_like_binary) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; char rightv[64] = {0}; char leftv[5][5]= {0}; - SSDataBlock *src = NULL; + SSDataBlock *src = NULL; SScalarParam res = {0}; - bool eRes[5] = {true, false, true, false, true}; - + bool eRes[5] = {true, false, true, false, true}; + for (int32_t i = 0; i < 5; ++i) { leftv[i][2] = 'a'; leftv[i][3] = 'a'; leftv[i][4] = '0' + i % 2; varDataSetLen(leftv[i], 3); - } - + } + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); sprintf(&rightv[2], "%s", "__0"); varDataSetLen(rightv, strlen(&rightv[2])); flttMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv); flttMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -618,9 +598,9 @@ TEST(columnTest, binary_column_like_binary) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -633,31 +613,31 @@ TEST(columnTest, binary_column_like_binary) { TEST(columnTest, binary_column_is_null) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; - SSDataBlock *src = NULL; + SSDataBlock *src = NULL; SScalarParam res = {0}; - bool eRes[5] = {false, false, true, false, true}; - + bool eRes[5] = {false, false, true, false, true}; + for (int32_t i = 0; i < 5; ++i) { leftv[i][2] = '0' + i % 2; leftv[i][3] = 'a'; leftv[i][4] = '0' + i % 2; varDataSetLen(leftv[i], 3); - } - + } + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); colDataAppend(pcolumn, 2, NULL, true); colDataAppend(pcolumn, 4, NULL, true); flttMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -665,9 +645,9 @@ TEST(columnTest, binary_column_is_null) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -680,31 +660,31 @@ TEST(columnTest, binary_column_is_null) { TEST(columnTest, binary_column_is_not_null) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; - SSDataBlock *src = NULL; + SSDataBlock *src = NULL; SScalarParam res = {0}; - bool eRes[5] = {true, true, true, true, false}; - + bool eRes[5] = {true, true, true, true, false}; + for (int32_t i = 0; i < 5; ++i) { leftv[i][2] = '0' + i % 2; leftv[i][3] = 'a'; leftv[i][4] = '0' + i % 2; varDataSetLen(leftv[i], 3); - } - + } + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); SColumnInfoData *pcolumn = (SColumnInfoData *)taosArrayGetLast(src->pDataBlock); colDataAppend(pcolumn, 4, NULL, true); flttMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -712,9 +692,9 @@ TEST(columnTest, binary_column_is_not_null) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -735,13 +715,13 @@ TEST(opTest, smallint_column_greater_int_column) { flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv); flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -749,9 +729,9 @@ TEST(opTest, smallint_column_greater_int_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -773,13 +753,13 @@ TEST(opTest, smallint_value_add_int_column) { flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -787,9 +767,9 @@ TEST(opTest, smallint_value_add_int_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -816,13 +796,13 @@ TEST(opTest, bigint_column_multi_binary_column) { flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -830,9 +810,9 @@ TEST(opTest, bigint_column_multi_binary_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -859,13 +839,13 @@ TEST(opTest, smallint_column_and_binary_column) { flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -873,9 +853,9 @@ TEST(opTest, smallint_column_and_binary_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, (int32_t) taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -897,13 +877,13 @@ TEST(opTest, smallint_column_or_float_column) { flttMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -911,9 +891,9 @@ TEST(opTest, smallint_column_or_float_column) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -935,13 +915,13 @@ TEST(opTest, smallint_column_or_double_value) { flttMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv); flttMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -949,9 +929,9 @@ TEST(opTest, smallint_column_or_double_value) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, true); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -964,28 +944,28 @@ TEST(opTest, smallint_column_or_double_value) { TEST(opTest, binary_column_is_true) { SNode *pLeft = NULL, *opNode = NULL; char leftv[5][5]= {0}; - SSDataBlock *src = NULL; + SSDataBlock *src = NULL; SScalarParam res = {0}; - bool eRes[5] = {false, true, false, true, false}; - + bool eRes[5] = {false, true, false, true, false}; + for (int32_t i = 0; i < 5; ++i) { leftv[i][2] = '0' + i % 2; leftv[i][3] = 'a'; leftv[i][4] = '0' + i % 2; varDataSetLen(leftv[i], 3); - } - + } + int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); - flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); + flttMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); flttMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(opNode, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -993,9 +973,9 @@ TEST(opTest, binary_column_is_true) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1027,12 +1007,12 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); list = nodesMakeList(); - + flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1042,7 +1022,7 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode2, LOGIC_COND_TYPE_AND, list); list = nodesMakeList(); @@ -1050,13 +1030,13 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1064,9 +1044,9 @@ TEST(filterModelogicTest, diff_columns_and_or_and) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1096,13 +1076,13 @@ TEST(filterModelogicTest, same_column_and_or_and) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); list = nodesMakeList(); - flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); + flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv3); flttMakeOpNode(&opNode1, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); nodesListAppend(list, opNode1); @@ -1111,7 +1091,7 @@ TEST(filterModelogicTest, same_column_and_or_and) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv4); flttMakeOpNode(&opNode2, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode2, LOGIC_COND_TYPE_AND, list); list = nodesMakeList(); @@ -1119,13 +1099,13 @@ TEST(filterModelogicTest, same_column_and_or_and) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1133,9 +1113,9 @@ TEST(filterModelogicTest, same_column_and_or_and) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1165,12 +1145,12 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); - + flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv1); flttMakeOpNode(&opNode1, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1180,7 +1160,7 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode2, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); @@ -1188,13 +1168,13 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t) taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1202,9 +1182,9 @@ TEST(filterModelogicTest, diff_columns_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1234,12 +1214,12 @@ TEST(filterModelogicTest, same_column_or_and_or) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); - + flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeValueNode(&pRight1, TSDB_DATA_TYPE_INT, &rightv3); flttMakeOpNode(&opNode1, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1249,7 +1229,7 @@ TEST(filterModelogicTest, same_column_or_and_or) { flttMakeValueNode(&pRight2, TSDB_DATA_TYPE_INT, &rightv4); flttMakeOpNode(&opNode2, OP_TYPE_GREATER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft1, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode2, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); @@ -1257,13 +1237,13 @@ TEST(filterModelogicTest, same_column_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1271,9 +1251,9 @@ TEST(filterModelogicTest, same_column_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); - + for (int32_t i = 0; i < rowNum; ++i) { ASSERT_EQ(*((int8_t *)rowRes + i), eRes[i]); } @@ -1305,12 +1285,12 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { flttMakeColumnNode(&pRight2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); - + flttMakeColumnNode(&pLeft1, &src, TSDB_DATA_TYPE_DOUBLE, sizeof(double), rowNum, leftv1); flttMakeColumnNode(&pRight1, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv1); flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft1, pRight1); @@ -1320,7 +1300,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { flttMakeColumnNode(&pRight2, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, rightv2); flttMakeOpNode(&opNode2, OP_TYPE_LOWER_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft2, pRight2); nodesListAppend(list, opNode2); - + flttMakeLogicNodeFromList(&logicNode2, LOGIC_COND_TYPE_OR, list); list = nodesMakeList(); @@ -1328,13 +1308,13 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { nodesListAppend(list, logicNode2); flttMakeLogicNodeFromList(&logicNode1, LOGIC_COND_TYPE_AND, list); - + SFilterInfo *filter = NULL; int32_t code = filterInitFromNode(logicNode1, &filter, 0); ASSERT_EQ(code, 0); SColumnDataAgg stat = {0}; - SFilterColumnParam param = { src->info.numOfCols, src->pDataBlock }; + SFilterColumnParam param = { (int32_t)taosArrayGetSize(src->pDataBlock), src->pDataBlock }; code = filterSetDataFromSlotId(filter, ¶m); ASSERT_EQ(code, 0); @@ -1342,7 +1322,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { stat.min = 1; stat.numOfNull = 0; int8_t *rowRes = NULL; - bool keep = filterExecute(filter, src, &rowRes, &stat, src->info.numOfCols); + bool keep = filterExecute(filter, src, &rowRes, &stat, taosArrayGetSize(src->pDataBlock)); ASSERT_EQ(keep, false); for (int32_t i = 0; i < rowNum; ++i) { diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index d879150200..07440e7435 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -84,30 +84,29 @@ void scltInitLogFile() { void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *slotId, bool newBlock, int32_t rows, SColumnInfo *colInfo) { if (newBlock) { - SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = 1; - res->info.rows = rows; - res->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + SSDataBlock *res = createDataBlock(); + SColumnInfoData idata = {0}; - idata.info = *colInfo; + idata.info = *colInfo; + colInfoDataEnsureCapacity(&idata, rows); + + blockDataAppendColInfo(res, &idata); + + res->info.capacity = rows; + res->info.rows = rows; + SColumnInfoData* p = static_cast(taosArrayGet(res->pDataBlock, 0)); + ASSERT(p->pData != NULL && p->nullbitmap != NULL); - taosArrayPush(res->pDataBlock, &idata); taosArrayPush(pBlockList, &res); - - blockDataEnsureCapacity(res, rows); - *dataBlockId = taosArrayGetSize(pBlockList) - 1; res->info.blockId = *dataBlockId; *slotId = 0; } else { SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); - res->info.numOfCols++; SColumnInfoData idata = {0}; idata.info = *colInfo; - - colInfoDataEnsureCapacity(&idata, 0, rows); - - taosArrayPush(res->pDataBlock, &idata); + colInfoDataEnsureCapacity(&idata, rows); + blockDataAppendColInfo(res, &idata); *dataBlockId = taosArrayGetSize(pBlockList) - 1; *slotId = taosArrayGetSize(res->pDataBlock) - 1; @@ -144,29 +143,19 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in } if (NULL == *block) { - SSDataBlock *res = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock)); - res->info.numOfCols = 3; - res->info.rows = rowNum; - res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData)); + SSDataBlock *res = createDataBlock(); for (int32_t i = 0; i < 2; ++i) { - SColumnInfoData idata = {{0}}; - idata.info.type = TSDB_DATA_TYPE_NULL; - idata.info.bytes = 10; - idata.info.colId = i + 1; - - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); + SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1); + colInfoDataEnsureCapacity(&idata, rowNum); + blockDataAppendColInfo(res, &idata); } - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 3; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - colInfoDataEnsureCapacity(&idata, 0, rowNum); - taosArrayPush(res->pDataBlock, &idata); + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3); + colInfoDataEnsureCapacity(&idata, rowNum); + blockDataAppendColInfo(res, &idata); + res->info.capacity = rowNum; + + res->info.rows = rowNum; SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); for (int32_t i = 0; i < rowNum; ++i) { colDataAppend(pColumn, i, (const char *)value, false); @@ -185,17 +174,13 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in SSDataBlock *res = *block; int32_t idx = taosArrayGetSize(res->pDataBlock); - SColumnInfoData idata = {{0}}; - idata.info.type = dataType; - idata.info.bytes = dataBytes; - idata.info.colId = 1 + idx; - int32_t size = idata.info.bytes * rowNum; - idata.pData = (char *)taosMemoryCalloc(1, size); - taosArrayPush(res->pDataBlock, &idata); - res->info.numOfCols++; - SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx); + colInfoDataEnsureCapacity(&idata, rowNum); - colInfoDataEnsureCapacity(pColumn, 0, rowNum); + res->info.capacity = rowNum; + blockDataAppendColInfo(res, &idata); + + SColumnInfoData *pColumn = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); for (int32_t i = 0; i < rowNum; ++i) { colDataAppend(pColumn, i, (const char *)value, false); @@ -279,9 +264,6 @@ void scltMakeTargetNode(SNode **pNode, int16_t dataBlockId, int16_t slotId, SNod *pNode = (SNode *)onode; } - - - } TEST(constantTest, bigint_add_bigint) { @@ -1310,11 +1292,11 @@ TEST(columnTest, json_column_logic_op) { printf("--------------------json string--0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); key = "k2"; - bool eRes1[len+len1] = {false, false, true, true, false, false, false, true, false, true, false, true, true}; + bool eRes1[len+len1] = {false, false, false, false, false, false, false, true, false, true, false, true, true}; for(int i = 0; i < len; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i], false); } - bool eRes_1[len0] = {true, true, false, false, false, false}; + bool eRes_1[len0] = {false, false, false, false, false, false}; for(int i = 0; i < len0; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_1[i], op[i], true); } @@ -1346,11 +1328,11 @@ TEST(columnTest, json_column_logic_op) { printf("--------------------json bool--1 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); key = "k4"; - bool eRes3[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; + bool eRes3[len+len1] = {false, false, false, false, false, false, false, true, true, false, false, false, false}; for(int i = 0; i < len; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i], false); } - bool eRes_3[len0] = {false, true, false, false, false, true}; + bool eRes_3[len0] = {false, false, false, false, false, false}; for(int i = 0; i < len0; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_3[i], op[i], true); } @@ -1419,11 +1401,11 @@ TEST(columnTest, json_column_logic_op) { printf("--------------------json bool-- 0 {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); key = "k8"; - bool eRes7[len+len1] = {false, false, true, true, false, false, false, true, false, false, false, false, false}; + bool eRes7[len+len1] = {false, false, false, false, false, false, false, true, false, false, false, false, false}; for(int i = 0; i < len; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes7[i], op[i], false); } - bool eRes_7[len0] = {true, true, false, false, false, false}; + bool eRes_7[len0] = {false, false, false, false, false, false}; for(int i = 0; i < len0; i++) { makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_7[i], op[i], true); } @@ -1438,11 +1420,11 @@ TEST(columnTest, json_column_logic_op) { printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); key = "k9"; - bool eRes8[len+len1] = {true, false, false, false, false, true, false, true, true, false, true, false, true}; + bool eRes8[len+len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true}; for(int i = 0; i < len; i++){ makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false); } - bool eRes_8[len0] = {false, true, true, true, false, true}; + bool eRes_8[len0] = {false, false, false, false, false, false}; for(int i = 0; i < len0; i++) { makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes_8[i], op[i], true); } @@ -1529,6 +1511,7 @@ TEST(columnTest, bigint_column_multi_binary_column) { SArray *blockList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(blockList, &src); + SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); int16_t dataBlockId = 0, slotId = 0; scltAppendReservedSlot(blockList, &dataBlockId, &slotId, false, rowNum, &colInfo); @@ -2033,7 +2016,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t input->numOfRows = num; input->columnData->info = createColumnInfo(0, type, bytes); - colInfoDataEnsureCapacity(input->columnData, 0, num); + colInfoDataEnsureCapacity(input->columnData, num); if (setVal) { for (int32_t i = 0; i < num; ++i) { diff --git a/source/libs/stream/inc/streamInc.h b/source/libs/stream/inc/streamInc.h index 8aaf4953de..2f41c08354 100644 --- a/source/libs/stream/inc/streamInc.h +++ b/source/libs/stream/inc/streamInc.h @@ -33,7 +33,12 @@ static SStreamGlobalEnv streamEnv; int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb); int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb); int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock* pData); -int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet); +int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock* pData); +int32_t streamBuildDispatchMsg(SStreamTask* pTask, const SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet); + +int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock); + +int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq); #ifdef __cplusplus } diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index 18a6e5bf77..9d92865e47 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -112,7 +112,7 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* // enqueue if (pData != NULL) { pData->type = STREAM_DATA_TYPE_SSDATA_BLOCK; - pData->sourceVg = pReq->sourceVg; + pData->srcVgId = pReq->dataSrcVgId; // decode /*pData->blocks = pReq->data;*/ /*pBlock->sourceVer = pReq->sourceVer;*/ @@ -133,7 +133,42 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* SStreamDispatchRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead)); pCont->inputStatus = status; pCont->streamId = pReq->streamId; - pCont->taskId = pReq->sourceTaskId; + pCont->taskId = pReq->upstreamTaskId; + pRsp->pCont = buf; + pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp); + tmsgSendRsp(pRsp); + return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1; +} + +int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pRsp) { + SStreamDataBlock* pData = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); + int8_t status = TASK_INPUT_STATUS__NORMAL; + + // enqueue + if (pData != NULL) { + pData->type = STREAM_DATA_TYPE_SSDATA_BLOCK; + pData->srcVgId = 0; + // decode + /*pData->blocks = pReq->data;*/ + /*pBlock->sourceVer = pReq->sourceVer;*/ + streamRetrieveReqToData(pReq, pData); + if (streamTaskInput(pTask, (SStreamQueueItem*)pData) == 0) { + status = TASK_INPUT_STATUS__NORMAL; + } else { + status = TASK_INPUT_STATUS__FAILED; + } + } else { + /*streamTaskInputFail(pTask);*/ + /*status = TASK_INPUT_STATUS__FAILED;*/ + } + + // rsp by input status + void* buf = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamRetrieveRsp)); + ((SMsgHead*)buf)->vgId = htonl(pReq->srcNodeId); + SStreamRetrieveRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead)); + pCont->streamId = pReq->streamId; + pCont->rspToTaskId = pReq->srcTaskId; + pCont->rspFromTaskId = pReq->dstTaskId; pRsp->pCont = buf; pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp); tmsgSendRsp(pRsp); @@ -141,7 +176,7 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* } int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) { - qInfo("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, pReq->sourceTaskId); + qInfo("task %d receive dispatch req from node %d task %d", pTask->taskId, pReq->upstreamNodeId, pReq->upstreamTaskId); // 1. handle input streamTaskEnqueue(pTask, pReq, pRsp); @@ -208,3 +243,22 @@ int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) // return 0; } + +int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pRsp) { + qInfo("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); + + streamTaskEnqueueRetrieve(pTask, pReq, pRsp); + + ASSERT(pTask->execType != TASK_EXEC__NONE); + streamExec(pTask, pTask->pMsgCb); + + ASSERT(pTask->dispatchType != TASK_DISPATCH__NONE); + streamDispatch(pTask, pTask->pMsgCb); + + return 0; +} + +int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp) { + // + return 0; +} diff --git a/source/libs/stream/src/streamData.c b/source/libs/stream/src/streamData.c index 6699e86b1e..ef328ecf84 100644 --- a/source/libs/stream/src/streamData.c +++ b/source/libs/stream/src/streamData.c @@ -15,27 +15,6 @@ #include "streamInc.h" -#if 0 -int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput) { - int32_t tlen = 0; - tlen += taosEncodeFixedI8(buf, pOutput->type); - tlen += taosEncodeFixedI32(buf, pOutput->sourceVg); - tlen += taosEncodeFixedI64(buf, pOutput->sourceVer); - ASSERT(pOutput->type == STREAM_INPUT__DATA_BLOCK); - tlen += tEncodeDataBlocks(buf, pOutput->blocks); - return tlen; -} - -void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput) { - buf = taosDecodeFixedI8(buf, &pInput->type); - buf = taosDecodeFixedI32(buf, &pInput->sourceVg); - buf = taosDecodeFixedI64(buf, &pInput->sourceVer); - ASSERT(pInput->type == STREAM_INPUT__DATA_BLOCK); - buf = tDecodeDataBlocks(buf, &pInput->blocks); - return (void*)buf; -} -#endif - int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock* pData) { int32_t blockNum = pReq->blockNum; SArray* pArray = taosArrayInit(blockNum, sizeof(SSDataBlock)); @@ -54,12 +33,25 @@ int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data); // TODO: refactor pDataBlock->info.type = pRetrieve->streamBlockType; - pDataBlock->info.childId = pReq->sourceChildId; + pDataBlock->info.childId = pReq->upstreamChildId; } pData->blocks = pArray; return 0; } +int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock* pData) { + SArray* pArray = taosArrayInit(1, sizeof(SSDataBlock)); + if (pArray == NULL) { + return -1; + } + taosArraySetSize(pArray, 1); + SRetrieveTableRsp* pRetrieve = pReq->pRetrieve; + SSDataBlock* pBlock = taosArrayGet(pArray, 0); + blockCompressDecode(pBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data); + pData->blocks = pArray; + return 0; +} + SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq) { SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM); if (pDataSubmit == NULL) return NULL; diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 1894f697c0..11cd089606 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -19,9 +19,9 @@ int32_t tEncodeStreamDispatchReq(SEncoder* pEncoder, const SStreamDispatchReq* p if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->sourceTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->sourceVg) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->sourceChildId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->dataSrcVgId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->upstreamChildId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->blockNum) < 0) return -1; ASSERT(taosArrayGetSize(pReq->data) == pReq->blockNum); @@ -40,9 +40,9 @@ int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) { if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->sourceTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->sourceVg) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->sourceChildId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->dataSrcVgId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->upstreamChildId) < 0) return -1; if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1; if (tDecodeI32(pDecoder, &pReq->blockNum) < 0) return -1; ASSERT(pReq->blockNum > 0); @@ -62,6 +62,103 @@ int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq) { return 0; } +int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq) { + // + if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->dstNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->dstTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->srcNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->srcTaskId) < 0) return -1; + if (tEncodeBinary(pEncoder, (const uint8_t*)&pReq->pRetrieve, pReq->retrieveLen) < 0) return -1; + tEndEncode(pEncoder); + return pEncoder->pos; +} + +int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq) { + int32_t tlen = 0; + if (tStartDecode(pDecoder) < 0) return -1; + if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->dstNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->dstTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->srcNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->srcTaskId) < 0) return -1; + if (tDecodeBinary(pDecoder, (uint8_t**)&pReq->pRetrieve, &pReq->retrieveLen) < 0) return -1; + tEndDecode(pDecoder); + return 0; +} + +int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock) { + SRetrieveTableRsp* pRetrieve = NULL; + void* buf = NULL; + int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + + pRetrieve = taosMemoryCalloc(1, dataStrLen); + if (pRetrieve == NULL) return -1; + + int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); + pRetrieve->useconds = 0; + pRetrieve->precision = TSDB_DEFAULT_PRECISION; + pRetrieve->compressed = 0; + pRetrieve->completed = 1; + pRetrieve->streamBlockType = pBlock->info.type; + pRetrieve->numOfRows = htonl(pBlock->info.rows); + pRetrieve->numOfCols = htonl(numOfCols); + + int32_t actualLen = 0; + blockCompressEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false); + + SStreamRetrieveReq req = { + .streamId = pTask->streamId, + .srcNodeId = pTask->nodeId, + .srcTaskId = pTask->taskId, + .pRetrieve = pRetrieve, + }; + + int32_t sz = taosArrayGetSize(pTask->childEpInfo); + ASSERT(sz > 0); + for (int32_t i = 0; i < sz; i++) { + SStreamChildEpInfo* pEpInfo = taosArrayGetP(pTask->childEpInfo, i); + req.dstNodeId = pEpInfo->nodeId; + req.dstTaskId = pEpInfo->taskId; + int32_t code; + int32_t len; + tEncodeSize(tEncodeStreamRetrieveReq, &req, len, code); + if (code < 0) { + ASSERT(0); + return -1; + } + + buf = rpcMallocCont(sizeof(SMsgHead) + len); + if (buf == NULL) { + goto FAIL; + } + + ((SMsgHead*)buf)->vgId = htonl(pEpInfo->nodeId); + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, len); + tEncodeStreamRetrieveReq(&encoder, &req); + + SRpcMsg rpcMsg = { + .code = 0, + .msgType = TDMT_STREAM_RETRIEVE, + .pCont = buf, + .contLen = len, + }; + + if (tmsgSendReq(&pEpInfo->epSet, &rpcMsg) < 0) { + ASSERT(0); + return -1; + } + } + return 0; +FAIL: + if (pRetrieve) taosMemoryFree(pRetrieve); + if (buf) taosMemoryFree(buf); + return -1; +} + static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDispatchReq* pReq) { int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); void* buf = taosMemoryCalloc(1, dataStrLen); @@ -74,10 +171,12 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis pRetrieve->completed = 1; pRetrieve->streamBlockType = pBlock->info.type; pRetrieve->numOfRows = htonl(pBlock->info.rows); - pRetrieve->numOfCols = htonl(pBlock->info.numOfCols); + + int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock); + pRetrieve->numOfCols = htonl(numOfCols); int32_t actualLen = 0; - blockCompressEncode(pBlock, pRetrieve->data, &actualLen, pBlock->info.numOfCols, false); + blockCompressEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false); actualLen += sizeof(SRetrieveTableRsp); ASSERT(actualLen <= dataStrLen); taosArrayPush(pReq->dataLen, &actualLen); @@ -86,7 +185,7 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis return 0; } -int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { +int32_t streamBuildDispatchMsg(SStreamTask* pTask, const SStreamDataBlock* data, SRpcMsg* pMsg, SEpSet** ppEpSet) { void* buf = NULL; int32_t code = -1; int32_t blockNum = taosArrayGetSize(data->blocks); @@ -94,9 +193,9 @@ int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcM SStreamDispatchReq req = { .streamId = pTask->streamId, - .sourceTaskId = pTask->taskId, - .sourceVg = data->sourceVg, - .sourceChildId = pTask->childId, + .dataSrcVgId = data->srcVgId, + .upstreamTaskId = pTask->taskId, + .upstreamChildId = pTask->selfChildId, .upstreamNodeId = pTask->nodeId, .blockNum = blockNum, }; @@ -147,7 +246,7 @@ int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcM ASSERT(vgId > 0 || vgId == SNODE_HANDLE); req.taskId = downstreamTaskId; - qInfo("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->childId, + qInfo("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId, downstreamTaskId, vgId); // serialize @@ -208,6 +307,8 @@ int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb) { atomic_store_8(&pTask->outputStatus, TASK_OUTPUT_STATUS__NORMAL); return -1; } + taosArrayDestroyEx(pBlock->blocks, (FDelete)tDeleteSSDataBlock); + taosFreeQitem(pBlock); tmsgSendReq(pEpSet, &dispatchMsg); return 0; diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index bab86223bf..cb7dd241c1 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -13,8 +13,7 @@ * along with this program. If not, see . */ -#include "executor.h" -#include "tstream.h" +#include "streamInc.h" static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) { void* exec = pTask->exec.executor; @@ -25,13 +24,12 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) SStreamTrigger* pTrigger = (SStreamTrigger*)data; qSetMultiStreamInput(exec, pTrigger->pBlock, 1, STREAM_DATA_TYPE_SSDATA_BLOCK, false); } else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) { + ASSERT(pTask->isDataScan); SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; - ASSERT(pTask->inputType == STREAM_INPUT__DATA_SUBMIT); qSetStreamInput(exec, pSubmit->data, STREAM_DATA_TYPE_SUBMIT_BLOCK, false); } else if (pItem->type == STREAM_INPUT__DATA_BLOCK) { SStreamDataBlock* pBlock = (SStreamDataBlock*)data; - ASSERT(pTask->inputType == STREAM_INPUT__DATA_BLOCK); - SArray* blocks = pBlock->blocks; + SArray* blocks = pBlock->blocks; qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_DATA_TYPE_SSDATA_BLOCK, false); } else if (pItem->type == STREAM_INPUT__DROP) { // TODO exec drop @@ -46,10 +44,22 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) ASSERT(false); } if (output == NULL) break; + + if (output->info.type == STREAM_RETRIEVE) { + if (streamBroadcastToChildren(pTask, output) < 0) { + // TODO + } + continue; + } + // TODO: do we need free memory? - SSDataBlock* outputCopy = createOneDataBlock(output, true); - outputCopy->info.childId = pTask->childId; - taosArrayPush(pRes, outputCopy); + SSDataBlock block = {0}; + assignOneDataBlock(&block, output); + block.info.childId = pTask->selfChildId; + taosArrayPush(pRes, &block); + /*SSDataBlock* outputCopy = createOneDataBlock(output, true);*/ + /*outputCopy->info.childId = pTask->selfChildId;*/ + /*taosArrayPush(pRes, outputCopy);*/ } return 0; } @@ -62,6 +72,7 @@ static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { streamTaskExecImpl(pTask, data, pRes); if (pTask->taskStatus == TASK_STATUS__DROPPING) { + taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock); return NULL; } @@ -74,28 +85,27 @@ static SArray* streamExecForQall(SStreamTask* pTask, SArray* pRes) { } qRes->type = STREAM_INPUT__DATA_BLOCK; qRes->blocks = pRes; - /*qRes->sourceVg = pTask->nodeId;*/ if (streamTaskOutput(pTask, qRes) < 0) { streamQueueProcessFail(pTask->inputQueue); - taosArrayDestroy(pRes); + taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock); taosFreeQitem(qRes); return NULL; } - - if (((SStreamQueueItem*)data)->type == STREAM_INPUT__TRIGGER) { - blockDataDestroy(((SStreamTrigger*)data)->pBlock); - taosFreeQitem(data); - } else { - if (pTask->inputType == STREAM_INPUT__DATA_SUBMIT) { - streamDataSubmitRefDec((SStreamDataSubmit*)data); - taosFreeQitem(data); - } else { - taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); - taosFreeQitem(data); - } - } streamQueueProcessSuccess(pTask->inputQueue); - return taosArrayInit(0, sizeof(SSDataBlock)); + pRes = taosArrayInit(0, sizeof(SSDataBlock)); + } + + int8_t type = ((SStreamQueueItem*)data)->type; + if (type == STREAM_INPUT__TRIGGER) { + blockDataDestroy(((SStreamTrigger*)data)->pBlock); + taosFreeQitem(data); + } else if (type == STREAM_INPUT__DATA_BLOCK) { + taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); + taosFreeQitem(data); + } else if (type == STREAM_INPUT__DATA_SUBMIT) { + ASSERT(pTask->isDataScan); + streamDataSubmitRefDec((SStreamDataSubmit*)data); + taosFreeQitem(data); } } return pRes; @@ -120,14 +130,14 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { pRes = streamExecForQall(pTask, pRes); if (pRes == NULL) goto FAIL; - taosArrayDestroy(pRes); + taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock); atomic_store_8(&pTask->execStatus, TASK_EXEC_STATUS__IDLE); return 0; } else if (execStatus == TASK_EXEC_STATUS__CLOSING) { continue; } else if (execStatus == TASK_EXEC_STATUS__EXECUTING) { ASSERT(taosArrayGetSize(pRes) == 0); - taosArrayDestroy(pRes); + taosArrayDestroyEx(pRes, (FDelete)tDeleteSSDataBlock); return 0; } else { ASSERT(0); diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 6dfaa4cb74..1daa9bd50e 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -30,23 +30,46 @@ SStreamTask* tNewSStreamTask(int64_t streamId) { return pTask; } +int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo) { + if (tEncodeI32(pEncoder, pInfo->taskId) < 0) return -1; + if (tEncodeI32(pEncoder, pInfo->nodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pInfo->childId) < 0) return -1; + if (tEncodeSEpSet(pEncoder, &pInfo->epSet) < 0) return -1; + return 0; +} + +int32_t tDecodeStreamEpInfo(SDecoder* pDecoder, SStreamChildEpInfo* pInfo) { + if (tDecodeI32(pDecoder, &pInfo->taskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pInfo->nodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pInfo->childId) < 0) return -1; + if (tDecodeSEpSet(pDecoder, &pInfo->epSet) < 0) return -1; + return 0; +} + int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { /*if (tStartEncode(pEncoder) < 0) return -1;*/ if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->inputType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->taskStatus) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->execStatus) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->isDataScan) < 0) return -1; if (tEncodeI8(pEncoder, pTask->execType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->sinkType) < 0) return -1; if (tEncodeI8(pEncoder, pTask->dispatchType) < 0) return -1; if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1; - if (tEncodeI8(pEncoder, pTask->dataScan) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->childId) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->taskStatus) < 0) return -1; + if (tEncodeI8(pEncoder, pTask->execStatus) < 0) return -1; + + if (tEncodeI32(pEncoder, pTask->selfChildId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; + int32_t epSz = taosArrayGetSize(pTask->childEpInfo); + if (tEncodeI32(pEncoder, epSz) < 0) return -1; + for (int32_t i = 0; i < epSz; i++) { + SStreamChildEpInfo* pInfo = taosArrayGetP(pTask->childEpInfo, i); + if (tEncodeStreamEpInfo(pEncoder, pInfo) < 0) return -1; + } + if (pTask->execType != TASK_EXEC__NONE) { if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; } @@ -83,19 +106,29 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { /*if (tStartDecode(pDecoder) < 0) return -1;*/ if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->inputType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->taskStatus) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->execStatus) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->isDataScan) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->execType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->sinkType) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->dispatchType) < 0) return -1; if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1; - if (tDecodeI8(pDecoder, &pTask->dataScan) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->childId) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->taskStatus) < 0) return -1; + if (tDecodeI8(pDecoder, &pTask->execStatus) < 0) return -1; + + if (tDecodeI32(pDecoder, &pTask->selfChildId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; + int32_t epSz; + if (tDecodeI32(pDecoder, &epSz) < 0) return -1; + pTask->childEpInfo = taosArrayInit(epSz, sizeof(void*)); + for (int32_t i = 0; i < epSz; i++) { + SStreamChildEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamChildEpInfo)); + if (pInfo == NULL) return -1; + if (tDecodeStreamEpInfo(pDecoder, pInfo) < 0) return -1; + taosArrayPush(pTask->childEpInfo, &pInfo); + } + if (pTask->execType != TASK_EXEC__NONE) { if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; } diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index 4f91990ccf..2e8e0e1227 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -28,13 +28,13 @@ extern "C" { #include "trpc.h" #include "ttimer.h" -#define TIMER_MAX_MS 0x7FFFFFFF -#define ENV_TICK_TIMER_MS 1000 -#define PING_TIMER_MS 1000 -#define ELECT_TIMER_MS_MIN 500 -#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) +#define TIMER_MAX_MS 0x7FFFFFFF +#define ENV_TICK_TIMER_MS 1000 +#define PING_TIMER_MS 1000 +#define ELECT_TIMER_MS_MIN 1300 +#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) #define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN) -#define HEARTBEAT_TIMER_MS 100 +#define HEARTBEAT_TIMER_MS 900 #define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0}) diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index aec1f77b42..f124867097 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -26,11 +26,13 @@ extern "C" { #include "syncInt.h" #include "syncRaftEntry.h" #include "taosdef.h" +#include "wal.h" typedef struct SSyncLogStoreData { - SSyncNode* pSyncNode; - SWal* pWal; - SyncIndex beginIndex; // valid begin index, default 0, may be set beginIndex > 0 + SSyncNode* pSyncNode; + SWal* pWal; + SWalReadHandle* pWalHandle; + // SyncIndex beginIndex; // valid begin index, default 0, may be set beginIndex > 0 } SSyncLogStoreData; SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode); diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index c51cbc0513..47d0976aca 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -420,39 +420,26 @@ static int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry) { // prevLogIndex == -1 static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries* pMsg) { if (pMsg->prevLogIndex == SYNC_INDEX_INVALID) { - if (gRaftDetailLog) { - sTrace("syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld", pMsg->prevLogIndex); - } return true; } SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); if (pMsg->prevLogIndex > myLastIndex) { - if (gRaftDetailLog) { - sTrace("syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld", pMsg->prevLogIndex, - myLastIndex); - } + sDebug("vgId:%d sync log not ok, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); return false; } SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); + if (myPreLogTerm == SYNC_TERM_INVALID) { + sDebug("vgId:%d sync log not ok2, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); + return false; + } + if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) { - if (gRaftDetailLog) { - sTrace( - "syncNodeOnAppendEntriesLogOK true, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, " - "myPreLogTerm:%lu", - pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm); - } return true; } - if (gRaftDetailLog) { - sTrace( - "syncNodeOnAppendEntriesLogOK false, pMsg->prevLogIndex:%ld, myLastIndex:%ld, pMsg->prevLogTerm:%lu, " - "myPreLogTerm:%lu", - pMsg->prevLogIndex, myLastIndex, pMsg->prevLogTerm, myPreLogTerm); - } - + sDebug("vgId:%d sync log not ok3, preindex:%ld", pSyncNode->vgId, pMsg->prevLogIndex); return false; } @@ -461,14 +448,11 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs int32_t code = 0; // print log - char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncAppendEntries, vgId:%d, term:%lu", ths->vgId, - ths->pRaftStore->currentTerm); - syncAppendEntriesLog2(logBuf, pMsg); + syncAppendEntriesLog2("==syncNodeOnAppendEntriesSnapshotCb==", pMsg); // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - sInfo("recv SyncAppendEntries maybe replica already dropped"); + syncNodeEventLog(ths, "recv sync-append-entries, maybe replica already dropped"); return ret; } @@ -492,7 +476,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs do { bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; if (condition) { - sTrace("recv SyncAppendEntries, candidate to follower"); + syncNodeEventLog(ths, "recv sync-append-entries, candidate to follower"); syncNodeBecomeFollower(ths, "from candidate by append entries"); // do not reply? @@ -500,6 +484,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs } } while (0); +#if 0 // fake match // // condition1: @@ -525,7 +510,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition0 = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && syncNodeHasSnapshot(ths); bool condition1 = - condition0 && (ths->pLogStore->syncLogEntryCount(ths->pLogStore) == 0) && (pMsg->prevLogIndex > myLastIndex); + condition0 && (ths->pLogStore->syncLogEntryCount(ths->pLogStore) == 0) && (pMsg->prevLogIndex > myLastIndex); // donot use syncLogEntryCount!!! use isEmpty bool condition2 = condition0 && (ths->pLogStore->syncLogLastIndex(ths->pLogStore) <= snapshot.lastApplyIndex) && (pMsg->prevLogIndex > myLastIndex); bool condition3 = condition0 && (pMsg->prevLogIndex < snapshot.lastApplyIndex); @@ -533,11 +518,10 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = condition1 || condition2 || condition3 || condition4; if (condition) { - sTrace( - "recv SyncAppendEntries, fake match, myLastIndex:%ld, syncLogBeginIndex:%ld, syncLogEndIndex:%ld, " - "condition1:%d, condition2:%d, condition3:%d, condition4:%d", - myLastIndex, ths->pLogStore->syncLogBeginIndex(ths->pLogStore), - ths->pLogStore->syncLogEndIndex(ths->pLogStore), condition1, condition2, condition3, condition4); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, fake match, pre-index:%ld, pre-term:%lu", + pMsg->prevLogIndex, pMsg->prevLogTerm); + syncNodeEventLog(ths, logBuf); // prepare response msg SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); @@ -557,6 +541,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs return ret; } } while (0); +#endif // fake match2 // @@ -571,8 +556,13 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && (pMsg->prevLogIndex <= ths->commitIndex); if (condition) { - sTrace("recv SyncAppendEntries, fake match2, msg-prevLogIndex:%ld, my-commitIndex:%ld", pMsg->prevLogIndex, - ths->commitIndex); + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries, fake match2, pre-index:%ld, pre-term:%lu, datalen:%d", pMsg->prevLogIndex, + pMsg->prevLogTerm, pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); SyncIndex matchIndex = ths->commitIndex; bool hasAppendEntries = pMsg->dataLen > 0; @@ -600,6 +590,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs code = syncNodePreCommit(ths, pAppendEntry); ASSERT(code == 0); + // update match index matchIndex = pMsg->prevLogIndex + 1; syncEntryDestory(pAppendEntry); @@ -645,11 +636,10 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = condition1 || condition2; if (condition) { - sTrace( - "recv SyncAppendEntries, not match, syncLogBeginIndex:%ld, syncLogEndIndex:%ld, condition1:%d, " - "condition2:%d, logOK:%d", - ths->pLogStore->syncLogBeginIndex(ths->pLogStore), ths->pLogStore->syncLogEndIndex(ths->pLogStore), - condition1, condition2, logOK); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, not match, pre-index:%ld, pre-term:%lu, datalen:%d", + pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + syncNodeEventLog(ths, logBuf); // prepare response msg SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); @@ -688,8 +678,10 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // has entries in SyncAppendEntries msg bool hasAppendEntries = pMsg->dataLen > 0; - sTrace("recv SyncAppendEntries, match, myLastIndex:%ld, hasExtraEntries:%d, hasAppendEntries:%d", myLastIndex, - hasExtraEntries, hasAppendEntries); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries, match, pre-index:%ld, pre-term:%lu, datalen:%d", + pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + syncNodeEventLog(ths, logBuf); if (hasExtraEntries) { // make log same, rollback deleted entries diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index f13a3604da..6ca356b4f6 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -101,32 +101,27 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries int32_t ret = 0; // print log - char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncAppendEntriesReply, vgId:%d, term:%lu", ths->vgId, - ths->pRaftStore->currentTerm); - syncAppendEntriesReplyLog2(logBuf, pMsg); + syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplySnapshotCb==", pMsg); // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - sInfo("recv SyncAppendEntriesReply, maybe replica already dropped"); - return ret; + syncNodeEventLog(ths, "recv sync-append-entries-reply, maybe replica already dropped"); + return 0; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - sTrace("recv SyncAppendEntriesReply, drop stale response, receive_term:%lu current_term:%lu", pMsg->term, - ths->pRaftStore->currentTerm); - return ret; + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%lu, drop stale response", pMsg->term); + syncNodeEventLog(ths, logBuf); + return 0; } - syncIndexMgrLog2("recv SyncAppendEntriesReply, before pNextIndex:", ths->pNextIndex); - syncIndexMgrLog2("recv SyncAppendEntriesReply, before pMatchIndex:", ths->pMatchIndex); if (gRaftDetailLog) { - SSnapshot snapshot; - ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); - sTrace("recv SyncAppendEntriesReply, before snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu", - snapshot.lastApplyIndex, snapshot.lastApplyTerm); + syncNodeEventLog(ths, "recv sync-append-entries-reply, before"); } + syncIndexMgrLog2("recv sync-append-entries-reply, before pNextIndex:", ths->pNextIndex); + syncIndexMgrLog2("recv sync-append-entries-reply, before pMatchIndex:", ths->pMatchIndex); // no need this code, because if I receive reply.term, then I must have sent for that term. // if (pMsg->term > ths->pRaftStore->currentTerm) { @@ -134,12 +129,10 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries // } if (pMsg->term > ths->pRaftStore->currentTerm) { - char logBuf[128] = {0}; - snprintf(logBuf, sizeof(logBuf), "recv SyncAppendEntriesReply, error term, receive_term:%lu current_term:%lu", - pMsg->term, ths->pRaftStore->currentTerm); - syncNodeLog2(logBuf, ths); - sError("%s", logBuf); - return ret; + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%lu", pMsg->term); + syncNodeErrorLog(ths, logBuf); + return -1; } ASSERT(pMsg->term == ths->pRaftStore->currentTerm); @@ -228,8 +221,11 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries } } - syncIndexMgrLog2("recv SyncAppendEntriesReply, after pNextIndex:", ths->pNextIndex); - syncIndexMgrLog2("recv SyncAppendEntriesReply, after pMatchIndex:", ths->pMatchIndex); + if (gRaftDetailLog) { + syncNodeEventLog(ths, "recv sync-append-entries-reply, after"); + } + syncIndexMgrLog2("recv sync-append-entries-reply, after pNextIndex:", ths->pNextIndex); + syncIndexMgrLog2("recv sync-append-entries-reply, after pMatchIndex:", ths->pMatchIndex); return ret; } \ No newline at end of file diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index da6d869611..42ba2b85b1 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -345,7 +345,7 @@ bool syncCanLeaderTransfer(int64_t rid) { return matchOK; } -int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { +int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) { int32_t ret = syncPropose(rid, pMsg, isWeak); return ret; } @@ -416,7 +416,7 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct } } sMeta->lastConfigIndex = lastIndex; - sTrace("vgId:%d, get snapshot meta by index:%" PRId64 " lastConfigIndex:%" PRId64, pSyncNode->vgId, snapshotIndex, + sTrace("vgId:%d, get snapshot meta by index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId, snapshotIndex, sMeta->lastConfigIndex); taosReleaseRef(tsNodeRefId, pSyncNode->rid); @@ -433,8 +433,9 @@ SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapsho lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i]; } } + sTrace("vgId:%d, sync get snapshot last config index, index:%ld lcindex:%ld", pSyncNode->vgId, snapshotLastApplyIndex, + lastIndex); - sTrace("sync syncNodeGetSnapshotConfigIndex index:%ld lastConfigIndex:%ld", snapshotLastApplyIndex, lastIndex); return lastIndex; } @@ -584,7 +585,7 @@ void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) { taosReleaseRef(tsNodeRefId, pSyncNode->rid); } -int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { +int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { int32_t ret = 0; SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); @@ -1309,40 +1310,48 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + char* pCfgStr = syncCfg2SimpleStr(&(pSyncNode->pRaftCfg->cfg)); + char* printStr = ""; + if (pCfgStr != NULL) { + printStr = pCfgStr; + } + if (userStrLen < 256) { - char logBuf[128 + 256]; + char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d", + "lconfig:%ld, changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing); + pSyncNode->changing, pSyncNode->restoreFinish, printStr); } else { snprintf(logBuf, sizeof(logBuf), "%s", str); } sDebug("%s", logBuf); } else { - int len = 128 + userStrLen; + int len = 256 + userStrLen; char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, "vgId:%d, sync %s %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " "replica-num:%d, " - "lconfig:%ld, changing:%d", + "lconfig:%ld, changing:%d, restore:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing); + pSyncNode->changing, pSyncNode->restoreFinish, printStr); } else { snprintf(s, len, "%s", str); } sDebug("%s", s); taosMemoryFree(s); } + + taosMemoryFree(pCfgStr); } void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { @@ -1394,14 +1403,34 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { int len = 256; char* s = (char*)taosMemoryMalloc(len); + + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + } + SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); + SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + snprintf(s, len, - "syncNode: vgId:%d, currentTerm:%lu, commitIndex:%ld, state:%d %s, isStandBy:%d, " - "electTimerLogicClock:%lu, " - "electTimerLogicClockUser:%lu, " - "electTimerMS:%d, replicaNum:%d", - pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, pSyncNode->state, - syncUtilState2String(pSyncNode->state), pSyncNode->pRaftCfg->isStandBy, pSyncNode->electTimerLogicClock, - pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS, pSyncNode->replicaNum); + "vgId:%d, sync %s, term:%lu, commit:%ld, beginlog:%ld, lastlog:%ld, lastsnapshot:%ld, standby:%d, " + "replica-num:%d, " + "lconfig:%ld, changing:%d, restore:%d", + pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, + pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, + pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish); + + /* + snprintf(s, len, + "syncNode: vgId:%d, term:%lu, commit:%ld, state:%d %s, standby:%d, " + "lc:%lu, " + "lc-user:%lu, " + "ems:%d, replica-num:%d, restore:%d, changing:%d", + pSyncNode->vgId, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, pSyncNode->state, + syncUtilState2String(pSyncNode->state), pSyncNode->pRaftCfg->isStandBy, pSyncNode->electTimerLogicClock, + pSyncNode->electTimerLogicClockUser, pSyncNode->electTimerMS, pSyncNode->replicaNum, + pSyncNode->restoreFinish, pSyncNode->changing); + */ + return s; } @@ -1455,6 +1484,17 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde isAdd = false; } + // log begin config change + do { + char eventLog[256]; + char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig); + char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig); + snprintf(eventLog, sizeof(eventLog), "begin do config change, from %s to %s", pOldCfgStr, pNewCfgStr); + syncNodeEventLog(pSyncNode, eventLog); + taosMemoryFree(pOldCfgStr); + taosMemoryFree(pNewCfgStr); + } while (0); + if (IamInNew) { pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal } @@ -1613,6 +1653,17 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } _END: + + // log end config change + do { + char eventLog[256]; + char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig); + char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig); + snprintf(eventLog, sizeof(eventLog), "end do config change, from %s to %s", pOldCfgStr, pNewCfgStr); + syncNodeEventLog(pSyncNode, eventLog); + taosMemoryFree(pOldCfgStr); + taosMemoryFree(pNewCfgStr); + } while (0); return; } @@ -1888,6 +1939,16 @@ SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode) { return syncStartIndex; } +SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) { + SyncIndex preIndex = index - 1; + if (preIndex < SYNC_INDEX_INVALID) { + preIndex = SYNC_INDEX_INVALID; + } + + return preIndex; +} + +/* SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(index >= SYNC_INDEX_BEGIN); @@ -1900,7 +1961,46 @@ SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index) { SyncIndex preIndex = index - 1; return preIndex; } +*/ +SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { + if (index < SYNC_INDEX_BEGIN) { + return SYNC_TERM_INVALID; + } + + if (index == SYNC_INDEX_BEGIN) { + return 0; + } + + SyncTerm preTerm = 0; + SyncIndex preIndex = index - 1; + SSyncRaftEntry* pPreEntry = NULL; + int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, preIndex, &pPreEntry); + if (code == 0) { + ASSERT(pPreEntry != NULL); + preTerm = pPreEntry->term; + taosMemoryFree(pPreEntry); + return preTerm; + } else { + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1}; + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + if (snapshot.lastApplyIndex == preIndex) { + return snapshot.lastApplyTerm; + } + } + } + + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "sync node get pre term error, index:%ld", index); + syncNodeErrorLog(pSyncNode, logBuf); + } while (0); + + return SYNC_TERM_INVALID; +} + +#if 0 SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(index >= SYNC_INDEX_BEGIN); @@ -1938,6 +2038,7 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { ASSERT(0); return -1; } +#endif #if 0 SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 2cc1eb0239..f40eff57d9 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -107,26 +107,30 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { } char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { - int32_t len = 512; - char *s = taosMemoryMalloc(len); - memset(s, 0, len); + if (pSyncCfg != NULL) { + int32_t len = 512; + char *s = taosMemoryMalloc(len); + memset(s, 0, len); - snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); - char *p = s + strlen(s); - for (int i = 0; i < pSyncCfg->replicaNum; ++i) { - /* - if (p + 128 + 32 > s + len) { - break; + snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); + char *p = s + strlen(s); + for (int i = 0; i < pSyncCfg->replicaNum; ++i) { + /* + if (p + 128 + 32 > s + len) { + break; + } + */ + char buf[128 + 32]; + snprintf(buf, sizeof(buf), "%s:%d, ", pSyncCfg->nodeInfo[i].nodeFqdn, pSyncCfg->nodeInfo[i].nodePort); + strncpy(p, buf, sizeof(buf)); + p = s + strlen(s); } - */ - char buf[128 + 32]; - snprintf(buf, sizeof(buf), "%s:%d, ", pSyncCfg->nodeInfo[i].nodeFqdn, pSyncCfg->nodeInfo[i].nodePort); - strncpy(p, buf, sizeof(buf)); - p = s + strlen(s); - } - strcpy(p - 2, "}"); + strcpy(p - 2, "}"); - return s; + return s; + } + + return NULL; } int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) { diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 0f6e8a28d9..cc606f4df8 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -16,10 +16,10 @@ #include "syncRaftLog.h" #include "syncRaftCfg.h" #include "syncRaftStore.h" -#include "wal.h" // refactor, log[0 .. n] ==> log[m .. n] -static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex beginIndex); +static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex); +// static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex beginIndex); static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore); static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore); static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore); @@ -45,31 +45,43 @@ static int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncI static SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore); // refactor, log[0 .. n] ==> log[m .. n] +/* static int32_t raftLogSetBeginIndex(struct SSyncLogStore* pLogStore, SyncIndex beginIndex) { - sTrace("raftLogSetBeginIndex beginIndex:%ld", beginIndex); - // if beginIndex == 0, donot need call this funciton ASSERT(beginIndex > 0); SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; + sTrace("vgId:%d, reset wal begin index:%ld", pData->pSyncNode->vgId, beginIndex); + pData->beginIndex = beginIndex; walRestoreFromSnapshot(pWal, beginIndex - 1); return 0; } +*/ + +static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex) { + ASSERT(snapshotIndex >= 0); + + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + walRestoreFromSnapshot(pWal, snapshotIndex); + return 0; +} static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; - return pData->beginIndex; + SyncIndex firstVer = walGetFirstVer(pWal); + return firstVer; } static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftLogLastIndex(pLogStore); } static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore) { - SyncIndex beginIndex = raftLogBeginIndex(pLogStore); - SyncIndex endIndex = raftLogEndIndex(pLogStore); - return (endIndex < beginIndex); + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + return walIsEmpty(pWal); } static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) { @@ -96,23 +108,8 @@ static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex lastVer = walGetLastVer(pWal); - SyncIndex firstVer = walGetFirstVer(pWal); - if (lastVer < firstVer) { - // no record - lastIndex = -1; - - } else { - if (firstVer >= 0) { - lastIndex = lastVer; - } else if (firstVer == -1) { - lastIndex = -1; - } else { - ASSERT(0); - } - } - - return lastIndex; + return lastVer; } static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) { @@ -122,6 +119,26 @@ static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) { return lastVer + 1; } +static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + if (walIsEmpty(pWal)) { + return 0; + } else { + SSyncRaftEntry* pLastEntry; + int32_t code = raftLogGetLastEntry(pLogStore, &pLastEntry); + ASSERT(code == 0); + ASSERT(pLastEntry != NULL); + + SyncTerm lastTerm = pLastEntry->term; + taosMemoryFree(pLastEntry); + return lastTerm; + } + + return 0; +} + +/* static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { SyncTerm lastTerm = 0; if (raftLogEntryCount(pLogStore) == 0) { @@ -137,6 +154,7 @@ static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { } return lastTerm; } +*/ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { SSyncLogStoreData* pData = pLogStore->data; @@ -144,7 +162,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr SyncIndex writeIndex = raftLogWriteIndex(pLogStore); if (pEntry->index != writeIndex) { - sError("raftLogAppendEntry error, pEntry->index:%ld update to writeIndex:%ld", pEntry->index, writeIndex); + sError("vgId:%d wal write index error, entry-index:%ld update to %ld", pData->pSyncNode->vgId, pEntry->index, + writeIndex); pEntry->index = writeIndex; } @@ -157,10 +176,14 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("raftLogAppendEntry error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + ASSERT(0); } @@ -228,7 +251,8 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, *ppEntry = NULL; - SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + // SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + SWalReadHandle* pWalHandle = pData->pWalHandle; if (pWalHandle == NULL) { return -1; } @@ -237,12 +261,26 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("raftLogGetEntry error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, + err, errStr, sysErr, sysErrStr); + if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + syncNodeEventLog(pData->pSyncNode, logBuf); + } else { + syncNodeErrorLog(pData->pSyncNode, logBuf); + } + } while (0); + + /* + int32_t saveErr = terrno; + walCloseReadHandle(pWalHandle); + terrno = saveErr; + */ - walCloseReadHandle(pWalHandle); return code; } @@ -257,8 +295,11 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, ASSERT((*ppEntry)->dataLen == pWalHandle->pHead->head.bodyLen); memcpy((*ppEntry)->data, pWalHandle->pHead->head.body, pWalHandle->pHead->head.bodyLen); - // need to hold, do not new every time!! - walCloseReadHandle(pWalHandle); + /* + int32_t saveErr = terrno; + walCloseReadHandle(pWalHandle); + terrno = saveErr; + */ return code; } @@ -270,15 +311,35 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("raftLogTruncate error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + sError("vgId:%d wal truncate error, from-index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); + ASSERT(0); } return code; } +static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry) { + SSyncLogStoreData* pData = pLogStore->data; + SWal* pWal = pData->pWal; + ASSERT(ppLastEntry != NULL); + + *ppLastEntry = NULL; + if (walIsEmpty(pWal)) { + terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; + return -1; + } else { + SyncIndex lastIndex = raftLogLastIndex(pLogStore); + int32_t code = raftLogGetEntry(pLogStore, lastIndex, ppLastEntry); + return code; + } + + return -1; +} + +/* static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry) { *ppLastEntry = NULL; if (raftLogEntryCount(pLogStore) == 0) { @@ -288,6 +349,7 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp int32_t code = raftLogGetEntry(pLogStore, lastIndex, ppLastEntry); return code; } +*/ //------------------------------- SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { @@ -300,16 +362,22 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { SSyncLogStoreData* pData = pLogStore->data; pData->pSyncNode = pSyncNode; pData->pWal = pSyncNode->pWal; + ASSERT(pData->pWal != NULL); - SyncIndex firstVer = walGetFirstVer(pData->pWal); - SyncIndex lastVer = walGetLastVer(pData->pWal); - if (firstVer >= 0) { - pData->beginIndex = firstVer; - } else if (firstVer == -1) { - pData->beginIndex = lastVer + 1; - } else { - ASSERT(0); - } + pData->pWalHandle = walOpenReadHandle(pData->pWal); + ASSERT(pData->pWalHandle != NULL); + + /* + SyncIndex firstVer = walGetFirstVer(pData->pWal); + SyncIndex lastVer = walGetLastVer(pData->pWal); + if (firstVer >= 0) { + pData->beginIndex = firstVer; + } else if (firstVer == -1) { + pData->beginIndex = lastVer + 1; + } else { + ASSERT(0); + } + */ pLogStore->appendEntry = logStoreAppendEntry; pLogStore->getEntry = logStoreGetEntry; @@ -319,7 +387,8 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { pLogStore->updateCommitIndex = logStoreUpdateCommitIndex; pLogStore->getCommitIndex = logStoreGetCommitIndex; - pLogStore->syncLogSetBeginIndex = raftLogSetBeginIndex; + // pLogStore->syncLogSetBeginIndex = raftLogSetBeginIndex; + pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot; pLogStore->syncLogBeginIndex = raftLogBeginIndex; pLogStore->syncLogEndIndex = raftLogEndIndex; pLogStore->syncLogIsEmpty = raftLogIsEmpty; @@ -338,6 +407,11 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) { void logStoreDestory(SSyncLogStore* pLogStore) { if (pLogStore != NULL) { + SSyncLogStoreData* pData = pLogStore->data; + if (pData->pWalHandle != NULL) { + walCloseReadHandle(pData->pWalHandle); + } + taosMemoryFree(pLogStore->data); taosMemoryFree(pLogStore); } @@ -360,10 +434,14 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) { if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("walWriteWithSyncInfo error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal write error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); + syncNodeErrorLog(pData->pSyncNode, logBuf); + ASSERT(0); } @@ -382,20 +460,30 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { SWal* pWal = pData->pWal; if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) { - SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + // SWalReadHandle* pWalHandle = walOpenReadHandle(pWal); + SWalReadHandle* pWalHandle = pData->pWalHandle; ASSERT(pWalHandle != NULL); int32_t code = walReadWithHandle(pWalHandle, index); if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("walReadWithHandle error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + + do { + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "wal read error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, + err, err, errStr, sysErr, sysErrStr); + if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + syncNodeEventLog(pData->pSyncNode, logBuf); + } else { + syncNodeErrorLog(pData->pSyncNode, logBuf); + } + } while (0); + ASSERT(0); } - // ASSERT(walReadWithHandle(pWalHandle, index) == 0); SSyncRaftEntry* pEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen); ASSERT(pEntry != NULL); @@ -409,8 +497,12 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) { ASSERT(pEntry->dataLen == pWalHandle->pHead->head.bodyLen); memcpy(pEntry->data, pWalHandle->pHead->head.body, pWalHandle->pHead->head.bodyLen); - // need to hold, do not new every time!! - walCloseReadHandle(pWalHandle); + /* + int32_t saveErr = terrno; + walCloseReadHandle(pWalHandle); + terrno = saveErr; + */ + return pEntry; } else { @@ -426,10 +518,11 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) { if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("walRollback error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, - linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + sError("vgId:%d wal truncate error, from-index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); + ASSERT(0); } return 0; @@ -460,9 +553,11 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { if (code != 0) { int32_t err = terrno; const char* errStr = tstrerror(err); - int32_t linuxErr = errno; - const char* linuxErrMsg = strerror(errno); - sError("walCommit error, err:%d %X, msg:%s, linuxErr:%d, linuxErrMsg:%s", err, err, errStr, linuxErr, linuxErrMsg); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + sError("vgId:%d wal update commit index error, index:%ld, err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pData->pSyncNode->vgId, index, err, err, errStr, sysErr, sysErrStr); + ASSERT(0); } return 0; @@ -485,6 +580,7 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) { return pEntry; } +/* cJSON* logStore2Json(SSyncLogStore* pLogStore) { char u64buf[128] = {0}; SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; @@ -531,6 +627,57 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) { cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot); return pJson; } +*/ + +cJSON* logStore2Json(SSyncLogStore* pLogStore) { + char u64buf[128] = {0}; + SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; + cJSON* pRoot = cJSON_CreateObject(); + + if (pData != NULL && pData->pWal != NULL) { + snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + + SyncIndex beginIndex = raftLogBeginIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%ld", beginIndex); + cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); + + SyncIndex endIndex = raftLogEndIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%ld", endIndex); + cJSON_AddStringToObject(pRoot, "endIndex", u64buf); + + int32_t count = raftLogEntryCount(pLogStore); + cJSON_AddNumberToObject(pRoot, "entryCount", count); + + snprintf(u64buf, sizeof(u64buf), "%ld", raftLogWriteIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); + cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%ld", raftLogLastIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%lu", raftLogLastTerm(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); + + cJSON* pEntries = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "pEntries", pEntries); + + if (!raftLogIsEmpty(pLogStore)) { + for (SyncIndex i = beginIndex; i <= endIndex; ++i) { + SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i); + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + syncEntryDestory(pEntry); + } + } + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot); + return pJson; +} char* logStore2Str(SSyncLogStore* pLogStore) { cJSON* pJson = logStore2Json(pLogStore); @@ -550,7 +697,8 @@ cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) { snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); cJSON_AddStringToObject(pRoot, "pWal", u64buf); - snprintf(u64buf, sizeof(u64buf), "%ld", pData->beginIndex); + SyncIndex beginIndex = raftLogBeginIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%ld", beginIndex); cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); SyncIndex endIndex = raftLogEndIndex(pLogStore); diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index d6e6fbe522..02cd977e1e 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -139,6 +139,15 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) { // pre index, pre term SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex); SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex); + if (preLogTerm == SYNC_TERM_INVALID) { + SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1; + syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex); + syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID); + sError("vgId:%d sync get pre term error, nextIndex:%ld, update next-index:%ld, match-index:%d, raftid:%ld", + pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr); + + return -1; + } // batch optimized // SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex); @@ -210,6 +219,17 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) { int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) { int32_t ret = 0; + do { + char host[128]; + uint16_t port; + syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); + sDebug( + "vgId:%d, send sync-append-entries to %s:%d, term:%lu, pre-index:%ld, pre-term:%lu, pterm:%lu, commit:%ld, " + "datalen:%d", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen); + } while (0); + SRpcMsg rpcMsg; syncAppendEntries2RpcMsg(pMsg, &rpcMsg); syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 3e062d395f..4fc0128400 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -113,8 +113,16 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot snapshot, void } if (!getLastConfig) { - syncNodeLog3("", pSender->pSyncNode); - ASSERT(0); + char logBuf[128]; + snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %ld to -1", + pSender->snapshot.lastConfigIndex); + pSender->snapshot.lastConfigIndex = -1; + + char *eventLog = snapshotSender2SimpleStr(pSender, logBuf); + syncNodeEventLog(pSender->pSyncNode, eventLog); + taosMemoryFree(eventLog); + + memset(&(pSender->lastConfig), 0, sizeof(SSyncCfg)); } } else { @@ -533,7 +541,12 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { ASSERT(writeCode == 0); pSyncNode->pFsm->FpSnapshotStopWrite(pSyncNode->pFsm, pReceiver->pWriter, true); - pSyncNode->pLogStore->syncLogSetBeginIndex(pSyncNode->pLogStore, pMsg->lastIndex + 1); + if (pReceiver->snapshot.lastApplyIndex > pReceiver->pSyncNode->commitIndex) { + pReceiver->pSyncNode->commitIndex = pReceiver->snapshot.lastApplyIndex; + } + + // pSyncNode->pLogStore->syncLogSetBeginIndex(pSyncNode->pLogStore, pMsg->lastIndex + 1); + pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pSyncNode->pLogStore, pMsg->lastIndex); // maybe update lastconfig if (pMsg->lastConfigIndex >= SYNC_INDEX_BEGIN) { @@ -552,7 +565,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver finish"); + char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver finish, apply snapshot"); syncNodeEventLog(pSyncNode, eventLog); taosMemoryFree(eventLog); } while (0); @@ -563,7 +576,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { needRsp = true; do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver end"); + char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver stop"); syncNodeEventLog(pSyncNode, eventLog); taosMemoryFree(eventLog); } while (0); diff --git a/source/libs/sync/test/syncLogStoreCheck2.cpp b/source/libs/sync/test/syncLogStoreCheck2.cpp index 431b291ca7..80679bc85c 100644 --- a/source/libs/sync/test/syncLogStoreCheck2.cpp +++ b/source/libs/sync/test/syncLogStoreCheck2.cpp @@ -65,7 +65,7 @@ int main(int argc, char** argv) { SSyncLogStore* pLog = logStoreCreate(pSyncNode); assert(pLog != NULL); - logStorePrint2((char*)"==syncLogStoreCheck==", pLog); + logStoreSimplePrint2((char*)"==syncLogStoreCheck2==", pLog); walClose(pWal); logStoreDestory(pLog); diff --git a/source/libs/sync/test/syncRaftLogTest2.cpp b/source/libs/sync/test/syncRaftLogTest2.cpp index bd6fa7c2c3..e3ceae0615 100644 --- a/source/libs/sync/test/syncRaftLogTest2.cpp +++ b/source/libs/sync/test/syncRaftLogTest2.cpp @@ -113,7 +113,8 @@ void test2() { pLogStore = logStoreCreate(pSyncNode); assert(pLogStore); pSyncNode->pLogStore = pLogStore; - pLogStore->syncLogSetBeginIndex(pLogStore, 5); + //pLogStore->syncLogSetBeginIndex(pLogStore, 5); + pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4); logStoreLog2((char*)"\n\n\ntest2 ----- ", pLogStore); if (gAssert) { @@ -228,7 +229,8 @@ void test4() { assert(pLogStore); pSyncNode->pLogStore = pLogStore; logStoreLog2((char*)"\n\n\ntest4 ----- ", pLogStore); - pLogStore->syncLogSetBeginIndex(pLogStore, 5); + //pLogStore->syncLogSetBeginIndex(pLogStore, 5); + pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4); for (int i = 5; i <= 9; ++i) { int32_t dataLen = 10; @@ -289,7 +291,8 @@ void test5() { assert(pLogStore); pSyncNode->pLogStore = pLogStore; logStoreLog2((char*)"\n\n\ntest5 ----- ", pLogStore); - pLogStore->syncLogSetBeginIndex(pLogStore, 5); + //pLogStore->syncLogSetBeginIndex(pLogStore, 5); + pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4); for (int i = 5; i <= 9; ++i) { int32_t dataLen = 10; @@ -363,7 +366,8 @@ void test6() { assert(pLogStore); pSyncNode->pLogStore = pLogStore; logStoreLog2((char*)"\n\n\ntest6 ----- ", pLogStore); - pLogStore->syncLogSetBeginIndex(pLogStore, 5); + // pLogStore->syncLogSetBeginIndex(pLogStore, 5); + pLogStore->syncLogRestoreFromSnapshot(pLogStore, 4); for (int i = 5; i <= 9; ++i) { int32_t dataLen = 10; @@ -405,14 +409,32 @@ void test6() { assert(pLogStore->syncLogLastTerm(pLogStore) == 0); } + do { + SyncIndex firstVer = walGetFirstVer(pWal); + SyncIndex lastVer = walGetLastVer(pWal); + bool isEmpty = walIsEmpty(pWal); + printf("before -------- firstVer:%ld lastVer:%ld isEmpty:%d \n", firstVer, lastVer, isEmpty); + } while (0); + logStoreDestory(pLogStore); cleanup(); + + // restart init(); pLogStore = logStoreCreate(pSyncNode); assert(pLogStore); pSyncNode->pLogStore = pLogStore; + + + do { + SyncIndex firstVer = walGetFirstVer(pWal); + SyncIndex lastVer = walGetLastVer(pWal); + bool isEmpty = walIsEmpty(pWal); + printf("after -------- firstVer:%ld lastVer:%ld isEmpty:%d \n", firstVer, lastVer, isEmpty); + } while (0); + logStoreLog2((char*)"\n\n\ntest6 restart ----- ", pLogStore); if (gAssert) { @@ -432,17 +454,20 @@ void test6() { int main(int argc, char** argv) { tsAsyncLog = 0; sDebugFlag = DEBUG_TRACE + DEBUG_INFO + DEBUG_SCREEN + DEBUG_FILE; + gRaftDetailLog = true; if (argc == 2) { gAssert = atoi(argv[1]); } sTrace("gAssert : %d", gAssert); +/* test1(); test2(); test3(); test4(); test5(); +*/ test6(); return 0; diff --git a/source/libs/sync/test/syncRaftLogTest3.cpp b/source/libs/sync/test/syncRaftLogTest3.cpp index c81a6d3ca9..302e29a091 100644 --- a/source/libs/sync/test/syncRaftLogTest3.cpp +++ b/source/libs/sync/test/syncRaftLogTest3.cpp @@ -312,7 +312,8 @@ void test5() { pSyncNode->pLogStore = pLogStore; logStoreLog2((char*)"\n\n\ntest5 ----- ", pLogStore); - pSyncNode->pLogStore->syncLogSetBeginIndex(pSyncNode->pLogStore, 6); + //pSyncNode->pLogStore->syncLogSetBeginIndex(pSyncNode->pLogStore, 6); + pLogStore->syncLogRestoreFromSnapshot(pSyncNode->pLogStore, 5); for (int i = 6; i <= 10; ++i) { int32_t dataLen = 10; SSyncRaftEntry* pEntry = syncEntryBuild(dataLen); @@ -372,6 +373,7 @@ void test5() { int main(int argc, char** argv) { tsAsyncLog = 0; sDebugFlag = DEBUG_TRACE + DEBUG_INFO + DEBUG_SCREEN + DEBUG_FILE; + gRaftDetailLog = true; if (argc == 2) { gAssert = atoi(argv[1]); diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 1c924fa636..05fe62762a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -857,20 +857,20 @@ static int tdbBtreeBalance(SBTC *pBtc) { } // TDB_BTREE_BALANCE -static int tdbFetchOvflPage(SPager *pPager, SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { +static int tdbFetchOvflPage(SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { int ret = 0; *pPgno = 0; SBtreeInitPageArg iArg; iArg.pBt = pBt; iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL); - ret = tdbPagerFetchPage(pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); + ret = tdbPagerFetchPage(pBt->pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); if (ret < 0) { return -1; } // mark dirty - ret = tdbPagerWrite(pPager, *ppOfp); + ret = tdbPagerWrite(pBt->pPager, *ppOfp); if (ret < 0) { ASSERT(0); return -1; @@ -879,13 +879,13 @@ static int tdbFetchOvflPage(SPager *pPager, SPgno *pPgno, SPage **ppOfp, TXN *pT return ret; } -static int tdbLoadOvflPage(SPager *pPager, SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { +static int tdbLoadOvflPage(SPgno *pPgno, SPage **ppOfp, TXN *pTxn, SBTree *pBt) { int ret = 0; SBtreeInitPageArg iArg; iArg.pBt = pBt; iArg.flags = TDB_FLAG_ADD(0, TDB_BTREE_OVFL); - ret = tdbPagerFetchPage(pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); + ret = tdbPagerFetchPage(pBt->pPager, pPgno, ppOfp, tdbBtreeInitPage, &iArg, pTxn); if (ret < 0) { return -1; } @@ -922,7 +922,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const SPgno pgno = 0; SPage *ofp, *nextOfp; - ret = tdbFetchOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + ret = tdbFetchOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } @@ -962,7 +962,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const // fetch next ofp if not last page if (!lastPage) { // fetch a new ofp and make it dirty - ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt); if (ret < 0) { tdbFree(pBuf); return -1; @@ -1019,14 +1019,14 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const nLeft -= lastKeyPageSpace; // fetch next ofp, a new ofp and make it dirty - ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt); if (ret < 0) { return -1; } } } else { // fetch next ofp, a new ofp and make it dirty - ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt); if (ret < 0) { return -1; } @@ -1057,7 +1057,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const // fetch next ofp if not last page if (!lastPage) { // fetch a new ofp and make it dirty - ret = tdbFetchOvflPage(pPage->pPager, &pgno, &nextOfp, pTxn, pBt); + ret = tdbFetchOvflPage(&pgno, &nextOfp, pTxn, pBt); if (ret < 0) { tdbFree(pBuf); return -1; @@ -1198,7 +1198,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, // unpack left val data from ovpages while (pgno != 0) { - ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } @@ -1235,7 +1235,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, int lastKeyPageSpace = 0; // load left key & val to ovpages while (pgno != 0) { - ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } @@ -1280,7 +1280,7 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader, } while (nLeft > 0) { - ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } @@ -1411,7 +1411,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN * int bytes; while (pgno != 0) { - ret = tdbLoadOvflPage(pPage->pPager, &pgno, &ofp, pTxn, pBt); + ret = tdbLoadOvflPage(&pgno, &ofp, pTxn, pBt); if (ret < 0) { return -1; } @@ -2023,7 +2023,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) { // check if key <= current position if (idx < nCells) { pCell = tdbPageGetCell(pPage, idx); - tdbBtreeDecodeCell(pPage, pCell, &cd, pBtc->pTxn, pBtc->pBt); + tdbBtreeDecodeCell(pPage, pCell, &cd); c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen); if (c > 0) break; } diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 146b127422..327fe50814 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -183,6 +183,8 @@ typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } Co #define transContLenFromMsg(msgLen) (msgLen - sizeof(STransMsgHead)); #define transIsReq(type) (type & 1U) +#define transLabel(trans) ((STrans*)trans)->label + // int rpcAuthenticateMsg(void* pMsg, int msgLen, void* pAuth, void* pKey); // void rpcBuildAuthHead(void* pMsg, int msgLen, void* pAuth, void* pKey); //// int32_t rpcCompressRpcMsg(char* pCont, int32_t contLen); diff --git a/source/libs/transport/inc/transLog.h b/source/libs/transport/inc/transLog.h index 81099941c6..121939787c 100644 --- a/source/libs/transport/inc/transLog.h +++ b/source/libs/transport/inc/transLog.h @@ -32,8 +32,13 @@ extern "C" { #define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC ", DEBUG_TRACE, rpcDebugFlag, __VA_ARGS__); }} #define tDump(x, y) { if (rpcDebugFlag & DEBUG_DUMP) { taosDumpData((unsigned char *)x, y); } } -//#define tTR(param, ...) do { char buf[40] = {0};TRACE_TO_STR(trace, buf);tTrace("TRID: %s "param, buf, __VA_ARGS__);} while(0) -#define tGTrace(param, ...) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); tTrace(param ", gtid:%s", __VA_ARGS__, buf);} +#define tGTrace(param, ...) do { if (rpcDebugFlag & DEBUG_TRACE){char buf[40] = {0}; TRACE_TO_STR(trace, buf); tTrace(param ", gtid:%s", __VA_ARGS__, buf);}} while(0) +#define tGFatal(param, ...) do {if (rpcDebugFlag & DEBUG_FATAL){ char buf[40] = {0}; TRACE_TO_STR(trace, buf); tFatal(param ", gtid:%s", __VA_ARGS__, buf); }} while (0) +#define tGError(param, ...) do { if (rpcDebugFlag & DEBUG_ERROR){ char buf[40] = {0}; TRACE_TO_STR(trace, buf); tError(param ", gtid:%s", __VA_ARGS__, buf);} } while(0) +#define tGWarn(param, ...) do { if (rpcDebugFlag & DEBUG_WARN) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); tWarn(param ", gtid:%s", __VA_ARGS__, buf); }} while(0) +#define tGInfo(param, ...) do { if (rpcDebugFlag & DEBUG_INFO) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); tInfo(param ", gtid:%s", __VA_ARGS__, buf); }} while(0) +#define tGDebug(param,...) do {if (rpcDebugFlag & DEBUG_DEBUG){ char buf[40] = {0}; TRACE_TO_STR(trace, buf); tDebug(param ", gtid:%s", __VA_ARGS__, buf); }} while(0) + // clang-format on #ifdef __cplusplus diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 912c8b59c2..0dd00e0dc2 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -175,6 +175,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { #define CONN_SHOULD_RELEASE(conn, head) \ do { \ if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \ + int connStatus = conn->status; \ uint64_t ahandle = head->ahandle; \ CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \ conn->status = ConnRelease; \ @@ -186,7 +187,9 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { } \ destroyCmsg(pMsg); \ cliReleaseUnfinishedMsg(conn); \ - addConnToPool(((SCliThrdObj*)conn->hostThrd)->pool, conn); \ + if (connStatus != ConnInPool) { \ + addConnToPool(((SCliThrdObj*)conn->hostThrd)->pool, conn); \ + } \ return; \ } \ } while (0) @@ -450,7 +453,7 @@ void* destroyConnPool(void* pool) { while (connList != NULL) { while (!QUEUE_IS_EMPTY(&connList->conn)) { queue* h = QUEUE_HEAD(&connList->conn); - QUEUE_REMOVE(h); + // QUEUE_REMOVE(h); SCliConn* c = QUEUE_DATA(h, SCliConn, conn); cliDestroyConn(c, true); } @@ -476,18 +479,19 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) { if (QUEUE_IS_EMPTY(&plist->conn)) { return NULL; } - queue* h = QUEUE_HEAD(&plist->conn); - QUEUE_REMOVE(h); + queue* h = QUEUE_HEAD(&plist->conn); SCliConn* conn = QUEUE_DATA(h, SCliConn, conn); conn->status = ConnNormal; + QUEUE_REMOVE(&conn->conn); QUEUE_INIT(&conn->conn); + assert(h == &conn->conn); return conn; } static void addConnToPool(void* pool, SCliConn* conn) { SCliThrdObj* thrd = conn->hostThrd; CONN_HANDLE_THREAD_QUIT(thrd); - STrans* pTransInst = ((SCliThrdObj*)conn->hostThrd)->pTransInst; + STrans* pTransInst = thrd->pTransInst; conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); transQueueClear(&conn->cliMsgs); transCtxCleanup(&conn->ctx); @@ -500,6 +504,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key)); // list already create before assert(plist != NULL); + QUEUE_INIT(&conn->conn); QUEUE_PUSH(&plist->conn, &conn->conn); assert(!QUEUE_IS_EMPTY(&plist->conn)); } @@ -561,7 +566,6 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) { } static void cliDestroyConn(SCliConn* conn, bool clear) { tTrace("%s conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn); - QUEUE_REMOVE(&conn->conn); if (clear) { uv_close((uv_handle_t*)conn->stream, cliDestroy); @@ -778,11 +782,11 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) { int ret = transSetConnOption((uv_tcp_t*)conn->stream); if (ret) { - tError("%s conn %p failed to set conn option, errmsg %s", pTransInst->label, conn, uv_err_name(ret)); + tError("%s conn %p failed to set conn option, errmsg %s", transLabel(pTransInst), conn, uv_err_name(ret)); } int fd = taosCreateSocketWithTimeOutOpt(TRANS_CONN_TIMEOUT); if (fd == -1) { - tTrace("%s conn %p failed to create socket", pTransInst->label, conn); + tTrace("%s conn %p failed to create socket", transLabel(pTransInst), conn); cliHandleExcept(conn); return; } @@ -979,17 +983,18 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { if (pCtx->retryCount < pEpSet->numOfEps * 3) { pEpSet->inUse = (++pEpSet->inUse) % pEpSet->numOfEps; + if (pThrd->quit == false) { + STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + arg->param1 = pMsg; + arg->param2 = pThrd; + transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); + transPrintEpSet(pEpSet); + tTrace("%s use local epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse, + pCtx->retryCount + 1, pEpSet->numOfEps * 3); - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - arg->param1 = pMsg; - arg->param2 = pThrd; - transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); - transPrintEpSet(pEpSet); - tTrace("%s use local epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse, - pCtx->retryCount + 1, pEpSet->numOfEps * 3); - - transUnrefCliHandle(pConn); - return -1; + transUnrefCliHandle(pConn); + return -1; + } } } else if (pCtx->retryCount < TRANS_RETRY_COUNT_LIMIT) { if (pResp->contLen == 0) { @@ -1006,13 +1011,16 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { tTrace("%s use remote epset, inUse: %d, retry count:%d, limit: %d", pTransInst->label, pEpSet->inUse, pCtx->retryCount + 1, TRANS_RETRY_COUNT_LIMIT); } - addConnToPool(pThrd->pool, pConn); - - STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); - arg->param1 = pMsg; - arg->param2 = pThrd; - transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); - return -1; + if (pThrd->quit == false) { + if (pConn->status != ConnInPool) { + addConnToPool(pThrd->pool, pConn); + } + STaskArg* arg = taosMemoryMalloc(sizeof(STaskArg)); + arg->param1 = pMsg; + arg->param2 = pThrd; + transDQSched(pThrd->delayQueue, doDelayTask, arg, TRANS_RETRY_INTERVAL); + return -1; + } } } @@ -1110,7 +1118,7 @@ void transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[idx]; STraceId* trace = &pReq->info.traceId; - tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", pTransInst->label, thrd->pid, + tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), thrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); ASSERT(transSendAsync(thrd->asyncPool, &(cliMsg->q)) == 0); } @@ -1143,7 +1151,7 @@ void transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STransM SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[idx]; STraceId* trace = &pReq->info.traceId; - tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", pTransInst->label, thrd->pid, + tGTrace("%s send request at thread:%08" PRId64 ", dst: %s:%d, app:%p", transLabel(pTransInst), thrd->pid, EPSET_GET_INUSE_IP(&pCtx->epSet), EPSET_GET_INUSE_PORT(&pCtx->epSet), pReq->info.ahandle); transSendAsync(thrd->asyncPool, &(cliMsg->q)); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index f9558d7252..593a790a21 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -284,12 +284,12 @@ static void uvHandleReq(SSvrConn* pConn) { if (pConn->status == ConnNormal && pHead->noResp == 0) { transRefSrvHandle(pConn); - tGTrace("conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pConn, TMSG_INFO(transMsg.msgType), - taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), - ntohs(pConn->localAddr.sin_port), transMsg.contLen); - } else { - tGTrace("conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d, code: %d", pConn, + tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", transLabel(pConn), pConn, TMSG_INFO(transMsg.msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), + taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), transMsg.contLen); + } else { + tGTrace("%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d, code: %d", transLabel(pConn), + pConn, TMSG_INFO(transMsg.msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), transMsg.contLen, pHead->noResp, transMsg.code); // no ref here @@ -304,7 +304,8 @@ static void uvHandleReq(SSvrConn* pConn) { transMsg.info.refId = pConn->refId; transMsg.info.traceId = pHead->traceId; - tGTrace("handle %p conn: %p translated to app, refId: %" PRIu64 "", transMsg.info.handle, pConn, pConn->refId); + tGTrace("%s handle %p conn: %p translated to app, refId: %" PRIu64 "", transLabel(pConn), transMsg.info.handle, pConn, + pConn->refId); assert(transMsg.info.handle != NULL); if (pHead->noResp == 1) { @@ -330,12 +331,12 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { SConnBuffer* pBuf = &conn->readBuf; if (nread > 0) { pBuf->len += nread; - tTrace("conn %p total read: %d, current read: %d", conn, pBuf->len, (int)nread); + tTrace("%s conn %p total read: %d, current read: %d", transLabel(conn->pTransInst), conn, pBuf->len, (int)nread); if (transReadComplete(pBuf)) { - tTrace("conn %p alread read complete packet", conn); + tTrace("%s conn %p alread read complete packet", transLabel(conn->pTransInst), conn); uvHandleReq(conn); } else { - tTrace("conn %p read partial packet, continue to read", conn); + tTrace("%s conn %p read partial packet, continue to read", transLabel(conn->pTransInst), conn); } return; } @@ -343,12 +344,12 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) { return; } - tError("conn %p read error: %s", conn, uv_err_name(nread)); + tError("%s conn %p read error: %s", transLabel(conn->pTransInst), conn, uv_err_name(nread)); if (nread < 0) { conn->broken = true; if (conn->status == ConnAcquire) { if (conn->regArg.init) { - tTrace("conn %p broken, notify server app", conn); + tTrace("%s conn %p broken, notify server app", transLabel(conn->pTransInst), conn); STrans* pTransInst = conn->pTransInst; (*pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); memset(&conn->regArg, 0, sizeof(conn->regArg)); @@ -457,9 +458,9 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { int32_t len = transMsgLenFromCont(pMsg->contLen); STraceId* trace = &pMsg->info.traceId; - tGTrace("conn %p %s is sent to %s:%d, local info: %s:%d, msglen:%d", pConn, TMSG_INFO(pHead->msgType), - taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->localAddr.sin_addr), - ntohs(pConn->localAddr.sin_port), len); + tGTrace("%s conn %p %s is sent to %s:%d, local info: %s:%d, msglen:%d", transLabel(pConn->pTransInst), pConn, + TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), + taosInetNtoa(pConn->localAddr.sin_addr), ntohs(pConn->localAddr.sin_port), len); pHead->msgLen = htonl(len); wb->base = msg; @@ -737,7 +738,7 @@ static bool addHandleToWorkloop(SWorkThrdObj* pThrd, char* pipeName) { // conn set QUEUE_INIT(&pThrd->conn); - pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, uvWorkerAsyncCb); + pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 1, pThrd, uvWorkerAsyncCb); uv_pipe_connect(&pThrd->connect_req, pThrd->pipe, pipeName, uvOnPipeConnectionCb); // uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); return true; @@ -801,7 +802,7 @@ static SSvrConn* createConn(void* hThrd) { pConn->refId = exh->refId; transRefSrvHandle(pConn); - tTrace("handle %p, conn %p created, refId: %" PRId64 "", exh, pConn, pConn->refId); + tTrace("%s handle %p, conn %p created, refId: %" PRId64 "", transLabel(pThrd->pTransInst), exh, pConn, pConn->refId); return pConn; } @@ -848,7 +849,7 @@ static void uvDestroyConn(uv_handle_t* handle) { transReleaseExHandle(refMgt, conn->refId); transRemoveExHandle(refMgt, conn->refId); - tDebug("conn %p destroy", conn); + tDebug("%s conn %p destroy", transLabel(thrd->pTransInst), conn); // uv_timer_stop(&conn->pTimer); transQueueDestroy(&conn->srvMsgs); @@ -977,18 +978,18 @@ void uvHandleRelease(SSvrMsg* msg, SWorkThrdObj* thrd) { uvStartSendRespInternal(msg); return; } else if (conn->status == ConnRelease || conn->status == ConnNormal) { - tDebug("conn %p already released, ignore release-msg", conn); + tDebug("%s conn %p already released, ignore release-msg", transLabel(thrd->pTransInst), conn); } destroySmsg(msg); } void uvHandleResp(SSvrMsg* msg, SWorkThrdObj* thrd) { // send msg to client - tDebug("conn %p start to send resp (2/2)", msg->pConn); + tDebug("%s conn %p start to send resp (2/2)", transLabel(thrd->pTransInst), msg->pConn); uvStartSendResp(msg); } void uvHandleRegister(SSvrMsg* msg, SWorkThrdObj* thrd) { SSvrConn* conn = msg->pConn; - tDebug("conn %p register brokenlink callback", conn); + tDebug("%s conn %p register brokenlink callback", transLabel(thrd->pTransInst), conn); if (conn->status == ConnAcquire) { if (!transQueuePush(&conn->srvMsgs, msg)) { return; @@ -1094,7 +1095,7 @@ void transReleaseSrvHandle(void* handle) { m->msg = tmsg; m->type = Release; - tTrace("conn %p start to release", exh->handle); + tTrace("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle); transSendAsync(pThrd->asyncPool, &m->q); transReleaseExHandle(refMgt, refId); return; @@ -1152,7 +1153,7 @@ void transRegisterMsg(const STransMsg* msg) { m->msg = tmsg; m->type = Register; - tTrace("conn %p start to register brokenlink callback", exh->handle); + tTrace("%s conn %p start to register brokenlink callback", transLabel(pThrd->pTransInst), exh->handle); transSendAsync(pThrd->asyncPool, &m->q); transReleaseExHandle(refMgt, refId); return; diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 8e9cb3a84b..4150fe6d1b 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -19,6 +19,8 @@ #include "tref.h" #include "walInt.h" +bool FORCE_INLINE walIsEmpty(SWal* pWal) { return pWal->vers.firstVer == -1; } + int64_t FORCE_INLINE walGetFirstVer(SWal* pWal) { return pWal->vers.firstVer; } int64_t FORCE_INLINE walGetSnaphostVer(SWal* pWal) { return pWal->vers.snapshotVer; } diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index b1129b441c..682afbb785 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -100,7 +100,6 @@ static int32_t walReadChangeFile(SWalReadHandle *pRead, int64_t fileFirstVer) { TdFilePtr pLogTFile = taosOpenFile(fnameStr, TD_FILE_READ); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - terrno = TSDB_CODE_WAL_INVALID_VER; wError("cannot open file %s, since %s", fnameStr, terrstr()); return -1; } @@ -273,14 +272,23 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { } } + if (ver > pRead->pWal->vers.lastVer || ver < pRead->pWal->vers.firstVer) { + wError("invalid version: % " PRId64 ", first ver %ld, last ver %ld", ver, pRead->pWal->vers.firstVer, + pRead->pWal->vers.lastVer); + terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; + return -1; + } + ASSERT(taosValidFile(pRead->pReadLogTFile) == true); code = taosReadFile(pRead->pReadLogTFile, pRead->pHead, sizeof(SWalHead)); if (code != sizeof(SWalHead)) { if (code < 0) terrno = TAOS_SYSTEM_ERROR(errno); - else + else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + ASSERT(0); + } return -1; } @@ -305,8 +313,10 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { pRead->pHead->head.bodyLen) { if (code < 0) terrno = TAOS_SYSTEM_ERROR(errno); - else + else { terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + ASSERT(0); + } return -1; } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 9cbc9a3b02..f82f27e3af 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -141,7 +141,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // validate offset SWalHead head; ASSERT(taosValidFile(pLogTFile)); - int size = taosReadFile(pLogTFile, &head, sizeof(SWalHead)); + int64_t size = taosReadFile(pLogTFile, &head, sizeof(SWalHead)); if (size != sizeof(SWalHead)) { return -1; } @@ -149,24 +149,40 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ASSERT(code == 0); if (code != 0) { + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + ASSERT(0); return -1; } if (head.head.version != ver) { - // TODO + ASSERT(0); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } + // truncate old files code = taosFtruncateFile(pLogTFile, entry.offset); if (code < 0) { + ASSERT(0); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } code = taosFtruncateFile(pIdxTFile, idxOff); if (code < 0) { + ASSERT(0); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } pWal->vers.lastVer = ver - 1; + if (pWal->vers.lastVer < pWal->vers.firstVer) { + ASSERT(pWal->vers.lastVer == pWal->vers.firstVer - 1); + pWal->vers.firstVer = -1; + } ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset; + if (((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer < ver - 1) { + ASSERT(((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize == 0); + ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->firstVer = -1; + } taosCloseFile(&pIdxTFile); taosCloseFile(&pLogTFile); @@ -384,8 +400,12 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog } // set status + if (pWal->vers.firstVer == -1) pWal->vers.firstVer = index; pWal->vers.lastVer = index; pWal->totSize += sizeof(SWalHead) + bodyLen; + if (walGetCurFileInfo(pWal)->firstVer == -1) { + walGetCurFileInfo(pWal)->firstVer = index; + } walGetCurFileInfo(pWal)->lastVer = index; walGetCurFileInfo(pWal)->fileSize += sizeof(SWalHead) + bodyLen; diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index d2369ea2a2..c2d10f3668 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -88,11 +88,11 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) { void taosGetSystemLocale(char *outLocale, char *outCharset) { #ifdef WINDOWS - char *locale = setlocale(LC_CTYPE, "chs"); + char *locale = setlocale(LC_CTYPE, "en_US.UTF-8"); if (locale != NULL) { tstrncpy(outLocale, locale, TD_LOCALE_LEN); } - strcpy(outCharset, "cp936"); + strcpy(outCharset, "UTF-8"); #elif defined(_TD_DARWIN_64) /* diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 11d7d9831a..db1207f057 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -503,6 +503,38 @@ const char *cfgDtypeStr(ECfgDataType type) { } } +void cfgDumpItemValue(SConfigItem *pItem, char* buf, int32_t bufSize, int32_t* pLen) { + int32_t len = 0; + switch (pItem->dtype) { + case CFG_DTYPE_BOOL: + len = snprintf(buf, bufSize, "%u", pItem->bval); + break; + case CFG_DTYPE_INT32: + len = snprintf(buf, bufSize, "%d", pItem->i32); + break; + case CFG_DTYPE_INT64: + len = snprintf(buf, bufSize, "%" PRId64, pItem->i64); + break; + case CFG_DTYPE_FLOAT: + len = snprintf(buf, bufSize, "%f", pItem->fval); + break; + case CFG_DTYPE_STRING: + case CFG_DTYPE_DIR: + case CFG_DTYPE_LOCALE: + case CFG_DTYPE_CHARSET: + case CFG_DTYPE_TIMEZONE: + case CFG_DTYPE_NONE: + len = snprintf(buf, bufSize, "%s", pItem->str); + break; + } + + if (len > bufSize) { + len = bufSize; + } + + *pLen = len; +} + void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { if (dump) { printf(" global config"); @@ -996,4 +1028,4 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl uInfo("fail get apollo url from cmd env file"); return -1; -} \ No newline at end of file +} diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b89e908df7..fa10fc26dd 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -76,6 +76,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_NEED_RETRY, "Retry needed") TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE, "Out of memory in rpc queue") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIMESTAMP, "Invalid timestamp format") TAOS_DEFINE_ERROR(TSDB_CODE_MSG_DECODE_ERROR, "Msg decode error") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_AVAIL_DISK, "No available disk") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") @@ -356,7 +357,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM, "No table data in memo TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_ALREADY_EXISTS, "File already exists") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_RECONFIGURE, "Need to reconfigure table") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO, "Invalid information to create table") -TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_AVAIL_DISK, "No available disk") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_AVAIL_DISK, "TSDB no available disk") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_MESSED_MSG, "TSDB messed message") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVLD_TAG_VAL, "TSDB invalid tag value") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_CACHE_LAST_ROW, "TSDB no cache last row data") diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 353e94a490..0439ed148b 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -743,7 +743,7 @@ cmp_end: } void taosSetAllDebugFlag(int32_t flag) { - if (!(flag & DEBUG_TRACE || flag & DEBUG_DEBUG || flag & DEBUG_DUMP)) return; + if (flag <= 0) return; dDebugFlag = flag; vDebugFlag = flag; diff --git a/tests/pytest/util/cluster.py b/tests/pytest/util/cluster.py new file mode 100644 index 0000000000..6eb78f0771 --- /dev/null +++ b/tests/pytest/util/cluster.py @@ -0,0 +1,92 @@ +from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE +import taos +import sys +import time +import os +import socket + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * + +class ClusterDnodes(TDDnodes): + """rewrite TDDnodes and make MyDdnodes as TDDnodes child class""" + def __init__(self ,dnodes_lists): + + super(ClusterDnodes,self).__init__() + self.dnodes = dnodes_lists # dnode must be TDDnode instance + self.simDeployed = False + self.testCluster = False + self.valgrind = 0 + self.killValgrind = 1 + + +class ConfigureyCluster: + """This will create defined number of dnodes and create a cluset. + at the same time, it will return TDDnodes list: dnodes, """ + hostname= socket.gethostname() + + def __init__(self): + self.dnodes = [] + self.dnodeNums = 5 + self.independent = True + self.startPort = 6030 + self.portStep = 100 + self.mnodeNums = 0 + + def configure_cluster(self ,dnodeNums=5,mnodeNums=0,startPort=6030,portStep=100,hostname="%s"%hostname): + self.startPort=int(startPort) + self.portStep=int(portStep) + self.hostname=hostname + self.dnodeNums = int(dnodeNums) + self.mnodeNums = int(mnodeNums) + self.dnodes = [] + startPort_sec = int(startPort+portStep) + for num in range(1, (self.dnodeNums+1)): + dnode = TDDnode(num) + dnode.addExtraCfg("firstEp", f"{hostname}:{self.startPort}") + dnode.addExtraCfg("fqdn", f"{hostname}") + dnode.addExtraCfg("serverPort", f"{self.startPort + (num-1)*self.portStep}") + dnode.addExtraCfg("secondEp", f"{hostname}:{startPort_sec}") + + # configure dnoe of independent mnodes + if num <= self.mnodeNums and self.mnodeNums != 0 : + dnode.addExtraCfg("supportVnodes", 0) + # print(dnode) + self.dnodes.append(dnode) + return self.dnodes + + def create_dnode(self,conn): + tdSql.init(conn.cursor()) + for dnode in self.dnodes[1:]: + # print(dnode.cfgDict) + dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] + tdSql.execute(" create dnode '%s';"%dnode_id) + + + + def check_dnode(self,conn): + tdSql.init(conn.cursor()) + count=0 + while count < 5: + tdSql.query("show dnodes") + # tdLog.debug(tdSql.queryResult) + status=0 + for i in range(self.dnodeNums): + if tdSql.queryResult[i][4] == "ready": + status+=1 + # tdLog.debug(status) + + if status == self.dnodeNums: + tdLog.debug(" create cluster with %d dnode and check cluster dnode all ready within 5s! " %self.dnodeNums) + break + count+=1 + time.sleep(1) + else: + tdLog.debug("create cluster with %d dnode but check dnode not ready within 5s ! "%self.dnodeNums) + return -1 + + +cluster = ConfigureyCluster() \ No newline at end of file diff --git a/tests/script/general/parser/udf.sim b/tests/script/general/parser/udf.sim index c048a7c37a..4b767dbf60 100644 --- a/tests/script/general/parser/udf.sim +++ b/tests/script/general/parser/udf.sim @@ -44,6 +44,7 @@ endi sql create function n02 as '/tmp/normal' outputtype bool; sql show functions; if $rows != 1 then + print expect 1, actual $rows return -1 endi diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index dbfd05146c..cc28b19de9 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -12,6 +12,8 @@ ## ---- db ./test.sh -f tsim/db/create_all_options.sim ./test.sh -f tsim/db/alter_option.sim +./test.sh -f tsim/db/alter_replica_13.sim +#./test.sh -f tsim/db/alter_replica_31.sim ./test.sh -f tsim/db/basic1.sim ./test.sh -f tsim/db/basic2.sim ./test.sh -f tsim/db/basic3.sim @@ -21,8 +23,16 @@ ./test.sh -f tsim/db/taosdlog.sim # ---- dnode +./test.sh -f tsim/dnode/balance_replica1.sim ./test.sh -f tsim/dnode/create_dnode.sim ./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim +./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim +./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica1.sim +#./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica3.sim +#./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim +#./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim +#./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim +./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim # ---- insert ./test.sh -f tsim/insert/basic0.sim @@ -99,6 +109,7 @@ ./test.sh -f tsim/tmq/basic4Of2Cons.sim ./test.sh -f tsim/tmq/basic2Of2ConsOverlap.sim ./test.sh -f tsim/tmq/topic.sim +./test.sh -f tsim/tmq/snapshot.sim # --- stable ./test.sh -f tsim/stable/disk.sim diff --git a/tests/script/tmp/monitor.sim b/tests/script/tmp/monitor.sim index ba98bec2d0..036d4cc6db 100644 --- a/tests/script/tmp/monitor.sim +++ b/tests/script/tmp/monitor.sim @@ -12,6 +12,8 @@ sql connect print =============== show dnodes sleep 2000 sql create database db vgroups 2; +sql use db; +sql create table db.stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 binary(16)) comment "abd"; sleep 2000 print =============== create drop qnode 1 diff --git a/tests/script/tsim/dnode/balance_replica1.sim b/tests/script/tsim/dnode/balance_replica1.sim new file mode 100644 index 0000000000..14f3f130fb --- /dev/null +++ b/tests/script/tsim/dnode/balance_replica1.sim @@ -0,0 +1,123 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sql connect + +print =============== step1 create dnode2 +# no enough vnodes +sql balance vgroup + +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ---> dnode not online! + return -1 + endi +sql show dnodes +print ---> $data00 $data01 $data02 $data03 $data04 $data05 +print ---> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != offline then + goto step1 +endi + +print =============== step2 create database +sql create database d1 vgroups 2 +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql create table d1.c2 using st tags(1) +sql create table d1.c3 using st tags(1) +sql create table d1.c4 using st tags(1) +sql create table d1.c5 using st tags(1) +sql create table d1.c6 using st tags(1) +sql show d1.tables +if $rows != 6 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 2 then + return -1 +endi +if $data(2)[3] != 2 then + return -1 +endi +if $data(3)[3] != 2 then + return -1 +endi + +print =============== step3: balance vgroup +# has offline dnode +sql_error balance vgroup + +system sh/exec.sh -n dnode3 -s start +$x = 0 +step3: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ---> dnode not online! + return -1 + endi +sql show dnodes +print ---> $data00 $data01 $data02 $data03 $data04 $data05 +print ---> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step3 +endi +if $data(2)[4] != ready then + goto step3 +endi +if $data(3)[4] != ready then + goto step3 +endi + +print =============== step4: balance +sql balance vgroup + +print show d1.vgroups +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 2 then + return -1 +endi +if $data(2)[3] != 3 then + return -1 +endi +if $data(3)[3] != 2 then + return -1 +endi + +print =============== step7: select data +sql show d1.tables +print rows $rows +if $rows != 6 then + return -1 +endi + +return +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/drop_dnode_has_mnode.sim b/tests/script/tsim/dnode/drop_dnode_has_mnode.sim index 1dbec2c04d..16cd2bb3b0 100644 --- a/tests/script/tsim/dnode/drop_dnode_has_mnode.sim +++ b/tests/script/tsim/dnode/drop_dnode_has_mnode.sim @@ -70,6 +70,7 @@ if $data(2)[2] != follower then endi print =============== step4: drop dnode 2 +sql_error drop dnode 1 sql drop dnode 2 print show dnodes; @@ -83,7 +84,7 @@ if $data00 != 1 then return -1 endi -print show dnodes; +print show mnodes; sql show mnodes print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] diff --git a/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim b/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim new file mode 100644 index 0000000000..15ad13b6fa --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim @@ -0,0 +1,135 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sql connect + +print =============== step1 create dnode2 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != offline then + goto step1 +endi + +print =============== step2 create database +sql create database d1 vgroups 4 +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql show d1.tables +if $rows != 1 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 4 then + return -1 +endi +if $data(2)[3] != 2 then + return -1 +endi +if $data(3)[3] != 2 then + return -1 +endi +if $data(4)[3] != 2 then + return -1 +endi +if $data(5)[3] != 2 then + return -1 +endi + +print =============== step3: start dnode 3 +system sh/exec.sh -n dnode3 -s start +$x = 0 +step4: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step4 +endi +if $data(2)[4] != ready then + goto step4 +endi +if $data(3)[4] != ready then + goto step4 +endi + +print =============== step3: drop dnode2 +sql drop dnode 2 + +print show dnodes; +sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 2 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 4 then + return -1 +endi +if $data(2)[3] != 3 then + return -1 +endi +if $data(3)[3] != 3 then + return -1 +endi +if $data(4)[3] != 3 then + return -1 +endi +if $data(5)[3] != 3 then + return -1 +endi + +print =============== step4: select data +sql show d1.tables +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim b/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim new file mode 100644 index 0000000000..35a2466297 --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim @@ -0,0 +1,135 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql connect + +print =============== step1 create dnode2 dnode3 dnode4 dnode 5 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 +sql create dnode $hostname port 7500 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != ready then + goto step1 +endi +if $data(4)[4] != ready then + goto step1 +endi +if $data(5)[4] != offline then + goto step1 +endi + +print =============== step3 create database +sql create database d1 vgroups 4 replica 3 +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql show d1.tables +if $rows != 1 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi +if $data(2)[3] != 2 then + return -1 +endi +if $data(2)[5] != 3 then + return -1 +endi +if $data(2)[7] != 4 then + return -1 +endi + +print =============== step4: drop dnode 2 +system sh/exec.sh -n dnode5 -s start +$x = 0 +step4: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step4 +endi +if $data(2)[4] != ready then + goto step4 +endi +if $data(3)[4] != ready then + goto step4 +endi +if $data(4)[4] != ready then + goto step4 +endi +if $data(5)[4] != ready then + goto step4 +endi + +print =============== step5: drop dnode2 +sql drop dnode 2 + +print show dnodes; +sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 4 then + return -1 +endi + +print show d1.vgroups +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi + + +print =============== step6: select data +sql show d1.tables +if $rows != 1 then + return -1 +endi + +return +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/drop_dnode_has_qnode_snode.sim b/tests/script/tsim/dnode/drop_dnode_has_qnode_snode.sim new file mode 100644 index 0000000000..6641ce053c --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_has_qnode_snode.sim @@ -0,0 +1,71 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sql connect + +print =============== step1 create dnode2 +sql create dnode $hostname port 7200 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi + +print =============== step2: create qnode snode on dnode 2 +sql create qnode on dnode 2 +sql create snode on dnode 2 + +sql show qnodes +if $rows != 1 then + return -1 +endi + +sql show snodes +if $rows != 1 then + return -1 +endi + +print =============== step3: drop dnode 2 +sql drop dnode 2 + +print show dnodes; +sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 1 then + return -1 +endi +if $data00 != 1 then + return -1 +endi + +sql show qnodes +if $rows != 0 then + return -1 +endi + +sql show snodes +if $rows != 0 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/drop_dnode_has_vnode_replica1.sim b/tests/script/tsim/dnode/drop_dnode_has_vnode_replica1.sim new file mode 100644 index 0000000000..63639877ee --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_has_vnode_replica1.sim @@ -0,0 +1,151 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sql connect + +print =============== step1 create dnode2 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != offline then + goto step1 +endi + +print =============== step2 drop dnode which not exist +sql_error drop dnode 1 +sql_error drop dnode 4 + +print =============== step3 create database +sql create database d1 vgroups 1 +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql show d1.tables +if $rows != 1 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi +if $data(2)[3] != 2 then + return -1 +endi + +print =============== step4: drop dnode 2 +print cant drop since no enough vnodes +sql_error drop dnode 2 + +system sh/exec.sh -n dnode2 -s stop +system sh/exec.sh -n dnode3 -s start +$x = 0 +step4: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step4 +endi +if $data(2)[4] != offline then + goto step4 +endi +if $data(3)[4] != ready then + goto step4 +endi + +# cant drop since offline +sql_error drop dnode 2 + +print =============== step5: start dnode2 +system sh/exec.sh -n dnode2 -s start + +$x = 0 +step5: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step5 +endi +if $data(2)[4] != ready then + goto step5 +endi +if $data(3)[4] != ready then + goto step5 +endi + +print =============== step6: drop dnode2 +sql drop dnode 2 + +print show dnodes; +sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 2 then + return -1 +endi + +print show d1.vgroups +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi +if $data(2)[3] != 3 then + return -1 +endi + +print =============== step7: select data +sql show d1.tables +if $rows != 1 then + return -1 +endi + +return +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim b/tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim new file mode 100644 index 0000000000..3ea351f7a7 --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim @@ -0,0 +1,144 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql connect + +print =============== step1 create dnode2 dnode3 dnode4 dnode 5 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 +sql create dnode $hostname port 7500 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 5 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != ready then + goto step1 +endi +if $data(4)[4] != ready then + goto step1 +endi +if $data(5)[4] != offline then + goto step1 +endi + +print =============== step3 create database +sql create database d1 vgroups 1 replica 3 +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql show d1.tables +if $rows != 1 then + return -1 +endi + +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi +if $data(2)[3] != 2 then + return -1 +endi +if $data(2)[5] != 3 then + return -1 +endi +if $data(2)[7] != 4 then + return -1 +endi + +system sh/exec.sh -n dnode4 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT + + +return + + +print =============== step4: drop dnode 2 +system sh/exec.sh -n dnode5 -s start +$x = 0 +step4: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step4 +endi +if $data(2)[4] != ready then + goto step4 +endi +if $data(3)[4] != ready then + goto step4 +endi +if $data(4)[4] != ready then + goto step4 +endi +if $data(5)[4] != ready then + goto step4 +endi + +print =============== step5: drop dnode2 +sql drop dnode 2 + +print show dnodes; +sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 4 then + return -1 +endi + +print show d1.vgroups +sql show d1.vgroups +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +if $rows != 1 then + return -1 +endi +#if $data(2)[3] != 3 then +# return -1 +#endi + +print =============== step6: select data +sql show d1.tables +if $rows != 1 then + return -1 +endi + +return +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim index 3532332174..9b11e16616 100644 --- a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim +++ b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim @@ -112,7 +112,7 @@ if $data(5)[4] != ready then goto step2 endi -print =============== step31: move follower +print =============== step3: create database $leaderExist = 0 $leaderVnode = 0 $follower1 = 0 @@ -165,7 +165,7 @@ if $rows != 1 then return -1 endi -print =============== step32: move follower2 +print =============== step31: print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql show d1.vgroups @@ -176,7 +176,9 @@ if $rows != 1 then return -1 endi -print =============== step33: move follower1 +return + +print =============== step32: print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql show d1.vgroups @@ -187,7 +189,7 @@ if $rows != 1 then return -1 endi -print =============== step34: move follower2 +print =============== step33: print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql show d1.vgroups @@ -198,7 +200,7 @@ if $rows != 1 then return -1 endi -print =============== step35: move follower1 +print =============== step34: print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 sql show d1.vgroups @@ -209,9 +211,9 @@ if $rows != 1 then return -1 endi -print =============== step36: move follower2 -print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 -sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 +print =============== step34: +print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode $follower1 +sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode $follower1 sql show d1.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 @@ -220,7 +222,7 @@ if $rows != 1 then return -1 endi -print =============== step37: move follower1 +print =============== step36: print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql show d1.vgroups @@ -231,7 +233,7 @@ if $rows != 1 then return -1 endi -print =============== step38: move follower2 +print =============== step37: print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql show d1.vgroups @@ -242,7 +244,7 @@ if $rows != 1 then return -1 endi -print =============== step39: move follower1 +print =============== step38: print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1 sql show d1.vgroups @@ -253,6 +255,17 @@ if $rows != 1 then return -1 endi +print =============== step39: +print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode $follower2 +sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode $follower2 +sql show d1.vgroups +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 + +sql show d1.tables +if $rows != 1 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim index e9dd82cad9..947482b3d4 100644 --- a/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim +++ b/tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim @@ -91,7 +91,7 @@ if $data(5)[4] != ready then goto step2 endi -print =============== step31: move follower +print =============== step3: create database $leaderExist = 0 $leaderVnode = 0 $follower1 = 0 @@ -144,7 +144,7 @@ if $rows != 1 then return -1 endi -print =============== step32: move leader +print =============== step40: move leader print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5 sql redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5 sql show d1.vgroups @@ -155,9 +155,7 @@ if $rows != 1 then return -1 endi -return - -print =============== step33: move follower1 +print =============== step41: print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql show d1.vgroups @@ -168,7 +166,7 @@ if $rows != 1 then return -1 endi -print =============== step34: move follower2 +print =============== step42: print redistribute vgroup 2 dnode $follower1 dnode 5 dnode $leaderVnode sql redistribute vgroup 2 dnode $follower1 dnode 5 dnode $leaderVnode sql show d1.vgroups @@ -179,7 +177,18 @@ if $rows != 1 then return -1 endi -print =============== step35: move leader +print =============== step43: +print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode $leaderVnode +sql redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode $leaderVnode +sql show d1.vgroups +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 + +sql show d1.tables +if $rows != 1 then + return -1 +endi + +print =============== step44: print redistribute vgroup 2 dnode $follower2 dnode 5 dnode $follower1 sql redistribute vgroup 2 dnode $follower2 dnode 5 dnode $follower1 sql show d1.vgroups @@ -190,7 +199,7 @@ if $rows != 1 then return -1 endi -print =============== step36: move follower1 +print =============== step45: print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5 sql show d1.vgroups @@ -201,7 +210,7 @@ if $rows != 1 then return -1 endi -print =============== step37: move follower2 +print =============== step46: print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5 sql show d1.vgroups @@ -212,7 +221,7 @@ if $rows != 1 then return -1 endi -print =============== step38: move leader +print =============== step47: print redistribute vgroup 2 dnode $follower1 dnode 5 dnode $follower2 sql redistribute vgroup 2 dnode $follower1 dnode 5 dnode $follower2 sql show d1.vgroups @@ -223,7 +232,18 @@ if $rows != 1 then return -1 endi -print =============== step39: move follower1 +print =============== step48: +print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 +sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 +sql show d1.vgroups +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 + +sql show d1.tables +if $rows != 1 then + return -1 +endi + +print =============== step49: print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2 sql show d1.vgroups diff --git a/tests/script/tsim/query/udf.sim b/tests/script/tsim/query/udf.sim index d9821a0495..4e95095172 100644 --- a/tests/script/tsim/query/udf.sim +++ b/tests/script/tsim/query/udf.sim @@ -44,6 +44,7 @@ endi sql select udf2(f) from t; if $rows != 1 then + print expect 1, actual $rows return -1 endi if $data00 != 2.236067977 then diff --git a/tests/script/tsim/show/basic.sim b/tests/script/tsim/show/basic.sim index 94ca2f6550..4d646f39e3 100644 --- a/tests/script/tsim/show/basic.sim +++ b/tests/script/tsim/show/basic.sim @@ -99,7 +99,7 @@ if $rows != 1 then endi #sql select * from information_schema.`streams` sql select * from information_schema.user_tables -if $rows != 30 then +if $rows != 31 then return -1 endi #sql select * from information_schema.user_table_distributed @@ -197,7 +197,7 @@ if $rows != 1 then endi #sql select * from performance_schema.`streams` sql select * from information_schema.user_tables -if $rows != 30 then +if $rows != 31 then return -1 endi #sql select * from information_schema.user_table_distributed @@ -227,5 +227,20 @@ endi sql_error show create stable t0; +sql show variables; +if $rows != 4 then + return -1 +endi + +sql show dnode 1 variables; +if $rows <= 0 then + return -1 +endi + +sql show local variables; +if $rows <= 0 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/consume.sh b/tests/script/tsim/tmq/consume.sh index 3fa71d6edd..001ce6ae49 100755 --- a/tests/script/tsim/tmq/consume.sh +++ b/tests/script/tsim/tmq/consume.sh @@ -17,8 +17,9 @@ VALGRIND=0 SIGNAL=SIGINT SHOW_MSG=0 SHOW_ROW=0 +EXP_USE_SNAPSHOT=0 -while getopts "d:s:v:y:x:g:r:w:" arg +while getopts "d:s:v:y:x:g:r:w:e:" arg do case $arg in d) @@ -45,6 +46,9 @@ do w) CDB_NAME=$OPTARG ;; + e) + EXP_USE_SNAPSHOT=$OPTARG + ;; ?) echo "unkown argument" ;; @@ -91,8 +95,8 @@ if [ "$EXEC_OPTON" = "start" ]; then echo nohup valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tmq_sim.log $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW > /dev/null 2>&1 & nohup valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tmq_sim.log $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW > /dev/null 2>&1 & else - echo "nohup $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW -w $CDB_NAME > /dev/null 2>&1 &" - nohup $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW -w $CDB_NAME > /dev/null 2>&1 & + echo "nohup $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW -w $CDB_NAME -e $EXP_USE_SNAPSHOT > /dev/null 2>&1 &" + nohup $PROGRAM -c $CFG_DIR -y $POLL_DELAY -d $DB_NAME -g $SHOW_MSG -r $SHOW_ROW -w $CDB_NAME -e $EXP_USE_SNAPSHOT > /dev/null 2>&1 & fi else PID=`ps -ef|grep tmq_sim | grep -v grep | awk '{print $2}'` diff --git a/tests/script/tsim/tmq/snapshot.sim b/tests/script/tsim/tmq/snapshot.sim new file mode 100644 index 0000000000..5683aaa559 --- /dev/null +++ b/tests/script/tsim/tmq/snapshot.sim @@ -0,0 +1,289 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +#basic1.sim: vgroups=1, one topic for one consumer, firstly insert data, then start consume. Include six topics +#basic2.sim: vgroups=1, multi topics for one consumer, firstly insert data, then start consume. Include six topics +#basic3.sim: vgroups=4, one topic for one consumer, firstly insert data, then start consume. Include six topics +#basic4.sim: vgroups=4, multi topics for one consumer, firstly insert data, then start consume. Include six topics + +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# + +run tsim/tmq/prepareBasicEnv-1vgrp.sim + +#---- global parameters start ----# +$dbName = db +$vgroups = 1 +$stbPrefix = stb +$ctbPrefix = ctb +$ntbPrefix = ntb +$stbNum = 1 +$ctbNum = 10 +$ntbNum = 10 +$rowsPerCtb = 10 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +#---- global parameters end ----# + +$pullDelay = 3 +$ifcheckdata = 1 +$ifmanualcommit = 1 +$showMsg = 1 +$showRow = 0 + +sql connect +sql use $dbName + +print == create topics from super table +sql create topic topic_stb_column as select ts, c3 from stb +sql create topic topic_stb_all as select ts, c1, c2, c3 from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +print == create topics from child table +sql create topic topic_ctb_column as select ts, c3 from ctb0 +sql create topic topic_ctb_all as select * from ctb0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ctb0 + +print == create topics from normal table +sql create topic topic_ntb_column as select ts, c3 from ntb0 +sql create topic topic_ntb_all as select * from ntb0 +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb0 + +#sql show topics +#if $rows != 9 then +# return -1 +#endi + +#'group.id:cgrp1,enable.auto.commit:false,auto.commit.interval.ms:6000,auto.offset.reset:earliest' +$keyList = ' . group.id:cgrp1 +$keyList = $keyList . , +$keyList = $keyList . enable.auto.commit:false +#$keyList = $keyList . , +#$keyList = $keyList . auto.commit.interval.ms:6000 +#$keyList = $keyList . , +#$keyList = $keyList . auto.offset.reset:earliest +$keyList = $keyList . ' +print ========== key list: $keyList + + +$cdb_index = 0 +#=============================== start consume =============================# + +print ================ test consume from stb +$loop_cnt = 0 +loop_consume_diff_topic_from_stb: + +####################################################################################### +# clear consume info and consume result +#run tsim/tmq/clearConsume.sim +# because drop table function no stable, so by create new db for consume info and result. Modify it later +$cdb_index = $cdb_index + 1 +$cdbName = cdb . $cdb_index +sql create database $cdbName vgroups 1 +sleep 500 +sql use $cdbName + +print == create consume info table and consume result table +sql create table consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int) +sql create table consumeresult (ts timestamp, consumerid int, consummsgcnt bigint, consumrowcnt bigint, checkresult int) + +sql show tables +if $rows != 2 then + return -1 +endi +####################################################################################### + +if $loop_cnt == 0 then + print == scenario 1: topic_stb_column + $topicList = ' . topic_stb_column + $topicList = $topicList . ' +elif $loop_cnt == 1 then + print == scenario 2: topic_stb_all + $topicList = ' . topic_stb_all + $topicList = $topicList . ' +elif $loop_cnt == 2 then + print == scenario 3: topic_stb_function + $topicList = ' . topic_stb_function + $topicList = $topicList . ' +else + goto loop_consume_diff_topic_from_stb_end +endi + +$consumerId = 0 +$totalMsgOfStb = $ctbNum * $rowsPerCtb +$expectmsgcnt = 1 +$expectrowcnt = 100 +sql insert into consumeinfo values (now , $consumerId , $topicList , $keyList , $expectmsgcnt , $ifcheckdata , $ifmanualcommit ) + +print == start consumer to pull msgs from stb +print == tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -w $cdbName -e 1 -s start +system tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -w $cdbName -e 1 -s start + +print == check consume result +wait_consumer_end_from_stb: +sql select * from consumeresult +print ==> rows: $rows +print ==> rows[0]: $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +if $rows != 1 then + sleep 1000 + goto wait_consumer_end_from_stb +endi +if $data[0][1] != $consumerId then + return -1 +endi +if $data[0][2] != $expectmsgcnt then + return -1 +endi +if $data[0][3] != $expectrowcnt then + return -1 +endi +$loop_cnt = $loop_cnt + 1 +goto loop_consume_diff_topic_from_stb +loop_consume_diff_topic_from_stb_end: + +print ================ test consume from ctb +$loop_cnt = 0 +loop_consume_diff_topic_from_ctb: + +####################################################################################### +# clear consume info and consume result +#run tsim/tmq/clearConsume.sim +# because drop table function no stable, so by create new db for consume info and result. Modify it later +$cdb_index = $cdb_index + 1 +$cdbName = cdb . $cdb_index +sql create database $cdbName vgroups 1 +sleep 500 +sql use $cdbName + +print == create consume info table and consume result table +sql create table consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int) +sql create table consumeresult (ts timestamp, consumerid int, consummsgcnt bigint, consumrowcnt bigint, checkresult int) + +sql show tables +if $rows != 2 then + return -1 +endi +####################################################################################### + +if $loop_cnt == 0 then + print == scenario 1: topic_ctb_column + $topicList = ' . topic_ctb_column + $topicList = $topicList . ' +elif $loop_cnt == 1 then + print == scenario 2: topic_ctb_all + $topicList = ' . topic_ctb_all + $topicList = $topicList . ' +elif $loop_cnt == 2 then + print == scenario 3: topic_ctb_function + $topicList = ' . topic_ctb_function + $topicList = $topicList . ' +else + goto loop_consume_diff_topic_from_ctb_end +endi + +$consumerId = 0 +$totalMsgOfCtb = $rowsPerCtb +$expectmsgcnt = 1 +sql insert into consumeinfo values (now , $consumerId , $topicList , $keyList , $expectmsgcnt , $ifcheckdata , $ifmanualcommit ) + +print == start consumer to pull msgs from ctb +print == tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -s start -e 1 +system tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -w $cdbName -s start -e 1 + +print == check consume result +wait_consumer_end_from_ctb: +sql select * from consumeresult +print ==> rows: $rows +print ==> rows[0]: $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +if $rows != 1 then + sleep 1000 + goto wait_consumer_end_from_ctb +endi +if $data[0][1] != $consumerId then + return -1 +endi +if $data[0][2] != 1 then + return -1 +endi +if $data[0][3] != 10 then + return -1 +endi +$loop_cnt = $loop_cnt + 1 +goto loop_consume_diff_topic_from_ctb +loop_consume_diff_topic_from_ctb_end: + +print ================ test consume from ntb +$loop_cnt = 0 +loop_consume_diff_topic_from_ntb: + +####################################################################################### +# clear consume info and consume result +#run tsim/tmq/clearConsume.sim +# because drop table function no stable, so by create new db for consume info and result. Modify it later +$cdb_index = $cdb_index + 1 +$cdbName = cdb . $cdb_index +sql create database $cdbName vgroups 1 +sleep 500 +sql use $cdbName + +print == create consume info table and consume result table +sql create table consumeinfo (ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int, ifmanualcommit int) +sql create table consumeresult (ts timestamp, consumerid int, consummsgcnt bigint, consumrowcnt bigint, checkresult int) + +sql show tables +if $rows != 2 then + return -1 +endi +####################################################################################### + +if $loop_cnt == 0 then + print == scenario 1: topic_ntb_column + $topicList = ' . topic_ntb_column + $topicList = $topicList . ' +elif $loop_cnt == 1 then + print == scenario 2: topic_ntb_all + $topicList = ' . topic_ntb_all + $topicList = $topicList . ' +elif $loop_cnt == 2 then + print == scenario 3: topic_ntb_function + $topicList = ' . topic_ntb_function + $topicList = $topicList . ' +else + goto loop_consume_diff_topic_from_ntb_end +endi + +$consumerId = 0 +$totalMsgOfNtb = $rowsPerCtb +$expectmsgcnt = $totalMsgOfNtb +sql insert into consumeinfo values (now , $consumerId , $topicList , $keyList , $expectmsgcnt , $ifcheckdata , $ifmanualcommit ) + +print == start consumer to pull msgs from ntb +print == tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -s start -e 1 +system tsim/tmq/consume.sh -d $dbName -y $pullDelay -g $showMsg -r $showRow -w $cdbName -s start -e 1 + +print == check consume result from ntb +wait_consumer_end_from_ntb: +sql select * from consumeresult +print ==> rows: $rows +print ==> rows[0]: $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +if $rows != 1 then + sleep 1000 + goto wait_consumer_end_from_ntb +endi +if $data[0][1] != $consumerId then + return -1 +endi +if $data[0][2] != 1 then + return -1 +endi +if $data[0][3] != $totalMsgOfNtb then + return -1 +endi +$loop_cnt = $loop_cnt + 1 +goto loop_consume_diff_topic_from_ntb +loop_consume_diff_topic_from_ntb_end: + +#------ not need stop consumer, because it exit after pull msg overthan expect msg +#system tsim/tmq/consume.sh -s stop -x SIGINT + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/wtest.bat b/tests/script/wtest.bat index 1aa27202c6..1f089c9d86 100644 --- a/tests/script/wtest.bat +++ b/tests/script/wtest.bat @@ -52,7 +52,7 @@ echo wal 0 >> %TAOS_CFG% echo asyncLog 0 >> %TAOS_CFG% echo locale en_US.UTF-8 >> %TAOS_CFG% echo enableCoreFile 1 >> %TAOS_CFG% -echo charset cp65001 >> %TAOS_CFG% +echo charset UTF-8 >> %TAOS_CFG% set "FILE_NAME=testSuite.sim" if "%1" == "-f" set "FILE_NAME=%2" diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index d779cc26cd..244cccb041 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -6,15 +6,63 @@ import inspect from util.log import * from util.sql import * from util.cases import * +import random + class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143} + updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, + "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, + "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "fnDebugFlag": 143} + def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), True) + self.tb_nums = 10 + self.row_nums = 20 + self.ts = 1434938400000 + self.time_step = 1000 + + def insert_datas_and_check_abs(self ,tbnums , rownums , time_step ): + tdLog.info(" prepare datas for auto check abs function ") + + tdSql.execute(" create database test ") + tdSql.execute(" use test ") + tdSql.execute(" create stable stb (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ + c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)") + for tbnum in range(tbnums): + tbname = "sub_tb_%d"%tbnum + tdSql.execute(" create table %s using stb tags(%d) "%(tbname , tbnum)) + + ts = self.ts + for row in range(rownums): + ts += time_step*row + c1 = random.randint(0,10000) + c2 = random.randint(0,100000) + c3 = random.randint(0,125) + c4 = random.randint(0,125) + c5 = random.random()/1.0 + c6 = random.random()/1.0 + c7 = "'true'" + c8 = "'binary_val'" + c9 = "'nchar_val'" + c10 = ts + tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") + + tdSql.execute("use test") + tbnames = ["stb", "sub_tb_1"] + support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] + for tbname in tbnames: + tdSql.query("desc {}".format(tbname)) + coltypes = tdSql.queryResult + for coltype in coltypes: + colname = coltype[0] + abs_sql = "select abs({}) from {} order by tbname ".format(colname, tbname) + origin_sql = "select {} from {} order by tbname".format(colname, tbname) + if coltype[1] in support_types: + self.check_result_auto(origin_sql , abs_sql) + + def prepare_datas(self): tdSql.execute( '''create table stb1 @@ -22,7 +70,7 @@ class TDTestCase: tags (t1 int) ''' ) - + tdSql.execute( ''' create table t1 @@ -39,14 +87,21 @@ class TDTestCase: tdSql.execute( f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute( + "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( f'''insert into t1 values @@ -64,11 +119,11 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - def prepare_tag_datas(self): - # prepare datas - tdSql.execute("create database if not exists testdb keep 3650 duration 1000") + # prepare datas + tdSql.execute( + "create database if not exists testdb keep 3650 duration 1000") tdSql.execute(" use testdb ") tdSql.execute( '''create table stb1 @@ -84,7 +139,8 @@ class TDTestCase: ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + tdSql.execute( + f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( @@ -93,14 +149,21 @@ class TDTestCase: tdSql.execute( f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute( + "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute( + "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute( + "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( f'''insert into t1 values @@ -119,18 +182,18 @@ class TDTestCase: ''' ) - def check_result_auto(self ,origin_query , abs_query): + def check_result_auto(self, origin_query, abs_query): abs_result = tdSql.getResult(abs_query) origin_result = tdSql.getResult(origin_query) - auto_result =[] - + auto_result = [] + for row in origin_result: row_check = [] for elem in row: if elem == None: elem = None - elif elem >=0: + elif elem >= 0: elem = elem else: elem = -elem @@ -138,21 +201,23 @@ class TDTestCase: auto_result.append(row_check) check_status = True - for row_index , row in enumerate(abs_result): - for col_index , elem in enumerate(row): + for row_index, row in enumerate(abs_result): + for col_index, elem in enumerate(row): if auto_result[row_index][col_index] != elem: - check_status = False + check_status = False if not check_status: - tdLog.notice("abs function value has not as expected , sql is \"%s\" "%abs_query ) + tdLog.notice( + "abs function value has not as expected , sql is \"%s\" " % abs_query) sys.exit(1) else: - tdLog.info("abs value check pass , it work as expected ,sql is \"%s\" "%abs_query ) - + tdLog.info( + "abs value check pass , it work as expected ,sql is \"%s\" " % abs_query) + def test_errors(self): tdSql.execute("use testdb") error_sql_lists = [ "select abs from t1", - # "select abs(-+--+c1) from t1", + "select abs(-+--+c1) from t1", # "select +-abs(c1) from t1", # "select ++-abs(c1) from t1", # "select ++--abs(c1) from t1", @@ -182,93 +247,25 @@ class TDTestCase: ] for error_sql in error_sql_lists: tdSql.error(error_sql) - + def support_types(self): tdSql.execute("use testdb") - type_error_sql_lists = [ - "select abs(ts) from t1" , - "select abs(t0) from t1" , - "select abs(c7) from t1", - "select abs(c8) from t1", - "select abs(c9) from t1", - "select abs(t7) from t1", - "select abs(t8) from t1", - "select abs(t9) from t1", - "select abs(ts) from ct1" , - "select abs(c7) from ct1", - "select abs(c8) from ct1", - "select abs(c9) from ct1", - "select abs(ts) from ct3" , - "select abs(c7) from ct3", - "select abs(c8) from ct3", - "select abs(c9) from ct3", - "select abs(ts) from ct4" , - "select abs(c7) from ct4", - "select abs(c8) from ct4", - "select abs(c9) from ct4", - "select abs(ts) from stb1" , - "select abs(c7) from stb1", - "select abs(c8) from stb1", - "select abs(c9) from stb1" , + tbnames = ["stb1", "t1", "ct1", "ct2"] + support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] + for tbname in tbnames: + tdSql.query("desc {}".format(tbname)) + coltypes = tdSql.queryResult + for coltype in coltypes: + colname = coltype[0] + abs_sql = "select abs({}) from {}".format(colname, tbname) + if coltype[1] in support_types: + tdSql.query(abs_sql) + else: + tdSql.error(abs_sql) - "select abs(ts) from stbbb1" , - "select abs(c7) from stbbb1", - - "select abs(ts) from tbname", - "select abs(c9) from tbname" - - ] - - for type_sql in type_error_sql_lists: - tdSql.error(type_sql) - - - type_sql_lists = [ - "select abs(c1) from t1", - "select abs(c2) from t1", - "select abs(c3) from t1", - "select abs(c4) from t1", - "select abs(c5) from t1", - "select abs(c6) from t1", - - "select abs(t1) from ct1", - "select abs(t2) from ct1", - "select abs(t3) from ct1", - "select abs(t4) from ct1", - "select abs(t5) from ct1", - "select abs(t6) from ct1", - - "select abs(c1) from ct1", - "select abs(c2) from ct1", - "select abs(c3) from ct1", - "select abs(c4) from ct1", - "select abs(c5) from ct1", - "select abs(c6) from ct1", - - "select abs(c1) from ct3", - "select abs(c2) from ct3", - "select abs(c3) from ct3", - "select abs(c4) from ct3", - "select abs(c5) from ct3", - "select abs(c6) from ct3", - - "select abs(c1) from stb1", - "select abs(c2) from stb1", - "select abs(c3) from stb1", - "select abs(c4) from stb1", - "select abs(c5) from stb1", - "select abs(c6) from stb1", - - "select abs(c6) as alisb from stb1", - "select abs(c6) alisb from stb1", - ] - - for type_sql in type_sql_lists: - tdSql.query(type_sql) - def basic_abs_function(self): - # basic query + # basic query tdSql.query("select c1 from ct3") tdSql.checkRows(0) tdSql.query("select c1 from t1") @@ -288,13 +285,13 @@ class TDTestCase: tdSql.query("select abs(c5) from ct3") tdSql.checkRows(0) tdSql.query("select abs(c6) from ct3") - + # used for regular table tdSql.query("select abs(c1) from t1") tdSql.checkData(0, 0, None) - tdSql.checkData(1 , 0, 1) - tdSql.checkData(3 , 0, 3) - tdSql.checkData(5 , 0, None) + tdSql.checkData(1, 0, 1) + tdSql.checkData(3, 0, 3) + tdSql.checkData(5, 0, None) tdSql.query("select c1, c2, c3 , c4, c5 from t1") tdSql.checkData(1, 4, 1.11000) @@ -305,62 +302,66 @@ class TDTestCase: tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from t1") - + self.check_result_auto("select c1, c2, c3 , c4, c5 from t1", + "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from t1") + # used for sub table tdSql.query("select abs(c1) from ct1") tdSql.checkData(0, 0, 8) - tdSql.checkData(1 , 0, 7) - tdSql.checkData(3 , 0, 5) - tdSql.checkData(5 , 0, 4) + tdSql.checkData(1, 0, 7) + tdSql.checkData(3, 0, 5) + tdSql.checkData(5, 0, 4) tdSql.query("select abs(c1) from ct1") - self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct1") - self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) + self.check_result_auto("select c1, c2, c3 , c4, c5 from ct1", + "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct1") + self.check_result_auto( + "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct1;", "select c1 from ct1") + + # used for stable table - # used for stable table - tdSql.query("select abs(c1) from stb1") tdSql.checkRows(25) - self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct4") - self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) - + self.check_result_auto("select c1, c2, c3 , c4, c5 from ct4 ", + "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct4") + self.check_result_auto( + "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct4;", "select c1 from ct4") # used for not exists table tdSql.error("select abs(c1) from stbbb1") tdSql.error("select abs(c1) from tbname") tdSql.error("select abs(c1) from ct5") - # mix with common col + # mix with common col tdSql.query("select c1, abs(c1) from ct1") - tdSql.checkData(0 , 0 ,8) - tdSql.checkData(0 , 1 ,8) - tdSql.checkData(4 , 0 ,0) - tdSql.checkData(4 , 1 ,0) + tdSql.checkData(0, 0, 8) + tdSql.checkData(0, 1, 8) + tdSql.checkData(4, 0, 0) + tdSql.checkData(4, 1, 0) tdSql.query("select c1, abs(c1) from ct4") - tdSql.checkData(0 , 0 , None) - tdSql.checkData(0 , 1 ,None) - tdSql.checkData(4 , 0 ,5) - tdSql.checkData(4 , 1 ,5) - tdSql.checkData(5 , 0 ,None) - tdSql.checkData(5 , 1 ,None) + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(4, 0, 5) + tdSql.checkData(4, 1, 5) + tdSql.checkData(5, 0, None) + tdSql.checkData(5, 1, None) tdSql.query("select c1, abs(c1) from ct4 ") - tdSql.checkData(0 , 0 ,None) - tdSql.checkData(0 , 1 ,None) - tdSql.checkData(4 , 0 ,5) - tdSql.checkData(4 , 1 ,5) + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(4, 0, 5) + tdSql.checkData(4, 1, 5) # mix with common functions tdSql.query("select c1, abs(c1),c5, floor(c5) from ct4 ") - tdSql.checkData(0 , 0 ,None) - tdSql.checkData(0 , 1 ,None) - tdSql.checkData(0 , 2 ,None) - tdSql.checkData(0 , 3 ,None) - - tdSql.checkData(3 , 0 , 6) - tdSql.checkData(3 , 1 , 6) - tdSql.checkData(3 , 2 ,6.66000) - tdSql.checkData(3 , 3 ,6.00000) + tdSql.checkData(0, 0, None) + tdSql.checkData(0, 1, None) + tdSql.checkData(0, 2, None) + tdSql.checkData(0, 3, None) + + tdSql.checkData(3, 0, 6) + tdSql.checkData(3, 1, 6) + tdSql.checkData(3, 2, 6.66000) + tdSql.checkData(3, 3, 6.00000) tdSql.query("select c1, abs(c1),c5, floor(c5) from stb1 ") @@ -377,18 +378,17 @@ class TDTestCase: tdSql.query("select max(c5), count(c5) from stb1") tdSql.query("select max(c5), count(c5) from ct1") - # bug fix for count tdSql.query("select count(c1) from ct4 ") - tdSql.checkData(0,0,9) + tdSql.checkData(0, 0, 9) tdSql.query("select count(*) from ct4 ") - tdSql.checkData(0,0,12) + tdSql.checkData(0, 0, 12) tdSql.query("select count(c1) from stb1 ") - tdSql.checkData(0,0,22) + tdSql.checkData(0, 0, 22) tdSql.query("select count(*) from stb1 ") - tdSql.checkData(0,0,25) + tdSql.checkData(0, 0, 25) - # bug fix for compute + # bug fix for compute tdSql.query("select c1, abs(c1) -0 ,ceil(c1)-0 from ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) @@ -405,47 +405,48 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 7.900000000) - - def abs_func_filter(self): tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + tdSql.query( + "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") tdSql.checkRows(3) - tdSql.checkData(0,0,8) - tdSql.checkData(0,1,8.000000000) - tdSql.checkData(0,2,8.000000000) - tdSql.checkData(0,3,7.900000000) - tdSql.checkData(0,4,3.000000000) + tdSql.checkData(0, 0, 8) + tdSql.checkData(0, 1, 8.000000000) + tdSql.checkData(0, 2, 8.000000000) + tdSql.checkData(0, 3, 7.900000000) + tdSql.checkData(0, 4, 3.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.query( + "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") tdSql.checkRows(1) - tdSql.checkData(0,0,5) - tdSql.checkData(0,1,5.000000000) - tdSql.checkData(0,2,5.000000000) - tdSql.checkData(0,3,4.900000000) - tdSql.checkData(0,4,2.000000000) + tdSql.checkData(0, 0, 5) + tdSql.checkData(0, 1, 5.000000000) + tdSql.checkData(0, 2, 5.000000000) + tdSql.checkData(0, 3, 4.900000000) + tdSql.checkData(0, 4, 2.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.query( + "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") tdSql.checkRows(1) - tdSql.checkData(0,0,5) - tdSql.checkData(0,1,5.000000000) - tdSql.checkData(0,2,5.000000000) - tdSql.checkData(0,3,4.900000000) - tdSql.checkData(0,4,2.000000000) + tdSql.checkData(0, 0, 5) + tdSql.checkData(0, 1, 5.000000000) + tdSql.checkData(0, 2, 5.000000000) + tdSql.checkData(0, 3, 4.900000000) + tdSql.checkData(0, 4, 2.000000000) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.query( + "select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") tdSql.checkRows(1) - tdSql.checkData(0,0,8) - tdSql.checkData(0,1,88888) - tdSql.checkData(0,2,8.000000000) - tdSql.checkData(0,3,8.000000000) - tdSql.checkData(0,4,7.900000000) - tdSql.checkData(0,5,3.000000000) - + tdSql.checkData(0, 0, 8) + tdSql.checkData(0, 1, 88888) + tdSql.checkData(0, 2, 8.000000000) + tdSql.checkData(0, 3, 8.000000000) + tdSql.checkData(0, 4, 7.900000000) + tdSql.checkData(0, 5, 3.000000000) def abs_Arithmetic(self): pass - + def check_boundary_values(self): tdSql.execute("drop database if exists bound_test") @@ -457,74 +458,84 @@ class TDTestCase: ) tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) + f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) + f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) + f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) + f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" - ) - self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select abs(c1), abs(c2) ,abs(c3), abs(c4), abs(c5) ,abs(c6) from sub1_bound") - self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select abs(c1), abs(c2) ,abs(c3), abs(c3), abs(c2) ,abs(c1) from sub1_bound") - self.check_result_auto("select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from sub1_bound;" , "select abs(c1) from sub1_bound" ) - + f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + ) + self.check_result_auto("select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", + "select abs(c1), abs(c2) ,abs(c3), abs(c4), abs(c5) ,abs(c6) from sub1_bound") + self.check_result_auto("select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", + "select abs(c1), abs(c2) ,abs(c3), abs(c3), abs(c2) ,abs(c1) from sub1_bound") + self.check_result_auto( + "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from sub1_bound;", "select abs(c1) from sub1_bound") + # check basic elem for table per row - tdSql.query("select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") - tdSql.checkData(0,0,2147483647) - tdSql.checkData(0,1,9223372036854775807) - tdSql.checkData(0,2,32767) - tdSql.checkData(0,3,127) - tdSql.checkData(0,4,339999995214436424907732413799364296704.00000) - tdSql.checkData(0,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) - tdSql.checkData(1,0,2147483647) - tdSql.checkData(1,1,9223372036854775807) - tdSql.checkData(1,2,32767) - tdSql.checkData(1,3,127) - tdSql.checkData(1,4,339999995214436424907732413799364296704.00000) - tdSql.checkData(1,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) - tdSql.checkData(3,0,2147483646) - tdSql.checkData(3,1,9223372036854775806) - tdSql.checkData(3,2,32766) - tdSql.checkData(3,3,126) - tdSql.checkData(3,4,339999995214436424907732413799364296704.00000) - tdSql.checkData(3,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.query( + "select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") + tdSql.checkData(0, 0, 2147483647) + tdSql.checkData(0, 1, 9223372036854775807) + tdSql.checkData(0, 2, 32767) + tdSql.checkData(0, 3, 127) + tdSql.checkData(0, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(1, 0, 2147483647) + tdSql.checkData(1, 1, 9223372036854775807) + tdSql.checkData(1, 2, 32767) + tdSql.checkData(1, 3, 127) + tdSql.checkData(1, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(1, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(3, 0, 2147483646) + tdSql.checkData(3, 1, 9223372036854775806) + tdSql.checkData(3, 2, 32766) + tdSql.checkData(3, 3, 126) + tdSql.checkData(3, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(3, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) # check + - * / in functions - tdSql.query("select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") - tdSql.checkData(0,0,2147483648.000000000) - tdSql.checkData(0,1,9223372036854775807) - tdSql.checkData(0,2,32767.000000000) - tdSql.checkData(0,3,63.500000000) - tdSql.checkData(0,4,169999997607218212453866206899682148352.000000000) - tdSql.checkData(0,5,169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) - - - tdSql.checkData(1,0,2147483646.000000000) - tdSql.checkData(1,1,9223372036854775808.000000000) - tdSql.checkData(1,2,32767.000000000) - tdSql.checkData(1,3,63.500000000) - tdSql.checkData(1,4,169999997607218212453866206899682148352.000000000) + tdSql.query( + "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + tdSql.checkData(0, 0, 2147483648.000000000) + tdSql.checkData(0, 1, 9223372036854775807) + tdSql.checkData(0, 2, 32767.000000000) + tdSql.checkData(0, 3, 63.500000000) + tdSql.checkData( + 0, 4, 169999997607218212453866206899682148352.000000000) + tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + + tdSql.checkData(1, 0, 2147483646.000000000) + tdSql.checkData(1, 1, 9223372036854775808.000000000) + tdSql.checkData(1, 2, 32767.000000000) + tdSql.checkData(1, 3, 63.500000000) + tdSql.checkData( + 1, 4, 169999997607218212453866206899682148352.000000000) + + self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound", + "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") - self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound" ,"select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") - def test_tag_compute_for_scalar_function(self): - + tdSql.execute("use testdb") - self.check_result_auto( "select c1, t2, t3 , t4, t5 from ct4 ", "select (c1), abs(t2) ,abs(t3), abs(t4), abs(t5) from ct4") - self.check_result_auto( "select c1+2, t2+2, t3 , t4, t5 from ct4 ", "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from ct4") - self.check_result_auto( "select c1+2, t2+2, t3 , t4, t5 from stb1 order by t1 ", "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from stb1 order by t1") + self.check_result_auto("select c1, t2, t3 , t4, t5 from ct4 ", + "select (c1), abs(t2) ,abs(t3), abs(t4), abs(t5) from ct4") + self.check_result_auto("select c1+2, t2+2, t3 , t4, t5 from ct4 ", + "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from ct4") + self.check_result_auto("select c1+2, t2+2, t3 , t4, t5 from stb1 order by t1 ", + "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from stb1 order by t1") - # bug need fix + # bug need fix - # tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") # taosd crash + # tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") # taosd crash tdSql.query("select c1 ,t1 from stb1 where t1 =0 ") tdSql.checkRows(13) # tdSql.query("select t1 from stb1 where t1 >0 ") @@ -532,7 +543,7 @@ class TDTestCase: # tdSql.query("select sum(t1) from (select c1 ,t1 from stb1)") # tdSql.checkData(0,0,61) # tdSql.query("select distinct(c1) ,t1 from stb1") - # tdSql.checkRows(11) + # tdSql.checkRows(20) # tdSql.query("select max(t2) , t1 ,c1, t2 from stb1") # tdSql.checkData(0,3,33333) @@ -543,45 +554,49 @@ class TDTestCase: tdSql.checkRows(1) # tdSql.query("select t1 from stb1 where abs(t1+c1)=1") # tdSql.checkRows(1) - tdSql.query("select abs(c1+t1)*t1 from stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") - - + tdSql.query( + "select abs(c1+t1)*t1 from stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() self.prepare_tag_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: abs basic query ============") + tdLog.printNoPrefix("==========step4: abs basic query ============") self.basic_abs_function() - tdLog.printNoPrefix("==========step5: abs boundary query ============") + tdLog.printNoPrefix("==========step5: abs boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step6: abs filter query ============") + tdLog.printNoPrefix("==========step6: abs filter query ============") self.abs_func_filter() - tdLog.printNoPrefix("==========step6: tag coumpute query ============") - + tdLog.printNoPrefix("==========step6: tag coumpute query ============") + self.test_tag_compute_for_scalar_function() + tdLog.printNoPrefix("==========step7: check result of query ============") + + self.insert_datas_and_check_abs(self.tb_nums,self.row_nums,self.time_step) + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") + tdCases.addLinux(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/json_tag.py b/tests/system-test/2-query/json_tag.py index 957e916e34..0c649f2008 100644 --- a/tests/system-test/2-query/json_tag.py +++ b/tests/system-test/2-query/json_tag.py @@ -68,7 +68,7 @@ class TDTestCase: tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"fe\"}')") - # + # test invalidate json key, key must can be printed assic char tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')") @@ -79,7 +79,7 @@ class TDTestCase: # test invalidate json value, value number can not be inf,nan TD-12166 tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":1.8e308}')") tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":-1.8e308}')") - # + #test length limit char1= ''.join(['abcd']*64) char3= ''.join(['abcd']*1021) @@ -87,15 +87,15 @@ class TDTestCase: tdSql.error("CREATE TABLE if not exists jsons1_15 using jsons1 tags('{\"%s1\":5}')" % char1) # len(key)=257 tdSql.execute("CREATE TABLE if not exists jsons1_15 using jsons1 tags('{\"%s\":5}')" % char1) # len(key)=256 tdSql.error("CREATE TABLE if not exists jsons1_16 using jsons1 tags('{\"TSSSS\":\"%s\"}')" % char3) # len(object)=4096 - #tdSql.execute("CREATE TABLE if not exists jsons1_16 using jsons1 tags('{\"TSSS\":\"%s\"}')" % char3) # len(object)=4095 + tdSql.execute("CREATE TABLE if not exists jsons1_16 using jsons1 tags('{\"TSSS\":\"%s\"}')" % char3) # len(object)=4095 tdSql.execute("drop table if exists jsons1_15") tdSql.execute("drop table if exists jsons1_16") - # + print("============== STEP 2 ===== alter table json tag") tdSql.error("ALTER STABLE jsons1 add tag tag2 nchar(20)") tdSql.error("ALTER STABLE jsons1 drop tag jtag") tdSql.error("ALTER TABLE jsons1 MODIFY TAG jtag nchar(128)") - # + tdSql.execute("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'") tdSql.query("select jtag from jsons1_1") tdSql.checkData(0, 0, '{"tag1":"femail","tag2":35,"tag3":true}') @@ -105,9 +105,9 @@ class TDTestCase: tdSql.execute("create table st(ts timestamp, i int) tags(t int)") tdSql.error("ALTER STABLE st add tag jtag json") tdSql.error("ALTER STABLE st add column jtag json") - # - # print("============== STEP 3 ===== query table") - # # test error syntax + + print("============== STEP 3 ===== query table") + # test error syntax tdSql.error("select * from jsons1 where jtag->tag1='beijing'") tdSql.error("select -> from jsons1") tdSql.error("select * from jsons1 where contains") @@ -115,17 +115,17 @@ class TDTestCase: tdSql.error("select jtag->location from jsons1") tdSql.error("select jtag contains location from jsons1") tdSql.error("select * from jsons1 where jtag contains location") - #tdSql.error("select * from jsons1 where jtag contains''") + tdSql.query("select * from jsons1 where jtag contains''") tdSql.error("select * from jsons1 where jtag contains 'location'='beijing'") - # - # # test function error + + # test function error tdSql.error("select avg(jtag->'tag1') from jsons1") tdSql.error("select avg(jtag) from jsons1") tdSql.error("select min(jtag->'tag1') from jsons1") tdSql.error("select min(jtag) from jsons1") tdSql.error("select ceil(jtag->'tag1') from jsons1") tdSql.error("select ceil(jtag) from jsons1") - # + #test scalar operation tdSql.query("select jtag contains 'tag1',jtag->'tag1' from jsons1 order by jtag->'tag1'") @@ -158,10 +158,11 @@ class TDTestCase: tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, False) tdSql.checkData(7, 0, "false") - tdSql.checkData(7, 1, True) + tdSql.checkData(7, 1, False) + tdSql.checkData(8, 1, False) tdSql.checkData(12, 1, True) - # # test select normal column + # test select normal column tdSql.query("select dataint from jsons1 order by dataint") tdSql.checkRows(9) tdSql.checkData(1, 0, 1) @@ -180,7 +181,7 @@ class TDTestCase: tdSql.query("select jtag from jsons1_9") tdSql.checkData(0, 0, None) - # # test select json tag->'key', value is string + # test select json tag->'key', value is string tdSql.query("select jtag->'tag1' from jsons1_1") tdSql.checkData(0, 0, '"femail"') tdSql.query("select jtag->'tag2' from jsons1_6") @@ -200,7 +201,7 @@ class TDTestCase: # test select json tag->'key', key is not exist tdSql.query("select jtag->'tag10' from jsons1_4") tdSql.checkData(0, 0, None) - # + tdSql.query("select jtag->'tag1' from jsons1") tdSql.checkRows(13) # test header name @@ -210,24 +211,25 @@ class TDTestCase: tdSql.checkColNameList(res, cname_list) - # # test where with json tag + # test where with json tag tdSql.query("select * from jsons1_1 where jtag is not null") - # tdSql.error("select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'") - # tdSql.error("select * from jsons1 where jtag->'tag1'={}") - # - # # where json value is string + # tdSql.query("select * from jsons1 where jtag='{\"tag1\":11,\"tag2\":\"\"}'") + tdSql.error("select * from jsons1 where jtag->'tag1'={}") + + # where json value is string tdSql.query("select * from jsons1 where jtag->'tag2'='beijing'") tdSql.checkRows(2) - tdSql.query("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing'") + tdSql.query("select dataint,tbname,jtag->'tag1',jtag from jsons1 where jtag->'tag2'='beijing' order by dataint") tdSql.checkRows(2) - # out of order, cannot compare value - #tdSql.checkData(0, 0, 2) - #tdSql.checkData(0, 1, 'jsons1_2') - #tdSql.checkData(0, 2, 5) - #tdSql.checkData(0, 3, '{"tag1":5,"tag2":"beijing"}') - #tdSql.checkData(1, 0, 3) - #tdSql.checkData(1, 1, 'jsons1_3') - #tdSql.checkData(1, 2, 'false') + tdSql.checkData(0, 0, 2) + tdSql.checkData(0, 1, 'jsons1_2') + tdSql.checkData(0, 2, "5.000000000") + tdSql.checkData(0, 3, '{"tag1":5,"tag2":"beijing"}') + tdSql.checkData(1, 0, 3) + tdSql.checkData(1, 1, 'jsons1_3') + tdSql.checkData(1, 2, 'false') + + tdSql.query("select * from jsons1 where jtag->'tag1'='beijing'") tdSql.checkRows(0) tdSql.query("select * from jsons1 where jtag->'tag1'='收到货'") @@ -236,72 +238,73 @@ class TDTestCase: tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag2'>='beijing'") tdSql.checkRows(3) - # open - #tdSql.query("select * from jsons1 where jtag->'tag2'<'beijing'") - #tdSql.checkRows(2) - tdSql.query("select * from jsons1 where jtag->'tag2'<='beijing'") + tdSql.query("select * from jsons1 where jtag->'tag2'<'beijing'") tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag2'<='beijing'") + tdSql.checkRows(4) tdSql.query("select * from jsons1 where jtag->'tag2'!='beijing'") - tdSql.checkRows(5) + tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag2'=''") tdSql.checkRows(2) - # - # # where json value is int + + # where json value is int tdSql.query("select * from jsons1 where jtag->'tag1'=5") tdSql.checkRows(1) tdSql.checkData(0, 1, 2) tdSql.query("select * from jsons1 where jtag->'tag1'=10") tdSql.checkRows(0) tdSql.query("select * from jsons1 where jtag->'tag1'<54") - tdSql.checkRows(4) + tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1'<=11") - tdSql.checkRows(4) + tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1'>4") tdSql.checkRows(2) tdSql.query("select * from jsons1 where jtag->'tag1'>=5") tdSql.checkRows(2) tdSql.query("select * from jsons1 where jtag->'tag1'!=5") - tdSql.checkRows(6) + tdSql.checkRows(2) tdSql.query("select * from jsons1 where jtag->'tag1'!=55") - tdSql.checkRows(7) - # - # # where json value is double + tdSql.checkRows(3) + + # where json value is double tdSql.query("select * from jsons1 where jtag->'tag1'=1.232") tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag1'<1.232") - tdSql.checkRows(1) + tdSql.checkRows(0) tdSql.query("select * from jsons1 where jtag->'tag1'<=1.232") - tdSql.checkRows(2) + tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag1'>1.23") tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1'>=1.232") tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1'!=1.232") - tdSql.checkRows(6) + tdSql.checkRows(2) tdSql.query("select * from jsons1 where jtag->'tag1'!=3.232") - tdSql.checkRows(7) - #tdSql.error("select * from jsons1 where jtag->'tag1'/0=3") - #tdSql.error("select * from jsons1 where jtag->'tag1'/5=1") - # - # # where json value is bool + tdSql.checkRows(3) + tdSql.query("select * from jsons1 where jtag->'tag1'/0=3") + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'/5=1") + tdSql.checkRows(1) + + # where json value is bool tdSql.query("select * from jsons1 where jtag->'tag1'=true") tdSql.checkRows(0) - #tdSql.query("select * from jsons1 where jtag->'tag1'=false") - #tdSql.checkRows(1) + tdSql.query("select * from jsons1 where jtag->'tag1'=false") + tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag1'!=false") - tdSql.checkRows(3) - #tdSql.error("select * from jsons1 where jtag->'tag1'>false") - # - # # where json value is null - # open - #tdSql.query("select * from jsons1 where jtag->'tag1'=null") # only json suport =null. This synatx will change later. - #tdSql.checkRows(1) - # - # # where json key is null + tdSql.checkRows(0) + tdSql.query("select * from jsons1 where jtag->'tag1'>false") + tdSql.checkRows(0) + + # where json value is null + tdSql.query("select * from jsons1 where jtag->'tag1'=null") + tdSql.checkRows(0) + + # where json key is null tdSql.query("select * from jsons1 where jtag->'tag_no_exist'=3") tdSql.checkRows(0) - # - # # where json value is not exist + + # where json value is not exist tdSql.query("select * from jsons1 where jtag->'tag1' is null") tdSql.checkData(0, 0, 'jsons1_9') tdSql.checkRows(2) @@ -309,16 +312,16 @@ class TDTestCase: tdSql.checkRows(9) tdSql.query("select * from jsons1 where jtag->'tag3' is not null") tdSql.checkRows(3) - # - # # test contains + + # test contains tdSql.query("select * from jsons1 where jtag contains 'tag1'") - tdSql.checkRows(7) + tdSql.checkRows(8) tdSql.query("select * from jsons1 where jtag contains 'tag3'") - tdSql.checkRows(3) + tdSql.checkRows(4) tdSql.query("select * from jsons1 where jtag contains 'tag_no_exist'") tdSql.checkRows(0) - # - # # test json tag in where condition with and/or + + # test json tag in where condition with and/or tdSql.query("select * from jsons1 where jtag->'tag1'=false and jtag->'tag2'='beijing'") tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag1'=false or jtag->'tag2'='beijing'") @@ -335,15 +338,15 @@ class TDTestCase: tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'") tdSql.checkRows(2) - # - # - # # test with between and + + + # test with between and tdSql.query("select * from jsons1 where jtag->'tag1' between 1 and 30") tdSql.checkRows(3) tdSql.query("select * from jsons1 where jtag->'tag1' between 'femail' and 'beijing'") tdSql.checkRows(2) - # - # # test with tbname/normal column + + # test with tbname/normal column tdSql.query("select * from jsons1 where tbname = 'jsons1_1'") tdSql.checkRows(2) tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'") @@ -352,20 +355,18 @@ class TDTestCase: tdSql.checkRows(0) tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23") tdSql.checkRows(1) - # - # - # # test where condition like - # open - # syntax error - #tdSql.query("select *,tbname from jsons1 where jtag->'tag2' like 'bei%'") - #tdSql.checkRows(2) - #tdSql.query("select *,tbname from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null") - #tdSql.checkRows(2) - # - # # test where condition in no support in + + + # test where condition like + tdSql.query("select * from jsons1 where jtag->'tag2' like 'bei%'") + tdSql.checkRows(2) + tdSql.query("select * from jsons1 where jtag->'tag1' like 'fe%' and jtag->'tag2' is not null") + tdSql.checkRows(2) + + # test where condition in no support in # tdSql.error("select * from jsons1 where jtag->'tag1' in ('beijing')") - # - # # test where condition match/nmath + + # test where condition match/nmath tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma'") tdSql.checkRows(2) tdSql.query("select * from jsons1 where jtag->'tag1' match 'ma$'") @@ -376,23 +377,22 @@ class TDTestCase: tdSql.checkRows(1) tdSql.query("select * from jsons1 where jtag->'tag1' nmatch 'ma'") tdSql.checkRows(1) - # - # # test distinct + + # test distinct tdSql.execute("insert into jsons1_14 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":null}') values(1591062628000, 2, NULL, '你就会', 'dws')") tdSql.query("select distinct jtag->'tag1' from jsons1") tdSql.checkRows(8) tdSql.query("select distinct jtag from jsons1") tdSql.checkRows(9) - # - # #test dumplicate key with normal colomn + + #test dumplicate key with normal colomn tdSql.execute("INSERT INTO jsons1_15 using jsons1 tags('{\"tbname\":\"tt\",\"databool\":true,\"datastr\":\"是是是\"}') values(1591060828000, 4, false, 'jjsf', \"你就会\")") - #tdSql.query("select *,tbname,jtag from jsons1 where jtag->'datastr' match '是' and datastr match 'js'") - #tdSql.checkRows(1) - # open - #tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'") - #tdSql.checkRows(0) - # - # # test join + tdSql.query("select * from jsons1 where jtag->'datastr' match '是' and datastr match 'js'") + tdSql.checkRows(1) + # tdSql.query("select tbname,jtag->'tbname' from jsons1 where jtag->'tbname'='tt' and tbname='jsons1_14'") + # tdSql.checkRows(1) + + # test join tdSql.execute("create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)") tdSql.execute("insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')") tdSql.execute("insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')") @@ -460,19 +460,18 @@ class TDTestCase: tdSql.checkColNameList(res, cname_list) # test top/bottom with group by json tag - # random failure - #tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'") - #tdSql.checkRows(11) - #tdSql.checkData(0, 1, None) - #tdSql.checkData(2, 0, 4) - #tdSql.checkData(3, 0, 3) - #tdSql.checkData(3, 1, "false") - #tdSql.checkData(10, 0, 23) - #tdSql.checkData(10, 1, '"femail"') + # tdSql.query("select top(dataint,2),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1'") + # tdSql.checkRows(11) + # tdSql.checkData(0, 1, None) + # tdSql.checkData(2, 0, 4) + # tdSql.checkData(3, 0, 3) + # tdSql.checkData(3, 1, "false") + # tdSql.checkData(8, 0, 2) + # tdSql.checkData(10, 1, '"femail"') # test having - #tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1") - #tdSql.checkRows(3) + tdSql.query("select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1") + tdSql.checkRows(3) # subquery with json tag tdSql.query("select * from (select jtag, dataint from jsons1) order by dataint") @@ -480,22 +479,13 @@ class TDTestCase: tdSql.checkData(1, 1, 1) tdSql.checkData(5, 0, '{"tag1":false,"tag2":"beijing"}') - # tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") - # tdSql.checkRows(11) - # tdSql.checkData(1, 0, '"femail"') - # tdSql.checkData(2, 0, 5) - # - # res = tdSql.getColNameList("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") - # cname_list = [] - # cname_list.append("jtag->'tag1'") - # tdSql.checkColNameList(res, cname_list) - # - # tdSql.query("select ts,tbname,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)") + tdSql.error("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") + # tdSql.query("select ts,jtag->'tag1' from (select jtag->'tag1',tbname,ts from jsons1 order by ts)") # tdSql.checkRows(11) # tdSql.checkData(1, 1, "jsons1_1") # tdSql.checkData(1, 2, '"femail"') - # - # # union all + + # union all tdSql.query("select jtag->'tag1' from jsons1 union all select jtag->'tag2' from jsons2") tdSql.checkRows(17) tdSql.query("select jtag->'tag1' from jsons1_1 union all select jtag->'tag2' from jsons2_1") @@ -508,24 +498,25 @@ class TDTestCase: tdSql.query("select dataint,jtag,tbname from jsons1 union all select dataint,jtag,tbname from jsons2") tdSql.checkRows(13) - # #show create table - # tdSql.query("show create table jsons1") - # tdSql.checkData(0, 1, 'CREATE TABLE `jsons1` (`ts` TIMESTAMP,`dataint` INT,`databool` BOOL,`datastr` NCHAR(50),`datastrbin` BINARY(150)) TAGS (`jtag` JSON)') - # - # #test aggregate function:count/avg/twa/irate/sum/stddev/leastsquares + #show create table + tdSql.query("show create table jsons1") + tdSql.checkData(0, 1, 'CREATE STABLE `jsons1` (`ts` TIMESTAMP, `dataint` INT, `databool` BOOL, `datastr` NCHAR(50), `datastrbin` VARCHAR(150)) TAGS (`jtag` JSON) WATERMARK 5000a, 5000a') + + #test aggregate function:count/avg/twa/irate/sum/stddev/leastsquares tdSql.query("select count(*) from jsons1 where jtag is not null") tdSql.checkData(0, 0, 10) tdSql.query("select avg(dataint) from jsons1 where jtag is not null") tdSql.checkData(0, 0, 5.3) - #tdSql.error("select twa(dataint) from jsons1 where jtag is not null") - tdSql.error("select irate(dataint) from jsons1 where jtag is not null") - #tdSql.query("select sum(dataint) from jsons1 where jtag->'tag1' is not null") - #tdSql.checkData(0, 0, 49) + # tdSql.query("select twa(dataint) from jsons1 where jtag is not null") + # tdSql.checkData(0, 0, 36) + # tdSql.error("select irate(dataint) from jsons1 where jtag is not null") + tdSql.query("select sum(dataint) from jsons1 where jtag->'tag1' is not null") + tdSql.checkData(0, 0, 45) tdSql.query("select stddev(dataint) from jsons1 where jtag->'tag1'>1") tdSql.checkData(0, 0, 4.496912521) - #tdSql.error("SELECT LEASTSQUARES(dataint, 1, 1) from jsons1 where jtag is not null") - # - # #test selection function:min/max/first/last/top/bottom/percentile/apercentile/last_row/interp + tdSql.query("SELECT LEASTSQUARES(dataint, 1, 1) from jsons1 where jtag is not null") + + #test selection function:min/max/first/last/top/bottom/percentile/apercentile/last_row/interp tdSql.query("select min(dataint) from jsons1 where jtag->'tag1'>1") tdSql.checkData(0, 0, 1) tdSql.query("select max(dataint) from jsons1 where jtag->'tag1'>1") @@ -541,13 +532,16 @@ class TDTestCase: tdSql.query("select percentile(dataint,20) from jsons1 where jtag->'tag1'>1") tdSql.query("select apercentile(dataint, 50) from jsons1 where jtag->'tag1'>1") tdSql.checkData(0, 0, 1.5) - #tdSql.query("select last_row(dataint) from jsons1 where jtag->'tag1'>1") - #tdSql.checkData(0, 0, 11) - #tdSql.error("select interp(dataint) from jsons1 where ts = '2020-06-02 09:17:08.000' and jtag->'tag1'>1") - # - # #test calculation function:diff/derivative/spread/ceil/floor/round/ - #tdSql.error("select diff(dataint) from jsons1 where jtag->'tag1'>1") - #tdSql.error("select derivative(dataint, 10m, 0) from jsons1 where jtag->'tag1'>1") + # tdSql.query("select last_row(dataint) from jsons1 where jtag->'tag1'>1") + # tdSql.query("select interp(dataint) from jsons1 where ts = '2020-06-02 09:17:08.000' and jtag->'tag1'>1") + + #test calculation function:diff/derivative/spread/ceil/floor/round/ + tdSql.query("select diff(dataint) from jsons1 where jtag->'tag1'>1") + # tdSql.checkRows(2) + # tdSql.checkData(0, 0, -1) + # tdSql.checkData(1, 0, 10) + tdSql.query("select derivative(dataint, 10m, 0) from jsons1 where jtag->'tag1'>1") + tdSql.checkData(0, 0, -2) tdSql.query("select spread(dataint) from jsons1 where jtag->'tag1'>1") tdSql.checkData(0, 0, 10) tdSql.query("select ceil(dataint) from jsons1 where jtag->'tag1'>1") diff --git a/tests/system-test/2-query/sample.py b/tests/system-test/2-query/sample.py index a84d93404a..33ef7e65db 100644 --- a/tests/system-test/2-query/sample.py +++ b/tests/system-test/2-query/sample.py @@ -624,8 +624,7 @@ class TDTestCase: tdLog.info(" sample data is in datas groups ,successed sql is : %s" % sample_query ) else: tdLog.exit(" sample data is not in datas groups ,failed sql is : %s" % sample_query ) - - + def basic_sample_query(self): tdSql.execute(" drop database if exists db ") tdSql.execute(" create database if not exists db duration 300 ") @@ -760,6 +759,14 @@ class TDTestCase: self.check_sample("select sample( c1 ,3 ) from t1 where c1 between 1 and 10" ,"select c1 from t1 where c1 between 1 and 10") + tdSql.query("select sample(c1,2) ,c2,c3 ,c5 from stb1") + tdSql.checkRows(2) + tdSql.checkCols(4) + + self.check_sample("select sample( c1 ,3 ),c2,c3,c4,c5 from t1 where c1 between 1 and 10" ,"select c1,c2,c3,c4,c5 from t1 where c1 between 1 and 10") + self.check_sample("select sample( c1 ,3 ),c2,c3,c4,c5 from stb1 where c1 between 1 and 10" ,"select c1,c2,c3,c4,c5 from stb1 where c1 between 1 and 10") + self.check_sample("select sample( c1 ,3 ),t1 from stb1 where c1 between 1 and 10" ,"select c1,t1 from stb1 where c1 between 1 and 10") + # join tdSql.query("select sample( ct4.c1 , 1 ) from ct1, ct4 where ct4.ts=ct1.ts") @@ -772,8 +779,8 @@ class TDTestCase: self.check_sample("select sample(c1,2) from stb1 partition by tbname" , "select c1 from stb1 partition by tbname") # nest query - # tdSql.query("select sample(c1,2) from (select c1 from t1); ") - # tdSql.checkRows(2) + tdSql.query("select sample(c1,2) from (select c1 from t1); ") + tdSql.checkRows(2) # union all tdSql.query("select sample(c1,2) from t1 union all select sample(c1,3) from t1") diff --git a/tests/system-test/6-cluster/5dnode3mnodeStop.py b/tests/system-test/6-cluster/5dnode3mnodeStop.py index 654b27bfc0..69b9c3d879 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStop.py @@ -7,31 +7,25 @@ import os from util.log import * from util.sql import * from util.cases import * +from util.dnodes import * from util.dnodes import TDDnodes from util.dnodes import TDDnode +from util.cluster import * +from test import tdDnodes + import time import socket import subprocess from multiprocessing import Process -class MyDnodes(TDDnodes): - def __init__(self ,dnodes_lists): - super(MyDnodes,self).__init__() - self.dnodes = dnodes_lists # dnode must be TDDnode instance - self.simDeployed = False + class TDTestCase: def init(self,conn ,logSql): tdLog.debug(f"start to excute {__file__}") - self.TDDnodes = None + tdSql.init(conn.cursor()) + self.host = socket.gethostname() - def buildcluster(self,dnodenumber): - self.depoly_cluster(dnodenumber) - self.master_dnode = self.TDDnodes.dnodes[0] - self.host=self.master_dnode.cfgDict["fqdn"] - conn1 = taos.connect(self.master_dnode.cfgDict["fqdn"] , config=self.master_dnode.cfgDir) - tdSql.init(conn1.cursor()) - def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -70,72 +64,34 @@ class TDTestCase: for i in range(4): tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') - def depoly_cluster(self ,dnodes_nums): - - testCluster = False - valgrind = 0 - hostname = socket.gethostname() - dnodes = [] - start_port = 6030 - for num in range(1, dnodes_nums+1): - dnode = TDDnode(num) - dnode.addExtraCfg("firstEp", f"{hostname}:{start_port}") - dnode.addExtraCfg("fqdn", f"{hostname}") - dnode.addExtraCfg("serverPort", f"{start_port + (num-1)*100}") - dnode.addExtraCfg("monitorFqdn", hostname) - dnode.addExtraCfg("monitorPort", 7043) - dnodes.append(dnode) - - self.TDDnodes = MyDnodes(dnodes) - self.TDDnodes.init("") - self.TDDnodes.setTestCluster(testCluster) - self.TDDnodes.setValgrind(valgrind) - self.TDDnodes.stopAll() - for dnode in self.TDDnodes.dnodes: - self.TDDnodes.deploy(dnode.index,{}) - - for dnode in self.TDDnodes.dnodes: - self.TDDnodes.starttaosd(dnode.index) - - # create cluster - for dnode in self.TDDnodes.dnodes[1:]: - # tdLog.debug(dnode.cfgDict) - dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"] - dnode_first_host = dnode.cfgDict["firstEp"].split(":")[0] - dnode_first_port = dnode.cfgDict["firstEp"].split(":")[-1] - cmd = f" taos -h {dnode_first_host} -P {dnode_first_port} -s ' create dnode \"{dnode_id} \" ' ;" - tdLog.debug(cmd) - os.system(cmd) - - time.sleep(2) - tdLog.info(" create cluster with %d dnode done! " %dnodes_nums) - + def check3mnode(self): count=0 while count < 10: time.sleep(1) tdSql.query("show mnodes;") if tdSql.checkRows(3) : - tdLog.debug("mnode is three nodes") + tdLog.debug("mnode is three nodes") + else: + tdLog.exit("mnode number is correct") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='follower': if tdSql.queryResult[2][2]=='follower': tdLog.debug("three mnodes is ready in 10s") break - elif tdSql.queryResult[0][2]=='follower' : - if tdSql.queryResult[1][2]=='leader': + elif tdSql.queryResult[1][2]=='leader' : + if tdSql.queryResult[0][2]=='follower': if tdSql.queryResult[2][2]=='follower': tdLog.debug("three mnodes is ready in 10s") break - elif tdSql.queryResult[0][2]=='follower' : + elif tdSql.queryResult[2][2]=='leader' : if tdSql.queryResult[1][2]=='follower': - if tdSql.queryResult[2][2]=='leader': + if tdSql.queryResult[0][2]=='follower': tdLog.debug("three mnodes is ready in 10s") break count+=1 else: - tdLog.debug("three mnodes is not ready in 10s ") - return -1 + tdLog.exit("three mnodes is not ready in 10s ") tdSql.query("show mnodes;") tdSql.checkRows(3) @@ -153,6 +109,8 @@ class TDTestCase: tdSql.query("show mnodes;") if tdSql.checkRows(3) : tdLog.debug("mnode is three nodes") + else: + tdLog.exit("mnode number is correct") if tdSql.queryResult[0][2]=='offline' : if tdSql.queryResult[1][2]=='leader': if tdSql.queryResult[2][2]=='follower': @@ -164,8 +122,8 @@ class TDTestCase: break count+=1 else: - tdLog.debug("stop mnodes on dnode 2 failed in 10s ") - return -1 + tdLog.exit("stop mnodes on dnode 2 failed in 10s ") + tdSql.error("drop mnode on dnode 1;") tdSql.query("show mnodes;") @@ -185,6 +143,8 @@ class TDTestCase: tdSql.query("show mnodes;") if tdSql.checkRows(3) : tdLog.debug("mnode is three nodes") + else: + tdLog.exit("mnode number is correct") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[1][2]=='offline': if tdSql.queryResult[2][2]=='follower': @@ -192,20 +152,17 @@ class TDTestCase: break count+=1 else: - tdLog.debug("stop mnodes on dnode 2 failed in 10s ") - return -1 + tdLog.exit("stop mnodes on dnode 2 failed in 10s ") + tdSql.error("drop mnode on dnode 2;") tdSql.query("show mnodes;") tdSql.checkRows(3) tdSql.checkData(0,1,'%s:6030'%self.host) - tdSql.checkData(0,2,'leader') tdSql.checkData(0,3,'ready') tdSql.checkData(1,1,'%s:6130'%self.host) - tdSql.checkData(1,2,'offline') tdSql.checkData(1,3,'ready') tdSql.checkData(2,1,'%s:6230'%self.host) - tdSql.checkData(2,2,'follower') tdSql.checkData(2,3,'ready') def check3mnode3off(self): @@ -215,6 +172,8 @@ class TDTestCase: tdSql.query("show mnodes;") if tdSql.checkRows(3) : tdLog.debug("mnode is three nodes") + else: + tdLog.exit("mnode number is correct") if tdSql.queryResult[0][2]=='leader' : if tdSql.queryResult[2][2]=='offline': if tdSql.queryResult[1][2]=='follower': @@ -222,8 +181,8 @@ class TDTestCase: break count+=1 else: - tdLog.debug("stop mnodes on dnode 3 failed in 10s") - return -1 + tdLog.exit("stop mnodes on dnode 3 failed in 10s") + tdSql.error("drop mnode on dnode 3;") tdSql.query("show mnodes;") tdSql.checkRows(3) @@ -237,15 +196,30 @@ class TDTestCase: tdSql.checkData(2,2,'offline') tdSql.checkData(2,3,'ready') - + + def check_dnodes_status(self,dnodeNumbers): + count=0 + while count < 5: + tdSql.query("show dnodes") + # tdLog.debug(tdSql.queryResult) + status=0 + for i in range(dnodeNumbers): + if tdSql.queryResult[i][4] == "ready": + status+=1 + tdLog.debug(status) + + if status == dnodeNumbers: + tdLog.debug(" create cluster with %d dnode and check cluster dnode all ready within 5s! " %dnodeNumbers) + break + count+=1 + time.sleep(1) + else: + tdLog.exit("create cluster with %d dnode but check dnode not ready within 5s ! "%dnodeNumbers) def five_dnode_three_mnode(self,dnodenumber): - tdSql.query("show dnodes;") - tdSql.checkData(0,1,'%s:6030'%self.host) - tdSql.checkData(4,1,'%s:6430'%self.host) - tdSql.checkData(0,4,'ready') - tdSql.checkData(4,4,'ready') + self.check_dnodes_status(5) tdSql.query("show mnodes;") + tdLog.debug(self.host) tdSql.checkRows(1) tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(0,2,'leader') @@ -262,51 +236,40 @@ class TDTestCase: tdSql.error("create mnode on dnode 2") tdSql.query("show dnodes;") - tdLog.debug(tdSql.queryResult) + # tdLog.debug(tdSql.queryResult) tdLog.debug("stop and follower of mnode") - self.TDDnodes.stoptaosd(2) + tdDnodes=cluster.dnodes + # tdLog.debug(tdDnodes[0]) + + tdDnodes[1].stoptaosd() self.check3mnode2off() - self.TDDnodes.starttaosd(2) + tdDnodes[1].starttaosd() + self.check3mnode() - self.TDDnodes.stoptaosd(3) + tdDnodes[2].stoptaosd() self.check3mnode3off() - self.TDDnodes.starttaosd(3) + tdDnodes[2].starttaosd() + self.check3mnode() - self.TDDnodes.stoptaosd(1) + tdDnodes[0].stoptaosd() self.check3mnode1off() - self.TDDnodes.starttaosd(1) + tdDnodes[0].starttaosd() + self.check3mnode() self.check3mnode() stopcount =0 while stopcount <= 2: for i in range(dnodenumber): - self.TDDnodes.stoptaosd(i+1) - # if i == 1 : - # self.check3mnode2off() - # elif i == 2 : - # self.check3mnode3off() - # elif i == 0: - # self.check3mnode1off() - - self.TDDnodes.starttaosd(i+1) + tdDnodes[i].stoptaosd() + tdDnodes[i].starttaosd() # self.check3mnode() stopcount+=1 self.check3mnode() - - def getConnection(self, dnode): - host = dnode.cfgDict["fqdn"] - port = dnode.cfgDict["serverPort"] - config_dir = dnode.cfgDir - return taos.connect(host=host, port=int(port), config=config_dir) - - def run(self): - # tdLog.debug(self.master_dnode.cfgDict) - self.buildcluster(5) self.five_dnode_three_mnode(5) - + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/7-tmq/tmq3mnodeSwitch.py b/tests/system-test/7-tmq/tmq3mnodeSwitch.py new file mode 100644 index 0000000000..2769c3867b --- /dev/null +++ b/tests/system-test/7-tmq/tmq3mnodeSwitch.py @@ -0,0 +1,272 @@ + +from ntpath import join +import taos +import sys +import time +import socket +import os +import threading + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +from util.cluster import * + +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def __init__(self): + self.dnodes = 5 + self.mnodes = 3 + self.idIndex = 0 + self.roleIndex = 2 + self.mnodeStatusIndex = 3 + self.mnodeEpIndex = 1 + self.dnodeStatusIndex = 4 + self.mnodeCheckCnt = 10 + self.host = socket.gethostname() + self.startPort = 6030 + self.portStep = 100 + self.dnodeOfLeader = 0 + + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def checkDnodesStatusAndCreateMnode(self,dnodeNumbers): + count=0 + while count < dnodeNumbers: + tdSql.query("show dnodes") + # tdLog.debug(tdSql.queryResult) + dCnt = 0 + for i in range(dnodeNumbers): + if tdSql.queryResult[i][self.dnodeStatusIndex] != "ready": + break + else: + dCnt += 1 + if dCnt == dnodeNumbers: + break + time.sleep(1) + tdLog.debug("............... waiting for all dnodes ready!") + + tdLog.info("==============create two new mnodes ========") + tdSql.execute("create mnode on dnode 2") + tdSql.execute("create mnode on dnode 3") + self.check3mnode() + return + + def check3mnode(self): + count=0 + while count < self.mnodeCheckCnt: + time.sleep(1) + tdSql.query("show mnodes;") + if tdSql.checkRows(self.mnodes) : + tdLog.debug("mnode is three nodes") + else: + tdLog.exit("mnode number is correct") + + roleOfMnode0 = tdSql.queryResult[0][self.roleIndex] + roleOfMnode1 = tdSql.queryResult[1][self.roleIndex] + roleOfMnode2 = tdSql.queryResult[2][self.roleIndex] + + if roleOfMnode0=='leader' and roleOfMnode1=='follower' and roleOfMnode2 == 'follower' : + self.dnodeOfLeader = tdSql.queryResult[0][self.idIndex] + break + elif roleOfMnode0=='follower' and roleOfMnode1=='leader' and roleOfMnode2 == 'follower' : + self.dnodeOfLeader = tdSql.queryResult[1][self.idIndex] + break + elif roleOfMnode0=='follower' and roleOfMnode1=='follower' and roleOfMnode2 == 'leader' : + self.dnodeOfLeader = tdSql.queryResult[2][self.idIndex] + break + else: + count+=1 + else: + tdLog.exit("three mnodes is not ready in 10s ") + + tdSql.query("show mnodes;") + tdSql.checkRows(self.mnodes) + tdSql.checkData(0,self.mnodeEpIndex,'%s:%d'%(self.host,self.startPort)) + tdSql.checkData(0,self.mnodeStatusIndex,'ready') + tdSql.checkData(1,self.mnodeEpIndex,'%s:%d'%(self.host,self.startPort+self.portStep)) + tdSql.checkData(1,self.mnodeStatusIndex,'ready') + tdSql.checkData(2,self.mnodeEpIndex,'%s:%d'%(self.host,self.startPort+self.portStep*2)) + tdSql.checkData(2,self.mnodeStatusIndex,'ready') + + def check3mnode1off(self): + count=0 + while count < self.mnodeCheckCnt: + time.sleep(1) + tdSql.query("show mnodes") + tdLog.debug(tdSql.queryResult) + # if tdSql.checkRows(self.mnodes) : + # tdLog.debug("mnode is three nodes") + # else: + # tdLog.exit("mnode number is correct") + + roleOfMnode0 = tdSql.queryResult[0][self.roleIndex] + roleOfMnode1 = tdSql.queryResult[1][self.roleIndex] + roleOfMnode2 = tdSql.queryResult[2][self.roleIndex] + + if roleOfMnode0=='offline' : + if roleOfMnode1=='leader' and roleOfMnode2 == 'follower' : + self.dnodeOfLeader = tdSql.queryResult[1][self.idIndex] + break + elif roleOfMnode1=='follower' and roleOfMnode2 == 'leader' : + self.dnodeOfLeader = tdSql.queryResult[2][self.idIndex] + break + elif roleOfMnode1=='offline' : + if roleOfMnode0=='leader' and roleOfMnode2 == 'follower' : + self.dnodeOfLeader = tdSql.queryResult[0][self.idIndex] + break + elif roleOfMnode0=='follower' and roleOfMnode2 == 'leader' : + self.dnodeOfLeader = tdSql.queryResult[2][self.idIndex] + break + elif roleOfMnode2=='offline' : + if roleOfMnode0=='leader' and roleOfMnode1 == 'follower' : + self.dnodeOfLeader = tdSql.queryResult[0][self.idIndex] + break + elif roleOfMnode0=='follower' and roleOfMnode1 == 'leader' : + self.dnodeOfLeader = tdSql.queryResult[1][self.idIndex] + break + + count+=1 + else: + tdLog.exit("three mnodes is not ready in 10s ") + + def checkFileContent(self, consumerId, queryString): + buildPath = tdCom.getBuildPath() + cfgPath = tdCom.getClientCfgPath() + dstFile = '%s/../log/dstrows_%d.txt'%(cfgPath, consumerId) + cmdStr = '%s/build/bin/taos -c %s -s "%s >> %s"'%(buildPath, cfgPath, queryString, dstFile) + tdLog.info(cmdStr) + os.system(cmdStr) + + consumeRowsFile = '%s/../log/consumerid_%d.txt'%(cfgPath, consumerId) + tdLog.info("rows file: %s, %s"%(consumeRowsFile, dstFile)) + + consumeFile = open(consumeRowsFile, mode='r') + queryFile = open(dstFile, mode='r') + + # skip first line for it is schema + queryFile.readline() + + while True: + dst = queryFile.readline() + src = consumeFile.readline() + + if dst: + if dst != src: + tdLog.exit("consumerId %d consume rows is not match the rows by direct query"%consumerId) + else: + break + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db1', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':2}, {'type': 'binary', 'len':20, 'count':1}, {'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 1, + 'rowsPerTbl': 100000, + 'batchNum': 10, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 10, + 'showMsg': 1, + 'showRow': 1} + + topicNameList = ['topic1'] + expectRowsList = [] + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1) + tdLog.info("create stb") + tdCom.create_stable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"], column_elm_list=paraDict['colSchema'], tag_elm_list=paraDict['tagSchema']) + tdLog.info("create ctb") + tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) + tdLog.info("async insert data") + pThread = tmqCom.asyncInsertData(paraDict) + + tdLog.info("create topics from stb with filter") + queryString = "select ts, log(c1), ceil(pow(c1,3)) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[0], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + + # init consume info, and start tmq_sim, then check consume result + tdLog.info("insert consume info to consume processor") + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicNameList[0] + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the notify info of start consume") + tmqCom.getStartConsumeNotifyFromTmqsim() + + tdLog.info("start switch mnode ................") + tdDnodes = cluster.dnodes + + tdLog.info("1. stop dnode 0") + tdDnodes[0].stoptaosd() + time.sleep(10) + self.check3mnode1off() + + tdLog.info("2. start dnode 0") + tdDnodes[0].starttaosd() + self.check3mnode() + + tdLog.info("3. stop dnode 1") + tdDnodes[1].stoptaosd() + time.sleep(10) + self.check3mnode1off() + + tdLog.info("switch end and wait insert data end ................") + pThread.join() + + tdLog.info("check the consume result") + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + if expectRowsList[0] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) + tdLog.exit("0 tmq consume rows error!") + + self.checkFileContent(consumerId, queryString) + + time.sleep(10) + for i in range(len(topicNameList)): + tdSql.query("drop topic %s"%topicNameList[i]) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def run(self): + tdLog.printNoPrefix("======== Notes: must add '-N 5' for run the script ========") + self.checkDnodesStatusAndCreateMnode(self.dnodes) + self.tmqCase1() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqCheckData.py b/tests/system-test/7-tmq/tmqCheckData.py new file mode 100644 index 0000000000..0e55dfa19d --- /dev/null +++ b/tests/system-test/7-tmq/tmqCheckData.py @@ -0,0 +1,182 @@ + +import taos +import sys +import time +import socket +import os +import threading + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def checkFileContent(self, consumerId, queryString): + buildPath = tdCom.getBuildPath() + cfgPath = tdCom.getClientCfgPath() + dstFile = '%s/../log/dstrows_%d.txt'%(cfgPath, consumerId) + cmdStr = '%s/build/bin/taos -c %s -s "%s >> %s"'%(buildPath, cfgPath, queryString, dstFile) + tdLog.info(cmdStr) + os.system(cmdStr) + + consumeRowsFile = '%s/../log/consumerid_%d.txt'%(cfgPath, consumerId) + tdLog.info("rows file: %s, %s"%(consumeRowsFile, dstFile)) + + consumeFile = open(consumeRowsFile, mode='r') + queryFile = open(dstFile, mode='r') + + # skip first line for it is schema + queryFile.readline() + + while True: + dst = queryFile.readline() + src = consumeFile.readline() + + if dst: + if dst != src: + tdLog.exit("consumerId %d consume rows is not match the rows by direct query"%consumerId) + else: + break + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db1', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 1, + 'rowsPerTbl': 10000, + 'batchNum': 10, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 10, + 'showMsg': 1, + 'showRow': 1} + + topicNameList = ['topic1', 'topic2', 'topic3'] + expectRowsList = [] + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1) + tdLog.info("create stb") + tdCom.create_stable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"], column_elm_list=paraDict['colSchema'], tag_elm_list=paraDict['tagSchema']) + tdLog.info("create ctb") + tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) + tdLog.info("insert data") + tmqCom.insert_data(tdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) + + tdLog.info("create topics from stb with filter") + queryString = "select ts, log(c1), ceil(pow(c1,3)) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[0], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + # init consume info, and start tmq_sim, then check consume result + tdLog.info("insert consume info to consume processor") + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicNameList[0] + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + if expectRowsList[0] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) + tdLog.exit("0 tmq consume rows error!") + + self.checkFileContent(consumerId, queryString) + + # reinit consume info, and start tmq_sim, then check consume result + tmqCom.initConsumerTable() + + queryString = "select ts, log(c1), cos(c1) from %s.%s where c1 > 3169" %(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[1], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + consumerId = 1 + topicList = topicNameList[1] + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + if expectRowsList[1] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[1], resultList[0])) + tdLog.exit("1 tmq consume rows error!") + + self.checkFileContent(consumerId, queryString) + + # reinit consume info, and start tmq_sim, then check consume result + tmqCom.initConsumerTable() + + queryString = "select ts, log(c1), atan(c1) from %s.%s where ts >= %d" %(paraDict['dbName'], paraDict['stbName'], paraDict["startTs"]+6137) + sqlString = "create topic %s as %s" %(topicNameList[2], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + consumerId = 2 + topicList = topicNameList[2] + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + # if expectRowsList[2] != resultList[0]: + # tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[2], resultList[0])) + # tdLog.exit("2 tmq consume rows error!") + + # self.checkFileContent(consumerId, queryString) + + time.sleep(10) + for i in range(len(topicNameList)): + tdSql.query("drop topic %s"%topicNameList[i]) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def run(self): + tdSql.prepare() + self.tmqCase1() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py index 9b23056546..d17e36fc97 100644 --- a/tests/system-test/7-tmq/tmqCommon.py +++ b/tests/system-test/7-tmq/tmqCommon.py @@ -204,6 +204,35 @@ class TMQCom: tdLog.debug("insert data ............ [OK]") return + def insert_data_2(self,tsql,dbName,ctbPrefix,ctbNum,rowsPerTbl,batchNum,startTs): + tdLog.debug("start to insert data ............") + tsql.execute("use %s" %dbName) + pre_insert = "insert into " + sql = pre_insert + + t = time.time() + startTs = int(round(t * 1000)) + #tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows)) + for i in range(ctbNum): + sql += " %s%d values "%(ctbPrefix,i) + for j in range(rowsPerTbl): + if (j % 2 == 0): + sql += "(%d, %d, %d, 'tmqrow_%d', now) "%(startTs + j, j, j, j) + else: + sql += "(%d, %d, %d, 'tmqrow_%d', now) "%(startTs + j, j, -j, j) + if (j > 0) and ((j%batchNum == 0) or (j == rowsPerTbl - 1)): + tsql.execute(sql) + if j < rowsPerTbl - 1: + sql = "insert into %s%d values " %(ctbPrefix,i) + else: + sql = "insert into " + #end sql + if sql != pre_insert: + #print("insert sql:%s"%sql) + tsql.execute(sql) + tdLog.debug("insert data ............ [OK]") + return + def insert_data_interlaceByMultiTbl(self,tsql,dbName,ctbPrefix,ctbNum,rowsPerTbl,batchNum,startTs=0): tdLog.debug("start to insert data ............") tsql.execute("use %s" %dbName) @@ -291,6 +320,17 @@ class TMQCom: pThread.start() return pThread + def threadFunctionForInsert(self, **paraDict): + # create new connector for new tdSql instance in my thread + newTdSql = tdCom.newTdSql() + self.insert_data_2(newTdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) + return + + def asyncInsertData(self, paraDict): + pThread = threading.Thread(target=self.threadFunctionForInsert, kwargs=paraDict) + pThread.start() + return pThread + def close(self): self.cursor.close() diff --git a/tests/system-test/7-tmq/tmqUdf.py b/tests/system-test/7-tmq/tmqUdf.py new file mode 100644 index 0000000000..d241a97e0c --- /dev/null +++ b/tests/system-test/7-tmq/tmqUdf.py @@ -0,0 +1,194 @@ +from distutils.log import error +import taos +import sys +import time +import socket +import os +import threading +import subprocess +import platform + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def prepare_udf_so(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + print(projPath) + + if platform.system().lower() == 'windows': + self.libudf1 = subprocess.Popen('(for /r %s %%i in ("udf1.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + if (not tdDnodes.dnodes[0].remoteIP == ""): + tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf1.so',projPath+"\\debug\\build\\lib\\") + self.libudf1 = self.libudf1.replace('udf1.dll','libudf1.so') + else: + self.libudf1 = subprocess.Popen('find %s -name "libudf1.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") + self.libudf1 = self.libudf1.replace('\r','').replace('\n','') + return + + def create_udf_function(self): + # create scalar functions + tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) + + functions = tdSql.getResult("show functions") + function_nums = len(functions) + if function_nums == 1: + tdLog.info("create one udf functions success ") + else: + tdLog.exit("create udf functions fail") + return + + def checkFileContent(self, consumerId, queryString): + buildPath = tdCom.getBuildPath() + cfgPath = tdCom.getClientCfgPath() + dstFile = '%s/../log/dstrows_%d.txt'%(cfgPath, consumerId) + cmdStr = '%s/build/bin/taos -c %s -s "%s >> %s"'%(buildPath, cfgPath, queryString, dstFile) + tdLog.info(cmdStr) + os.system(cmdStr) + + consumeRowsFile = '%s/../log/consumerid_%d.txt'%(cfgPath, consumerId) + tdLog.info("rows file: %s, %s"%(consumeRowsFile, dstFile)) + + consumeFile = open(consumeRowsFile, mode='r') + queryFile = open(dstFile, mode='r') + + # skip first line for it is schema + queryFile.readline() + + while True: + dst = queryFile.readline() + src = consumeFile.readline() + + if dst: + if dst != src: + tdLog.exit("consumerId %d consume rows is not match the rows by direct query"%consumerId) + else: + break + return + + def tmqCase1(self): + tdLog.printNoPrefix("======== test case 1: ") + paraDict = {'dbName': 'db1', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':2}, {'type': 'binary', 'len':20, 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbNum': 1, + 'rowsPerTbl': 1000, + 'batchNum': 10, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 10, + 'showMsg': 1, + 'showRow': 1} + + topicNameList = ['topic1', 'topic2'] + expectRowsList = [] + tmqCom.initConsumerTable() + tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1) + tdLog.info("create stb") + tdCom.create_stable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"], column_elm_list=paraDict['colSchema'], tag_elm_list=paraDict['tagSchema']) + tdLog.info("create ctb") + tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) + tdLog.info("insert data") + tmqCom.insert_data_1(tdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) + + tdLog.info("create topics from stb with filter") + queryString = "select ts,c1,udf1(c1),c2,udf1(c2) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[0], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + # init consume info, and start tmq_sim, then check consume result + tdLog.info("insert consume info to consume processor") + consumerId = 0 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] + topicList = topicNameList[0] + ifcheckdata = 1 + ifManualCommit = 1 + keyList = 'group.id:cgrp1, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest' + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + + if expectRowsList[0] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) + tdLog.exit("0 tmq consume rows error!") + + self.checkFileContent(consumerId, queryString) + tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) + + + # reinit consume info, and start tmq_sim, then check consume result + tmqCom.initConsumerTable() + + queryString = "select ts, c1,udf1(c1),sin(udf1(c2)), log(udf1(c2)) from %s.%s where udf1(c1) == 88 or sin(udf1(c1)) > 0" %(paraDict['dbName'], paraDict['stbName']) + sqlString = "create topic %s as %s" %(topicNameList[1], queryString) + tdLog.info("create topic sql: %s"%sqlString) + tdSql.execute(sqlString) + tdSql.query(queryString) + expectRowsList.append(tdSql.getRows()) + + consumerId = 1 + topicList = topicNameList[1] + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow']) + + tdLog.info("wait the consume result") + expectRows = 1 + resultList = tmqCom.selectConsumeResult(expectRows) + if expectRowsList[1] != resultList[0]: + tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[1], resultList[0])) + tdLog.exit("1 tmq consume rows error!") + + self.checkFileContent(consumerId, queryString) + tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) + + time.sleep(10) + for i in range(len(topicNameList)): + tdSql.query("drop topic %s"%topicNameList[i]) + + tdLog.printNoPrefix("======== test case 1 end ...... ") + + def run(self): + tdSql.prepare() + self.prepare_udf_so() + self.create_udf_function() + self.tmqCase1() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 0e7c4673ee..73e6716cad 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -110,11 +110,11 @@ python3 ./test.py -f 2-query/distribute_agg_avg.py python3 ./test.py -f 2-query/distribute_agg_stddev.py python3 ./test.py -f 2-query/twa.py -python3 ./test.py -f 6-cluster/5dnode1mnode.py -python3 ./test.py -f 6-cluster/5dnode2mnode.py -#python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -#python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -# BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py +python3 ./test.py -f 6-cluster/5dnode1mnode.py +python3 ./test.py -f 6-cluster/5dnode2mnode.py +python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 +# python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 +# BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py python3 ./test.py -f 7-tmq/basic5.py python3 ./test.py -f 7-tmq/subscribeDb.py @@ -132,3 +132,6 @@ python3 ./test.py -f 7-tmq/db.py python3 ./test.py -f 7-tmq/tmqError.py python3 ./test.py -f 7-tmq/schema.py python3 ./test.py -f 7-tmq/stbFilter.py +python3 ./test.py -f 7-tmq/tmqCheckData.py +python3 ./test.py -f 7-tmq/tmqUdf.py +#python3 ./test.py -f 7-tmq/tmq3mnodeSwitch.py -N 5 diff --git a/tests/system-test/simpletest.bat b/tests/system-test/simpletest.bat index c8084c3ad5..0b1f16d216 100644 --- a/tests/system-test/simpletest.bat +++ b/tests/system-test/simpletest.bat @@ -5,7 +5,7 @@ python3 .\test.py -f 0-others\taosShellNetChk.py python3 .\test.py -f 0-others\telemetry.py python3 .\test.py -f 0-others\taosdMonitor.py python3 .\test.py -f 0-others\udfTest.py -python3 .\test.py -f 0-others\udf_create.py +@REM python3 .\test.py -f 0-others\udf_create.py @REM python3 .\test.py -f 0-others\udf_restart_taosd.py @REM python3 .\test.py -f 0-others\cachelast.py diff --git a/tests/system-test/test.py b/tests/system-test/test.py index 55bfd8c945..7d78f5ab21 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -28,6 +28,7 @@ sys.path.append("../pytest") from util.log import * from util.dnodes import * from util.cases import * +from util.cluster import * import taos @@ -58,10 +59,12 @@ if __name__ == "__main__": logSql = True stop = 0 restart = False + dnodeNums = 1 + mnodeNums = 0 updateCfgDict = {} execCmd = "" - opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:', [ - 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd']) + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums']) for key, value in opts: if key in ['-h', '--help']: tdLog.printNoPrefix( @@ -77,6 +80,9 @@ if __name__ == "__main__": tdLog.printNoPrefix('-d update cfg dict, base64 json str') tdLog.printNoPrefix('-k not kill valgrind processer') tdLog.printNoPrefix('-e eval str to run') + tdLog.printNoPrefix('-N create dnodes numbers in clusters') + tdLog.printNoPrefix('-M create mnode numbers in clusters') + sys.exit(0) if key in ['-r', '--restart']: @@ -126,6 +132,12 @@ if __name__ == "__main__": print('updateCfgDict convert fail.') sys.exit(0) + if key in ['-N', '--dnodeNums']: + dnodeNums = value + + if key in ['-M', '--mnodeNums']: + mnodeNums = value + if not execCmd == "": tdDnodes.init(deployPath) print(execCmd) @@ -232,11 +244,35 @@ if __name__ == "__main__": updateCfgDict = ucase.updatecfgDict except: pass - tdDnodes.deploy(1,updateCfgDict) - tdDnodes.start(1) - - tdCases.logSql(logSql) - + if dnodeNums == 1 : + tdDnodes.deploy(1,updateCfgDict) + tdDnodes.start(1) + tdCases.logSql(logSql) + else : + tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) + dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) + tdDnodes = ClusterDnodes(dnodeslist) + tdDnodes.init(deployPath, masterIp) + tdDnodes.setTestCluster(testCluster) + tdDnodes.setValgrind(valgrind) + tdDnodes.stopAll() + for dnode in tdDnodes.dnodes: + tdDnodes.deploy(dnode.index,{}) + for dnode in tdDnodes.dnodes: + tdDnodes.starttaosd(dnode.index) + tdCases.logSql(logSql) + conn = taos.connect( + host, + config=tdDnodes.getSimCfgPath()) + print(tdDnodes.getSimCfgPath(),host) + cluster.create_dnode(conn) + try: + if cluster.check_dnode(conn) : + print("check dnode ready") + except Exception as r: + print(r) + + if testCluster: tdLog.info("Procedures for testing cluster") if fileName == "all": @@ -248,10 +284,12 @@ if __name__ == "__main__": conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + if fileName == "all": tdCases.runAllLinux(conn) else: tdCases.runOneLinux(conn, fileName) + if restart: if fileName == "all": tdLog.info("not need to query ") diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 948df3a40a..e96f5d4793 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -22,8 +22,10 @@ #include #include "taos.h" +#include "taosdef.h" #include "taoserror.h" #include "tlog.h" +#include "types.h" #define GREEN "\033[1;32m" #define NC "\033[0m" @@ -34,11 +36,7 @@ #define MAX_CONSUMER_THREAD_CNT (16) #define MAX_VGROUP_CNT (32) -typedef enum { - NOTIFY_CMD_START_CONSUM, - NOTIFY_CMD_START_COMMIT, - NOTIFY_CMD_ID_BUTT -}NOTIFY_CMD_ID; +typedef enum { NOTIFY_CMD_START_CONSUM, NOTIFY_CMD_START_COMMIT, NOTIFY_CMD_ID_BUTT } NOTIFY_CMD_ID; typedef struct { TdThread thread; @@ -49,8 +47,9 @@ typedef struct { // char autoCommit[8]; // true, false // char autoOffsetRest[16]; // none, earliest, latest - int32_t ifCheckData; - int64_t expectMsgCnt; + TdFilePtr pConsumeRowsFile; + int32_t ifCheckData; + int64_t expectMsgCnt; int64_t consumeMsgCnt; int64_t consumeRowCnt; @@ -86,6 +85,7 @@ typedef struct { int32_t saveRowFlag; int32_t consumeDelay; // unit s int32_t numOfThread; + int32_t useSnapshot; SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT]; } SConfInfo; @@ -93,6 +93,8 @@ static SConfInfo g_stConfInfo; TdFilePtr g_fp = NULL; static int running = 1; +int8_t useSnapshot = 0; + // char* g_pRowValue = NULL; // TdFilePtr g_fp = NULL; @@ -129,7 +131,6 @@ void initLogFile() { char tmpString[128]; sprintf(filename, "%s/../log/tmqlog_%s.txt", configDir, getCurrentTimeString(tmpString)); - // sprintf(filename, "%s/../log/tmqlog.txt", configDir); #ifdef WINDOWS for (int i = 2; i < sizeof(filename); i++) { if (filename[i] == ':') filename[i] = '-'; @@ -203,6 +204,8 @@ void parseArgument(int32_t argc, char* argv[]) { g_stConfInfo.saveRowFlag = atol(argv[++i]); } else if (strcmp(argv[i], "-y") == 0) { g_stConfInfo.consumeDelay = atol(argv[++i]); + } else if (strcmp(argv[i], "-e") == 0) { + useSnapshot = (int8_t)atol(argv[++i]); } else { pError("%s unknow para: %s %s", GREEN, argv[++i], NC); exit(-1); @@ -296,17 +299,148 @@ int32_t saveConsumeContentToTbl(SThreadInfo* pInfo, char* buf) { return 0; } +static char* shellFormatTimestamp(char* buf, int64_t val, int32_t precision) { + // if (shell.args.is_raw_time) { + // sprintf(buf, "%" PRId64, val); + // return buf; + // } + + time_t tt; + int32_t ms = 0; + if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); + ms = val % 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + tt = (time_t)(val / 1000000); + ms = val % 1000000; + } else { + tt = (time_t)(val / 1000); + ms = val % 1000; + } + + /* + comment out as it make testcases like select_with_tags.sim fail. + but in windows, this may cause the call to localtime crash if tt < 0, + need to find a better solution. + if (tt < 0) { + tt = 0; + } + */ + +#ifdef WINDOWS + if (tt < 0) tt = 0; +#endif + if (tt <= 0 && ms < 0) { + tt--; + if (precision == TSDB_TIME_PRECISION_NANO) { + ms += 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + ms += 1000000; + } else { + ms += 1000; + } + } + + struct tm* ptm = taosLocalTime(&tt, NULL); + size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); + + if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", ms); + } else if (precision == TSDB_TIME_PRECISION_MICRO) { + sprintf(buf + pos, ".%06d", ms); + } else { + sprintf(buf + pos, ".%03d", ms); + } + + return buf; +} + +static void shellDumpFieldToFile(TdFilePtr pFile, const char* val, TAOS_FIELD* field, int32_t length, + int32_t precision) { + if (val == NULL) { + taosFprintfFile(pFile, "%s", TSDB_DATA_NULL_STR); + return; + } + + int n; + char buf[TSDB_MAX_BYTES_PER_ROW]; + switch (field->type) { + case TSDB_DATA_TYPE_BOOL: + taosFprintfFile(pFile, "%d", ((((int32_t)(*((char*)val))) == 1) ? 1 : 0)); + break; + case TSDB_DATA_TYPE_TINYINT: + taosFprintfFile(pFile, "%d", *((int8_t*)val)); + break; + case TSDB_DATA_TYPE_UTINYINT: + taosFprintfFile(pFile, "%u", *((uint8_t*)val)); + break; + case TSDB_DATA_TYPE_SMALLINT: + taosFprintfFile(pFile, "%d", *((int16_t*)val)); + break; + case TSDB_DATA_TYPE_USMALLINT: + taosFprintfFile(pFile, "%u", *((uint16_t*)val)); + break; + case TSDB_DATA_TYPE_INT: + taosFprintfFile(pFile, "%d", *((int32_t*)val)); + break; + case TSDB_DATA_TYPE_UINT: + taosFprintfFile(pFile, "%u", *((uint32_t*)val)); + break; + case TSDB_DATA_TYPE_BIGINT: + taosFprintfFile(pFile, "%" PRId64, *((int64_t*)val)); + break; + case TSDB_DATA_TYPE_UBIGINT: + taosFprintfFile(pFile, "%" PRIu64, *((uint64_t*)val)); + break; + case TSDB_DATA_TYPE_FLOAT: + taosFprintfFile(pFile, "%.5f", GET_FLOAT_VAL(val)); + break; + case TSDB_DATA_TYPE_DOUBLE: + n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", length, GET_DOUBLE_VAL(val)); + if (n > TMAX(25, length)) { + taosFprintfFile(pFile, "%*.15e", length, GET_DOUBLE_VAL(val)); + } else { + taosFprintfFile(pFile, "%s", buf); + } + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_JSON: + memcpy(buf, val, length); + buf[length] = 0; + taosFprintfFile(pFile, "\'%s\'", buf); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + shellFormatTimestamp(buf, *(int64_t*)val, precision); + taosFprintfFile(pFile, "'%s'", buf); + break; + default: + break; + } +} + +static void dumpToFileForCheck(TdFilePtr pFile, TAOS_ROW row, TAOS_FIELD* fields, int32_t* length, int32_t num_fields, + int32_t precision) { + for (int32_t i = 0; i < num_fields; i++) { + if (i > 0) { + taosFprintfFile(pFile, "\n"); + } + shellDumpFieldToFile(pFile, (const char*)row[i], fields + i, length[i], precision); + } + taosFprintfFile(pFile, "\n"); +} + static int32_t msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) { char buf[1024]; int32_t totalRows = 0; // printf("topic: %s\n", tmq_get_topic_name(msg)); - int32_t vgroupId = tmq_get_vgroup_id(msg); + int32_t vgroupId = tmq_get_vgroup_id(msg); + const char* dbName = tmq_get_db_name(msg); - taosFprintfFile(g_fp, "msg index:%" PRId64 ", consumerId: %d\n", msgIndex, pInfo->consumerId); - // taosFprintfFile(g_fp, "topic: %s, vgroupId: %d, tableName: %s\n", tmq_get_topic_name(msg), vgroupId, - // tmq_get_table_name(msg)); - taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), vgroupId); + taosFprintfFile(g_fp, "consumerId: %d, msg index:%" PRId64 "\n", pInfo->consumerId, msgIndex); + taosFprintfFile(g_fp, "dbName: %s, topic: %s, vgroupId: %d\n", dbName != NULL ? dbName : "invalid table", + tmq_get_topic_name(msg), vgroupId); while (1) { TAOS_ROW row = taos_fetch_row(msg); @@ -315,16 +449,28 @@ static int32_t msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIndex) TAOS_FIELD* fields = taos_fetch_fields(msg); int32_t numOfFields = taos_field_count(msg); + int32_t* length = taos_fetch_lengths(msg); + int32_t precision = taos_result_precision(msg); + const char* tbName = tmq_get_table_name(msg); + + #if 0 + // get schema + //============================== stub =================================================// + for (int32_t i = 0; i < numOfFields; i++) { + taosFprintfFile(g_fp, "%02d: name: %s, type: %d, len: %d\n", i, fields[i].name, fields[i].type, fields[i].bytes); + } + //============================== stub =================================================// + #endif + + dumpToFileForCheck(pInfo->pConsumeRowsFile, row, fields, length, numOfFields, precision); taos_print_row(buf, row, fields, numOfFields); - const char* tbName = tmq_get_table_name(msg); - if (0 != g_stConfInfo.showRowFlag) { taosFprintfFile(g_fp, "tbname:%s, rows[%d]: %s\n", (tbName != NULL ? tbName : "null table"), totalRows, buf); - if (0 != g_stConfInfo.saveRowFlag) { - saveConsumeContentToTbl(pInfo, buf); - } + // if (0 != g_stConfInfo.saveRowFlag) { + // saveConsumeContentToTbl(pInfo, buf); + // } } totalRows++; @@ -347,8 +493,7 @@ int queryDB(TAOS* taos, char* command) { return 0; } -static void appNothing(void* param, TAOS_RES* res, int32_t numOfRows) { -} +static void appNothing(void* param, TAOS_RES* res, int32_t numOfRows) {} int32_t notifyMainScript(SThreadInfo* pInfo, int32_t cmdId) { char sqlStr[1024] = {0}; @@ -356,11 +501,8 @@ int32_t notifyMainScript(SThreadInfo* pInfo, int32_t cmdId) { int64_t now = taosGetTimestampMs(); // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int - sprintf(sqlStr, "insert into %s.notifyinfo values (%"PRId64", %d, %d)", - g_stConfInfo.cdbName, - now, - cmdId, - pInfo->consumerId); + sprintf(sqlStr, "insert into %s.notifyinfo values (%" PRId64 ", %d, %d)", g_stConfInfo.cdbName, now, cmdId, + pInfo->consumerId); taos_query_a(pInfo->taos, sqlStr, appNothing, NULL); @@ -370,12 +512,12 @@ int32_t notifyMainScript(SThreadInfo* pInfo, int32_t cmdId) { } static int32_t g_once_commit_flag = 0; -static void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { - pError("tmq_commit_cb_print() commit %d\n", code); +static void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { + pError("tmq_commit_cb_print() commit %d\n", code); if (0 == g_once_commit_flag) { g_once_commit_flag = 1; - notifyMainScript((SThreadInfo*)param, (int32_t)NOTIFY_CMD_START_COMMIT); + notifyMainScript((SThreadInfo*)param, (int32_t)NOTIFY_CMD_START_COMMIT); } taosFprintfFile(g_fp, "tmq_commit_cb_print() be called\n"); } @@ -409,6 +551,10 @@ void build_consumer(SThreadInfo* pInfo) { // tmq_conf_set(conf, "auto.offset.reset", "none"); // tmq_conf_set(conf, "auto.offset.reset", "earliest"); // tmq_conf_set(conf, "auto.offset.reset", "latest"); + // + if (useSnapshot) { + tmq_conf_set(conf, "experiment.use.snapshot", "true"); + } pInfo->tmq = tmq_consumer_new(conf, NULL, 0); @@ -464,6 +610,19 @@ void loop_consume(SThreadInfo* pInfo) { pInfo->ts = taosGetTimestampMs(); + if (pInfo->ifCheckData) { + char filename[256] = {0}; + char tmpString[128]; + // sprintf(filename, "%s/../log/consumerid_%d_%s.txt", configDir, pInfo->consumerId, + // getCurrentTimeString(tmpString)); + sprintf(filename, "%s/../log/consumerid_%d.txt", configDir, pInfo->consumerId); + pInfo->pConsumeRowsFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + if (pInfo->pConsumeRowsFile == NULL) { + taosFprintfFile(g_fp, "%s create file fail for save rows content\n", getCurrentTimeString(tmpString)); + return; + } + } + while (running) { TAOS_RES* tmqMsg = tmq_consumer_poll(pInfo->tmq, g_stConfInfo.consumeDelay * 1000); if (tmqMsg) { @@ -475,10 +634,10 @@ void loop_consume(SThreadInfo* pInfo) { totalMsgs++; - if (0 == once_flag) { + if (0 == once_flag) { once_flag = 1; - notifyMainScript(pInfo, NOTIFY_CMD_START_CONSUM); - } + notifyMainScript(pInfo, NOTIFY_CMD_START_CONSUM); + } if (totalRows >= pInfo->expectMsgCnt) { char tmpString[128]; @@ -507,12 +666,13 @@ void* consumeThreadFunc(void* param) { pInfo->taos = taos_connect(NULL, "root", "taosdata", NULL, 0); if (pInfo->taos == NULL) { taosFprintfFile(g_fp, "taos_connect() fail, can not notify and save consume result to main scripte\n"); - exit(-1); + return NULL; } build_consumer(pInfo); build_topic_list(pInfo); if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)) { + taosFprintfFile(g_fp, "create consumer fail! tmq is null or topicList is null\n"); assert(0); return NULL; } @@ -520,7 +680,9 @@ void* consumeThreadFunc(void* param) { int32_t err = tmq_subscribe(pInfo->tmq, pInfo->topicList); if (err != 0) { pError("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); - exit(-1); + taosFprintfFile(g_fp, "tmq_subscribe()! reason: %s\n", tmq_err2str(err)); + assert(0); + return NULL; } tmq_list_destroy(pInfo->topicList); @@ -539,14 +701,13 @@ void* consumeThreadFunc(void* param) { err = tmq_unsubscribe(pInfo->tmq); if (err != 0) { pError("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); - /*pInfo->consumeMsgCnt = -1;*/ - /*return NULL;*/ + taosFprintfFile(g_fp, "tmq_unsubscribe()! reason: %s\n", tmq_err2str(err)); } err = tmq_consumer_close(pInfo->tmq); if (err != 0) { pError("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); - /*exit(-1);*/ + taosFprintfFile(g_fp, "tmq_consumer_close()! reason: %s\n", tmq_err2str(err)); } pInfo->tmq = NULL; diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index ef71f3fce6..f236c1eb88 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -21,6 +21,7 @@ #define UP 3 #define DOWN 4 #define PSIZE shell.info.promptSize +#define SHELL_INPUT_MAX_COMMAND_SIZE 10000 typedef struct { char *buffer; @@ -227,6 +228,7 @@ void shellPrintChar(char c, int32_t times) { } void shellPositionCursor(int32_t step, int32_t direction) { +#ifndef WINDOWS if (step > 0) { if (direction == LEFT) { fprintf(stdout, "\033[%dD", step); @@ -239,6 +241,7 @@ void shellPositionCursor(int32_t step, int32_t direction) { } fflush(stdout); } +#endif } void shellUpdateBuffer(SShellCmd *cmd) { @@ -330,10 +333,14 @@ void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos) { int32_t command_x = ecmd_pos / ws_col; shellPositionCursor(cursor_y, LEFT); shellPositionCursor(command_x - cursor_x, DOWN); +#ifndef WINDOWS fprintf(stdout, "\033[2K"); +#endif for (int32_t i = 0; i < command_x; i++) { shellPositionCursor(1, UP); + #ifndef WINDOWS fprintf(stdout, "\033[2K"); + #endif } fflush(stdout); } @@ -394,6 +401,41 @@ void shellShowOnScreen(SShellCmd *cmd) { fflush(stdout); } +char taosGetConsoleChar() { +#ifdef WINDOWS + static void *console = NULL; + if (console == NULL) { + console = GetStdHandle(STD_INPUT_HANDLE); + } + static TdWchar buf[SHELL_INPUT_MAX_COMMAND_SIZE]; + static char mbStr[5]; + static unsigned long bufLen = 0; + static uint16_t bufIndex = 0, mbStrIndex = 0, mbStrLen = 0; + if (bufLen == 0) { + ReadConsoleW(console, buf, SHELL_INPUT_MAX_COMMAND_SIZE, &bufLen, NULL); + bufIndex = 0; + } + if (mbStrLen == 0){ + if (buf[bufIndex] == '\r') { + bufIndex++; + } + mbStrLen = WideCharToMultiByte(CP_UTF8, 0, &buf[bufIndex], 1, mbStr, sizeof(mbStr), NULL, NULL); + mbStrIndex = 0; + bufIndex++; + } + mbStrIndex++; + if (mbStrIndex == mbStrLen) { + mbStrLen = 0; + if (bufIndex == bufLen) { + bufLen = 0; + } + } + return mbStr[mbStrIndex-1]; +#else + return (char)getchar(); // getchar() return an 'int32_t' value +#endif +} + int32_t shellReadCommand(char *command) { SShellHistory *pHistory = &shell.history; SShellCmd cmd = {0}; @@ -407,7 +449,7 @@ int32_t shellReadCommand(char *command) { // Read input. char c; while (1) { - c = (char)getchar(); // getchar() return an 'int32_t' value + c = taosGetConsoleChar(); if (c == EOF) { return c; @@ -417,7 +459,7 @@ int32_t shellReadCommand(char *command) { int32_t count = shellCountPrefixOnes(c); utf8_array[0] = c; for (int32_t k = 1; k < count; k++) { - c = (char)getchar(); + c = taosGetConsoleChar(); utf8_array[k] = c; } shellInsertChar(&cmd, utf8_array, count); @@ -472,10 +514,10 @@ int32_t shellReadCommand(char *command) { break; } } else if (c == '\033') { - c = (char)getchar(); + c = taosGetConsoleChar(); switch (c) { case '[': - c = (char)getchar(); + c = taosGetConsoleChar(); switch (c) { case 'A': // Up arrow if (hist_counter != pHistory->hstart) { @@ -502,35 +544,35 @@ int32_t shellReadCommand(char *command) { shellMoveCursorLeft(&cmd); break; case '1': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Home key shellPositionCursorHome(&cmd); } break; case '2': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Insert key } break; case '3': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Delete key shellDeleteChar(&cmd); } break; case '4': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // End key shellPositionCursorEnd(&cmd); } break; case '5': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Page up key } break; case '6': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Page down key } break; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 1f29237d38..8a017d378d 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -393,15 +393,11 @@ void shellPrintNChar(const char *str, int32_t length, int32_t width) { break; } int w = 0; -#ifdef WINDOWS - w = bytes; -#else if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){ w = bytes; }else{ w = taosWcharWidth(wc); } -#endif pos += bytes; if (w <= 0) { @@ -524,6 +520,16 @@ bool shellIsLimitQuery(const char *sql) { return false; } +bool shellIsShowQuery(const char *sql) { + //todo refactor + if (taosStrCaseStr(sql, "show ") != NULL) { + return true; + } + + return false; +} + + int32_t shellVerticalPrintResult(TAOS_RES *tres, const char *sql) { TAOS_ROW row = taos_fetch_row(tres); if (row == NULL) { @@ -686,7 +692,7 @@ int32_t shellHorizontalPrintResult(TAOS_RES *tres, const char *sql) { uint64_t resShowMaxNum = UINT64_MAX; - if (shell.args.commands == NULL && shell.args.file[0] == 0 && !shellIsLimitQuery(sql)) { + if (shell.args.commands == NULL && shell.args.file[0] == 0 && !shellIsLimitQuery(sql) && !shellIsShowQuery(sql)) { resShowMaxNum = SHELL_DEFAULT_RES_SHOW_NUM; } diff --git a/tools/taos-tools b/tools/taos-tools index d3c29fb492..28a49b447f 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit d3c29fb492514cbaf08cb533976121bff5d94dea +Subproject commit 28a49b447f71c4f014ebbac858b7215b897d57fd