Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions fluss-cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss</artifactId>
<version>0.9-SNAPSHOT</version>
</parent>

<artifactId>fluss-cli</artifactId>
<name>Fluss : CLI</name>
<packaging>jar</packaging>

<properties>
<picocli.version>4.7.5</picocli.version>
<calcite.version>1.37.0</calcite.version>
<jline.version>3.29.0</jline.version>
<jansi.version>2.4.1</jansi.version>
</properties>

<dependencies>
<!-- Fluss dependencies -->
<dependency>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss-client</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss-common</artifactId>
<version>${project.version}</version>
</dependency>

<!-- CLI Framework -->
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>${picocli.version}</version>
</dependency>

<!-- SQL Parser -->
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>${calcite.version}</version>
</dependency>

<!-- SQL DDL Parser Extension -->
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-server</artifactId>
<version>${calcite.version}</version>
</dependency>

<!-- SQL Babel Parser (supports complex types like ARRAY, MAP, ROW) -->
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-babel</artifactId>
<version>${calcite.version}</version>
</dependency>

<!-- Flink SQL Parser (supports complex types in DDL) -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-sql-parser</artifactId>
<version>1.20.3</version>
</dependency>


<!-- Interactive Console (REPL) -->
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>${jline.version}</version>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<version>${jline.version}</version>
</dependency>

<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
<version>${jline.version}</version>
</dependency>

<!-- ANSI color support -->
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>${jansi.version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss-test-utils</artifactId>
</dependency>

<dependency>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.fluss</groupId>
<artifactId>fluss-server</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${target.java.version}</source>
<target>${target.java.version}</target>
</configuration>
</plugin>

<!-- Shade Plugin to create executable JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>shade-fluss-cli</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
<excludes>
<exclude>org.apache.logging.log4j:log4j-slf4j-impl</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>LICENSE</exclude>
<exclude>NOTICE</exclude>
<!-- Exclude files with forbidden licenses -->
<exclude>javax/transaction/package.html</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.apache.fluss.cli.FlussCliMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>sync-cli-jar</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/../build-target/lib</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>fluss-cli-${project.version}.jar</include>
</includes>
</resource>
</resources>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
39 changes: 39 additions & 0 deletions fluss-cli/src/main/java/org/apache/fluss/cli/FlussCliMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

package org.apache.fluss.cli;

import org.apache.fluss.cli.command.SqlCommand;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.HelpCommand;

/** Main entry point for the Fluss CLI tool. */
@Command(
name = "fluss-cli",
description = "Fluss Command Line Interface",
mixinStandardHelpOptions = true,
version = "Fluss CLI 0.9-SNAPSHOT",
subcommands = {SqlCommand.class, HelpCommand.class})
public class FlussCliMain {

public static void main(String[] args) {
int exitCode = new CommandLine(new FlussCliMain()).execute(args);
System.exit(exitCode);
}
}
116 changes: 116 additions & 0 deletions fluss-cli/src/main/java/org/apache/fluss/cli/command/SqlCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

package org.apache.fluss.cli.command;

import org.apache.fluss.cli.config.ConnectionConfig;
import org.apache.fluss.cli.config.ConnectionManager;
import org.apache.fluss.cli.format.OutputFormat;
import org.apache.fluss.cli.repl.ReplShell;
import org.apache.fluss.cli.sql.SqlExecutor;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.io.File;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.concurrent.Callable;

/** Command for executing SQL statements. */
@Command(name = "sql", description = "Execute SQL commands against Fluss cluster")
public class SqlCommand implements Callable<Integer> {

@Option(
names = {"-b", "--bootstrap-servers"},
description = "Fluss bootstrap servers (host:port,host:port)",
required = true)
private String bootstrapServers;

@Option(
names = {"-f", "--file"},
description = "Execute SQL from file")
private File sqlFile;

@Option(
names = {"-e", "--execute"},
description = "Execute SQL statement directly")
private String sqlStatement;

@Option(
names = {"-c", "--config"},
description = "Configuration properties file")
private File configFile;

@Option(
names = {"-o", "--output-format"},
description = "Output format: table (default), csv, json, tsv",
defaultValue = "table")
private String outputFormat;

@Option(
names = {"-q", "--quiet"},
description = "Quiet mode: suppress status messages (useful for piping output)")
private boolean quiet;

@Option(
names = {"--streaming-timeout"},
description = "Idle timeout in seconds for streaming queries (default: 30)",
defaultValue = "30")
private long streamingTimeoutSeconds;

@Parameters(description = "SQL statements to execute", arity = "0..1")
private String sqlFromArgs;

@Override
public Integer call() throws Exception {
ConnectionConfig connectionConfig;

if (configFile != null) {
connectionConfig = new ConnectionConfig(configFile);
} else {
connectionConfig = new ConnectionConfig(bootstrapServers);
}

try (ConnectionManager connectionManager = new ConnectionManager(connectionConfig)) {
PrintWriter out = new PrintWriter(System.out, true);
OutputFormat format = OutputFormat.fromString(outputFormat);
SqlExecutor executor = new SqlExecutor(connectionManager, out, format, quiet, streamingTimeoutSeconds);

if (sqlFile != null) {
String sql =
new String(Files.readAllBytes(sqlFile.toPath()), StandardCharsets.UTF_8);
executor.executeSql(sql);
} else if (sqlStatement != null) {
executor.executeSql(sqlStatement);
} else if (sqlFromArgs != null) {
executor.executeSql(sqlFromArgs);
} else {
ReplShell repl = new ReplShell(executor);
repl.run();
}

return 0;
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
return 1;
}
}
}
Loading
Loading