Skip to content

Commit 8dc2b76

Browse files
committed
Applied google formatter to project
Signed-off-by: Marvin Froeder <velo.br@gmail.com>
1 parent 681d36d commit 8dc2b76

File tree

6 files changed

+177
-66
lines changed

6 files changed

+177
-66
lines changed

pom.xml

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<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">
23
<modelVersion>4.0.0</modelVersion>
34

@@ -6,6 +7,9 @@
67
<version>1.0.0-SNAPSHOT</version>
78

89
<properties>
10+
<gcf.skipInstallHooks>true</gcf.skipInstallHooks>
11+
<git-code-format-maven-plugin.version>5.3</git-code-format-maven-plugin.version>
12+
913
<maven.deploy.skip>true</maven.deploy.skip>
1014
<maven.compiler.source>11</maven.compiler.source>
1115
<maven.compiler.target>11</maven.compiler.target>
@@ -103,7 +107,6 @@
103107
</dependency>
104108
</dependencies>
105109

106-
107110
<build>
108111
<plugins>
109112
<plugin>
@@ -113,10 +116,10 @@
113116
<executions>
114117
<!-- Run shade goal on package phase -->
115118
<execution>
116-
<phase>package</phase>
117119
<goals>
118120
<goal>shade</goal>
119121
</goals>
122+
<phase>package</phase>
120123
<configuration>
121124
<artifactSet>
122125
<excludes>
@@ -139,7 +142,7 @@
139142
</filter>
140143
</filters>
141144
<transformers>
142-
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
145+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"></transformer>
143146
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
144147
<mainClass>com.datasqrl.SqlRunner</mainClass>
145148
</transformer>
@@ -148,6 +151,107 @@
148151
</execution>
149152
</executions>
150153
</plugin>
154+
155+
<!-- linter for java code, will be applied automatically when files are committed to git -->
156+
<!-- alternatively, can run with -Pdev to force code format on the whole project -->
157+
<plugin>
158+
<groupId>com.cosium.code</groupId>
159+
<artifactId>git-code-format-maven-plugin</artifactId>
160+
<version>${git-code-format-maven-plugin.version}</version>
161+
<dependencies>
162+
<!-- Enable https://github.com/google/google-java-format -->
163+
<dependency>
164+
<groupId>com.cosium.code</groupId>
165+
<artifactId>google-java-format</artifactId>
166+
<version>${git-code-format-maven-plugin.version}</version>
167+
</dependency>
168+
</dependencies>
169+
<executions>
170+
<!-- On commit, format the modified files -->
171+
<execution>
172+
<id>install-formatter-hook</id>
173+
<goals>
174+
<goal>install-hooks</goal>
175+
</goals>
176+
<inherited>false</inherited>
177+
</execution>
178+
<!-- On Maven verify phase, fail if any file (including
179+
unmodified) is
180+
badly formatted -->
181+
<execution>
182+
<id>validate-code-format</id>
183+
<goals>
184+
<goal>validate-code-format</goal>
185+
</goals>
186+
</execution>
187+
</executions>
188+
</plugin>
189+
190+
<plugin>
191+
<groupId>com.github.ekryd.sortpom</groupId>
192+
<artifactId>sortpom-maven-plugin</artifactId>
193+
<version>4.0.0</version>
194+
<configuration>
195+
<keepBlankLines>true</keepBlankLines>
196+
<lineSeparator>\n</lineSeparator>
197+
<predefinedSortOrder>recommended_2008_06</predefinedSortOrder>
198+
<createBackupFile>false</createBackupFile>
199+
</configuration>
200+
</plugin>
151201
</plugins>
152202
</build>
153-
</project>
203+
204+
<profiles>
205+
<profile>
206+
<!-- useful profile for local development -->
207+
<id>dev</id>
208+
209+
<properties>
210+
<gcf.skipInstallHooks>false</gcf.skipInstallHooks>
211+
</properties>
212+
213+
<build>
214+
<plugins>
215+
<plugin>
216+
<groupId>com.cosium.code</groupId>
217+
<artifactId>git-code-format-maven-plugin</artifactId>
218+
<executions>
219+
<execution>
220+
<id>format-code</id>
221+
<goals>
222+
<goal>format-code</goal>
223+
</goals>
224+
<phase>initialize</phase>
225+
</execution>
226+
</executions>
227+
</plugin>
228+
229+
<plugin>
230+
<groupId>com.github.ekryd.sortpom</groupId>
231+
<artifactId>sortpom-maven-plugin</artifactId>
232+
<executions>
233+
<execution>
234+
<id>format</id>
235+
<goals>
236+
<goal>sort</goal>
237+
</goals>
238+
<phase>initialize</phase>
239+
</execution>
240+
</executions>
241+
</plugin>
242+
</plugins>
243+
</build>
244+
</profile>
245+
246+
<profile>
247+
<!-- just compile, skip all other checks -->
248+
<id>quickbuild</id>
249+
<properties>
250+
<skipTests>true</skipTests>
251+
<enforcer.skip>true</enforcer.skip>
252+
<maven.javadoc.skip>true</maven.javadoc.skip>
253+
<gcf.skip>true</gcf.skip>
254+
</properties>
255+
</profile>
256+
</profiles>
257+
</project>

src/main/java/com/datasqrl/JsonEnvVarDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public String replaceWithEnv(Map<String, String> env, String value) {
4141

4242
return result.toString();
4343
}
44-
}
44+
}

src/main/java/com/datasqrl/SqlExecutor.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
1717

18-
/**
19-
* Class for executing SQL scripts programmatically.
20-
*/
18+
/** Class for executing SQL scripts programmatically. */
2119
class SqlExecutor {
2220

2321
private static final Logger log = LoggerFactory.getLogger(SqlExecutor.class);
2422

25-
private static final Pattern SET_STATEMENT_PATTERN = Pattern.compile(
26-
"SET\\s+'(\\S+)'\\s*=\\s*'(.+)';?", Pattern.CASE_INSENSITIVE);
23+
private static final Pattern SET_STATEMENT_PATTERN =
24+
Pattern.compile("SET\\s+'(\\S+)'\\s*=\\s*'(.+)';?", Pattern.CASE_INSENSITIVE);
2725

2826
private final TableEnvironment tableEnv;
2927

@@ -35,9 +33,8 @@ public SqlExecutor(Configuration configuration, String udfPath) {
3533
throw e;
3634
}
3735

38-
EnvironmentSettings tEnvConfig = EnvironmentSettings.newInstance()
39-
.withConfiguration(configuration)
40-
.build();
36+
EnvironmentSettings tEnvConfig =
37+
EnvironmentSettings.newInstance().withConfiguration(configuration).build();
4138

4239
this.tableEnv = StreamTableEnvironment.create(sEnv, tEnvConfig);
4340

@@ -62,14 +59,15 @@ public TableResult executeScript(String script) throws Exception {
6259
for (String statement : statements) {
6360
tableResult = executeStatement(statement);
6461
}
65-
//
66-
// TableEnvironmentImpl tEnv1 = (TableEnvironmentImpl) tableEnv;
67-
//
68-
// StatementSetOperation parse = (StatementSetOperation)tEnv1.getParser()
69-
// .parse(statements.get(statements.size()-1)).get(0);
70-
//
71-
// CompiledPlan plan = tEnv1.compilePlan(parse.getOperations());
72-
// plan.writeToFile("/Users/henneberger/flink-jar-runner/src/test/resources/sql/compiled-plan-udf.json");
62+
//
63+
// TableEnvironmentImpl tEnv1 = (TableEnvironmentImpl) tableEnv;
64+
//
65+
// StatementSetOperation parse = (StatementSetOperation)tEnv1.getParser()
66+
// .parse(statements.get(statements.size()-1)).get(0);
67+
//
68+
// CompiledPlan plan = tEnv1.compilePlan(parse.getOperations());
69+
//
70+
// plan.writeToFile("/Users/henneberger/flink-jar-runner/src/test/resources/sql/compiled-plan-udf.json");
7371

7472
return tableResult;
7573
}
@@ -168,4 +166,4 @@ protected TableResult executeCompiledPlan(String planJson) throws Exception {
168166
throw e;
169167
}
170168
}
171-
}
169+
}

src/main/java/com/datasqrl/SqlRunner.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,53 @@
1717

1818
package com.datasqrl;
1919

20+
import java.io.File;
21+
import java.util.*;
22+
import java.util.concurrent.Callable;
2023
import lombok.SneakyThrows;
2124
import lombok.extern.slf4j.Slf4j;
2225
import org.apache.flink.configuration.Configuration;
2326
import org.apache.flink.configuration.GlobalConfiguration;
2427
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
2528
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.module.SimpleModule;
26-
import org.apache.flink.table.api.CompiledPlan;
2729
import org.apache.flink.table.api.TableResult;
28-
import org.apache.flink.table.api.internal.TableEnvironmentImpl;
29-
import org.apache.flink.table.operations.StatementSetOperation;
3030
import org.apache.flink.util.FileUtils;
3131
import picocli.CommandLine;
3232
import picocli.CommandLine.*;
33-
import java.io.File;
34-
import java.util.*;
35-
import java.util.concurrent.Callable;
3633

37-
/**
38-
* Main class for executing SQL scripts using picocli.
39-
*/
40-
@Command(name = "SqlRunner", mixinStandardHelpOptions = true, version = "1.0", description = "Runs SQL scripts using Flink TableEnvironment.")
34+
/** Main class for executing SQL scripts using picocli. */
35+
@Command(
36+
name = "SqlRunner",
37+
mixinStandardHelpOptions = true,
38+
version = "1.0",
39+
description = "Runs SQL scripts using Flink TableEnvironment.")
4140
@Slf4j
4241
public class SqlRunner implements Callable<Integer> {
4342

44-
@Option(names = {"-s", "--sqlfile"}, description = "SQL file to execute.")
43+
@Option(
44+
names = {"-s", "--sqlfile"},
45+
description = "SQL file to execute.")
4546
private File sqlFile;
4647

47-
@Option(names = {"--block"}, description = "Wait for the flink job manager to exit.",
48-
defaultValue = "false")
48+
@Option(
49+
names = {"--block"},
50+
description = "Wait for the flink job manager to exit.",
51+
defaultValue = "false")
4952
private boolean block;
5053

51-
@Option(names = {"--planfile"}, description = "Compiled plan JSON file.")
54+
@Option(
55+
names = {"--planfile"},
56+
description = "Compiled plan JSON file.")
5257
private File planFile;
5358

54-
@Option(names = {"--configfile"}, description = "Configuration YAML file.")
59+
@Option(
60+
names = {"--configfile"},
61+
description = "Configuration YAML file.")
5562
private File configFile;
5663

57-
@Option(names = {"--udfpath"}, description = "Path to UDFs.")
64+
@Option(
65+
names = {"--udfpath"},
66+
description = "Path to UDFs.")
5867
private String udfPath;
5968

6069
public static void main(String[] args) {
@@ -110,7 +119,6 @@ private String replaceScriptWithEnv(String script) {
110119
return objectMapper.writeValueAsString(map);
111120
}
112121

113-
114122
public static ObjectMapper getObjectMapper() {
115123
ObjectMapper objectMapper = new ObjectMapper();
116124

@@ -130,7 +138,8 @@ public static ObjectMapper getObjectMapper() {
130138
*/
131139
private Configuration loadConfigurationFromYaml(File configFile) throws Exception {
132140
log.info("Loading configuration from {}", configFile.getAbsolutePath());
133-
Configuration configuration = GlobalConfiguration.loadConfiguration(configFile.getAbsolutePath());
141+
Configuration configuration =
142+
GlobalConfiguration.loadConfiguration(configFile.getAbsolutePath());
134143
return configuration;
135144
}
136-
}
145+
}

src/main/java/com/datasqrl/SqlUtils.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* Utility class for parsing SQL scripts.
8-
*/
6+
/** Utility class for parsing SQL scripts. */
97
class SqlUtils {
108

119
private static final String STATEMENT_DELIMITER = ";"; // a statement should end with `;`
@@ -25,10 +23,13 @@ class SqlUtils {
2523
* @return A list of individual SQL statements.
2624
*/
2725
public static List<String> parseStatements(String script) {
28-
String formatted = formatSqlFile(script).replaceAll(BEGIN_CERTIFICATE,
29-
ESCAPED_BEGIN_CERTIFICATE).replaceAll(END_CERTIFICATE, ESCAPED_END_CERTIFICATE)
30-
.replaceAll(COMMENT_PATTERN, "").replaceAll(ESCAPED_BEGIN_CERTIFICATE, BEGIN_CERTIFICATE)
31-
.replaceAll(ESCAPED_END_CERTIFICATE, END_CERTIFICATE);
26+
String formatted =
27+
formatSqlFile(script)
28+
.replaceAll(BEGIN_CERTIFICATE, ESCAPED_BEGIN_CERTIFICATE)
29+
.replaceAll(END_CERTIFICATE, ESCAPED_END_CERTIFICATE)
30+
.replaceAll(COMMENT_PATTERN, "")
31+
.replaceAll(ESCAPED_BEGIN_CERTIFICATE, BEGIN_CERTIFICATE)
32+
.replaceAll(ESCAPED_END_CERTIFICATE, END_CERTIFICATE);
3233

3334
List<String> statements = new ArrayList<>();
3435

@@ -74,4 +75,4 @@ public static String formatSqlFile(String content) {
7475
formatted.append(LINE_DELIMITER);
7576
return formatted.toString();
7677
}
77-
}
78+
}

0 commit comments

Comments
 (0)