SQL Client for exploring and submitting SQL programs to Flink
—
Main application entry point providing embedded execution mode for SQL operations against Flink clusters. The SqlClient class manages the complete lifecycle of the SQL client including mode selection, context creation, and CLI initialization.
Primary entry point for starting the Flink SQL Client application from command line.
/**
* Main method to start the SQL Client application
* @param args Command line arguments including mode and options
*/
public static void main(String[] args);Usage Example:
// Start in embedded mode (default)
SqlClient.main(new String[]{"--jar", "path/to/flink-sql-client.jar"});
// Start with explicit embedded mode
SqlClient.main(new String[]{"embedded", "--jar", "path/to/flink-sql-client.jar"});
// Start with initialization script
SqlClient.main(new String[]{"embedded", "--init", "init.sql", "--jar", "flink-sql-client.jar"});Test-friendly method for starting the SQL client with custom terminal factory.
/**
* Start SQL client with custom terminal factory for testing
* @param args Command line arguments
* @param terminalFactory Factory for creating terminal instances
*/
public static void startClient(String[] args, Supplier<Terminal> terminalFactory);Usage Example:
import org.apache.flink.table.client.cli.TerminalUtils;
// Start with default terminal
SqlClient.startClient(args, TerminalUtils::createDefaultTerminal);
// Start with custom terminal for testing
Supplier<Terminal> testTerminalFactory = () -> TerminalUtils.createDumbTerminal(outputStream);
SqlClient.startClient(args, testTerminalFactory);Creates a SQL client instance with specified mode and configuration.
/**
* Create SQL client instance
* @param isEmbedded Whether to use embedded mode (true) or gateway mode (false)
* @param options Parsed command line options
* @param terminalFactory Factory for creating terminal instances
*/
public SqlClient(boolean isEmbedded, CliOptions options, Supplier<Terminal> terminalFactory);Usage Example:
// Parse options and create client
CliOptions options = CliOptionsParser.parseEmbeddedModeClient(args);
SqlClient client = new SqlClient(true, options, TerminalUtils::createDefaultTerminal);Initializes and starts the SQL client with the configured options.
/**
* Start the SQL client and begin processing
* Handles context creation, executor setup, and CLI initialization
*/
private void start();This method internally:
public static final String MODE_EMBEDDED = "embedded";In embedded mode, the SQL CLI is tightly coupled with the executor in a common process. This allows for submitting jobs without having to start an additional component. The embedded mode:
public static final String MODE_GATEWAY = "gateway";Gateway mode is planned for future versions where the SQL CLI client would connect to a REST API gateway. Currently throws SqlClientException when used.
The SqlClient handles various error conditions:
Example Error Handling:
try {
SqlClient client = new SqlClient(true, options, terminalFactory);
client.start();
} catch (SqlClientException e) {
System.err.println("SQL Client error: " + e.getMessage());
// Handle client-specific errors
} catch (Exception e) {
System.err.println("Unexpected error: " + e.getMessage());
// Handle unexpected errors
}The SqlClient automatically registers shutdown hooks to ensure proper cleanup:
Runtime.getRuntime().addShutdownHook(new EmbeddedShutdownThread(sessionId, executor));The shutdown process:
The SqlClient integrates with several key components:
This integration provides a complete SQL client experience from command line parsing through SQL execution and result display.
Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-sql-client-2-12