-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(batch): support extended declare query cursor (#19043)
- Loading branch information
1 parent
f5537d9
commit 7ba6650
Showing
9 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
integration_tests/client-library/java/src/test/java/com/risingwave/TestCursor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.risingwave; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.*; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
|
||
public class TestCursor { | ||
|
||
public static void createTable() throws SQLException { | ||
try (Connection connection = TestUtils.establishConnection()) { | ||
String createTableSQL = "CREATE TABLE test_table (" + | ||
"id INT PRIMARY KEY, " + | ||
"trading_date DATE, " + | ||
"volume INT)"; | ||
Statement statement = connection.createStatement(); | ||
statement.execute(createTableSQL); | ||
|
||
String insertSQL = "INSERT INTO test_table (id, trading_date, volume) VALUES (1, '2024-07-10', 23)"; | ||
statement.execute(insertSQL); | ||
System.out.println("Table test_table created successfully."); | ||
} | ||
} | ||
|
||
public static void dropTable() throws SQLException { | ||
String dropSourceQuery = "DROP TABLE test_table;"; | ||
try (Connection connection = TestUtils.establishConnection()) { | ||
Statement statement = connection.createStatement(); | ||
statement.executeUpdate(dropSourceQuery); | ||
System.out.println("Table test_table dropped successfully."); | ||
} | ||
} | ||
|
||
|
||
public static void readWithExtendedCursor() throws SQLException { | ||
try (Connection connection = TestUtils.establishConnection()) { | ||
connection.setAutoCommit(false); | ||
Statement statement = connection.createStatement(); | ||
statement.execute("START TRANSACTION ISOLATION LEVEL REPEATABLE READ"); | ||
|
||
String declareCursorSql = "DECLARE c1 CURSOR FOR SELECT id, trading_date, volume FROM public.test_table WHERE ((id = CAST(? AS INT)))"; | ||
PreparedStatement pstmt = connection.prepareStatement(declareCursorSql); | ||
pstmt.setInt(1, 1); | ||
pstmt.execute(); | ||
|
||
statement.execute("FETCH 100 FROM c1"); | ||
ResultSet resultSet = statement.getResultSet(); | ||
|
||
while (resultSet != null && resultSet.next()) { | ||
Assertions.assertEquals(resultSet.getInt("id"), 1); | ||
Assertions.assertEquals(resultSet.getString("trading_date"), "2024-07-10"); | ||
Assertions.assertEquals(resultSet.getInt("volume"), 23); | ||
} | ||
|
||
statement.execute("CLOSE c1"); | ||
statement.execute("COMMIT"); | ||
|
||
System.out.println("Data in table read with cursor successfully."); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCursor() throws SQLException { | ||
createTable(); | ||
readWithExtendedCursor(); | ||
dropTable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_sqlparser::ast::ObjectName; | ||
|
||
use super::statement::RewriteExprsRecursive; | ||
use crate::binder::BoundQuery; | ||
use crate::expr::ExprRewriter; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BoundDeclareCursor { | ||
pub cursor_name: ObjectName, | ||
// Currently we only support cursor with query | ||
pub query: Box<BoundQuery>, // reuse the BoundQuery struct | ||
} | ||
|
||
impl RewriteExprsRecursive for BoundDeclareCursor { | ||
fn rewrite_exprs_recursive(&mut self, rewriter: &mut impl ExprRewriter) { | ||
self.query.rewrite_exprs_recursive(rewriter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters