Skip to content

Commit 786b40d

Browse files
committed
fix pre-commit
1 parent 7a72e8a commit 786b40d

4 files changed

Lines changed: 34 additions & 34 deletions

File tree

engine/src/main/java/com/arcadedb/function/polyglot/JavascriptFunctionDefinition.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ private static String toJavaScriptValue(final Object value) {
120120
// This allows existing code that passes JSON strings (e.g., '{"foo":"bar"}') to continue working
121121
// Note: This is a heuristic and may not catch all edge cases, but prioritizes backward compatibility
122122
final String trimmed = str.trim();
123-
final boolean looksLikeJson =
123+
final boolean looksLikeJson =
124124
(trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.length() > 2 && trimmed.contains(":")) ||
125125
(trimmed.startsWith("[") && trimmed.endsWith("]") && trimmed.length() > 2);
126-
final boolean alreadyQuoted =
126+
final boolean alreadyQuoted =
127127
(trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length() > 1);
128-
128+
129129
if (looksLikeJson || alreadyQuoted) {
130130
// Pass through as-is for JSON-like objects/arrays or already-quoted strings
131131
return str;
132132
}
133-
133+
134134
// Otherwise, escape special characters and wrap in quotes
135135
final String escaped = str.replace("\\", "\\\\")
136136
.replace("\"", "\\\"")

engine/src/main/java/com/arcadedb/function/sql/SQLFunctionDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Object execute(final Object... parameters) {
6363
paramMap.put(parameterNames[i], parameters[i]);
6464
}
6565
}
66-
66+
6767
final ResultSet result = database.command("sqlscript", implementation, paramMap);
6868
Object first = null;
6969
if (result.hasNext()) {

engine/src/test/java/com/arcadedb/query/sql/function/sql/CustomFunctionParametersTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ void testSQLFunctionWithStringParameter() throws Exception {
3838
db.command("sql", "CREATE DOCUMENT TYPE Beer");
3939
db.command("sql", "INSERT INTO Beer SET name = 'Hocus Pocus'");
4040
db.command("sql", "INSERT INTO Beer SET name = 'Leffe'");
41-
41+
4242
// Define a function that retrieves data using a string argument
4343
db.command("sql", "DEFINE FUNCTION my.getBeerId \"SELECT @rid AS result FROM `Beer` WHERE name=:a\" PARAMETERS [a] LANGUAGE sql");
44-
44+
4545
// Call the function with a string parameter
4646
final ResultSet result = db.query("sql", "SELECT `my.getBeerId`('Hocus Pocus') as beerRid");
4747
assertThat(result.hasNext()).isTrue();
48-
48+
4949
final Object beerRid = result.next().getProperty("beerRid");
5050
assertThat(beerRid).isNotNull();
5151
// The RID should be a valid RID format (e.g., #1:0)
@@ -58,11 +58,11 @@ void testSQLFunctionReturningInput() throws Exception {
5858
TestHelper.executeInNewDatabase("testSQLFunctionReturningInput", (db) -> {
5959
// Define a function that returns the input directly
6060
db.command("sql", "DEFINE FUNCTION my.returnInput \"SELECT :a AS result\" PARAMETERS [a] LANGUAGE sql");
61-
61+
6262
// Call the function with a string parameter
6363
final ResultSet result = db.query("sql", "SELECT `my.returnInput`('Hocus Pocus') as output");
6464
assertThat(result.hasNext()).isTrue();
65-
65+
6666
final String output = result.next().getProperty("output");
6767
assertThat(output).isEqualTo("Hocus Pocus");
6868
});
@@ -73,11 +73,11 @@ void testSQLFunctionWithMultipleParameters() throws Exception {
7373
TestHelper.executeInNewDatabase("testSQLFunctionWithMultipleParameters", (db) -> {
7474
// Define a function that uses multiple parameters
7575
db.command("sql", "DEFINE FUNCTION my.add \"SELECT :a + :b AS result\" PARAMETERS [a, b] LANGUAGE sql");
76-
76+
7777
// Call the function with multiple numeric parameters
7878
final ResultSet result = db.query("sql", "SELECT `my.add`(10, 20) as output");
7979
assertThat(result.hasNext()).isTrue();
80-
80+
8181
final Integer output = result.next().getProperty("output");
8282
assertThat(output).isEqualTo(30);
8383
});
@@ -88,11 +88,11 @@ void testJavaScriptFunctionReturningInput() throws Exception {
8888
TestHelper.executeInNewDatabase("testJavaScriptFunctionReturningInput", (db) -> {
8989
// Define a JavaScript function that returns the input
9090
db.command("sql", "DEFINE FUNCTION my.returnInputJS \"return a\" PARAMETERS [a] LANGUAGE js");
91-
91+
9292
// Call the function with a string parameter
9393
final ResultSet result = db.query("sql", "SELECT `my.returnInputJS`('Hocus Pocus') as output");
9494
assertThat(result.hasNext()).isTrue();
95-
95+
9696
final String output = result.next().getProperty("output");
9797
assertThat(output).isEqualTo("Hocus Pocus");
9898
});
@@ -103,11 +103,11 @@ void testJavaScriptFunctionWithStringParameter() throws Exception {
103103
TestHelper.executeInNewDatabase("testJavaScriptFunctionWithStringParameter", (db) -> {
104104
// Define a JavaScript function that manipulates a string
105105
db.command("sql", "DEFINE FUNCTION my.uppercase \"return a.toUpperCase()\" PARAMETERS [a] LANGUAGE js");
106-
106+
107107
// Call the function with a string parameter
108108
final ResultSet result = db.query("sql", "SELECT `my.uppercase`('hello world') as output");
109109
assertThat(result.hasNext()).isTrue();
110-
110+
111111
final String output = result.next().getProperty("output");
112112
assertThat(output).isEqualTo("HELLO WORLD");
113113
});
@@ -118,11 +118,11 @@ void testJavaScriptFunctionWithMultipleParameters() throws Exception {
118118
TestHelper.executeInNewDatabase("testJavaScriptFunctionWithMultipleParameters", (db) -> {
119119
// Define a JavaScript function with multiple parameters
120120
db.command("sql", "DEFINE FUNCTION my.add \"return a + b\" PARAMETERS [a, b] LANGUAGE js");
121-
121+
122122
// Call the function with numeric parameters
123123
final ResultSet result = db.query("sql", "SELECT `my.add`(10, 20) as output");
124124
assertThat(result.hasNext()).isTrue();
125-
125+
126126
final Integer output = result.next().getProperty("output");
127127
assertThat(output).isEqualTo(30);
128128
});
@@ -133,11 +133,11 @@ void testJavaScriptFunctionWithStringContainingQuotes() throws Exception {
133133
TestHelper.executeInNewDatabase("testJavaScriptFunctionWithStringContainingQuotes", (db) -> {
134134
// Define a JavaScript function that handles strings
135135
db.command("sql", "DEFINE FUNCTION my.echo \"return a\" PARAMETERS [a] LANGUAGE js");
136-
136+
137137
// Call the function with a string containing special characters
138138
final ResultSet result = db.query("sql", "SELECT `my.echo`('It\\'s a \"test\"') as output");
139139
assertThat(result.hasNext()).isTrue();
140-
140+
141141
final String output = result.next().getProperty("output");
142142
assertThat(output).isEqualTo("It's a \"test\"");
143143
});
@@ -148,11 +148,11 @@ void testSQLFunctionWithNumericParameter() throws Exception {
148148
TestHelper.executeInNewDatabase("testSQLFunctionWithNumericParameter", (db) -> {
149149
// Define a function that works with numbers
150150
db.command("sql", "DEFINE FUNCTION my.double \"SELECT :a * 2 AS result\" PARAMETERS [a] LANGUAGE sql");
151-
151+
152152
// Call the function with a numeric parameter
153153
final ResultSet result = db.query("sql", "SELECT `my.double`(21) as output");
154154
assertThat(result.hasNext()).isTrue();
155-
155+
156156
final Integer output = result.next().getProperty("output");
157157
assertThat(output).isEqualTo(42);
158158
});
@@ -163,11 +163,11 @@ void testJavaScriptFunctionWithBooleanParameter() throws Exception {
163163
TestHelper.executeInNewDatabase("testJavaScriptFunctionWithBooleanParameter", (db) -> {
164164
// Define a JavaScript function that works with booleans
165165
db.command("sql", "DEFINE FUNCTION my.negate \"return !a\" PARAMETERS [a] LANGUAGE js");
166-
166+
167167
// Call the function with a boolean parameter
168168
final ResultSet result = db.query("sql", "SELECT `my.negate`(true) as output");
169169
assertThat(result.hasNext()).isTrue();
170-
170+
171171
final Boolean output = result.next().getProperty("output");
172172
assertThat(output).isFalse();
173173
});

engine/src/test/java/com/arcadedb/query/sql/function/sql/GitHubIssueCustomFunctionTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ void testCase1_SQLFunctionWithStringParameter_BeerExample() throws Exception {
3737
db.command("sql", "CREATE DOCUMENT TYPE Beer");
3838
db.command("sql", "INSERT INTO Beer SET name = 'Hocus Pocus'");
3939
db.command("sql", "INSERT INTO Beer SET name = 'Leffe'");
40-
40+
4141
// Define function as in the issue
4242
db.command("sql", "DEFINE FUNCTION my.getBeerId \"SELECT @rid AS result FROM `Beer` WHERE name=:a\" PARAMETERS [a] LANGUAGE sql");
43-
43+
4444
// Call the function - should NOT return null
4545
final ResultSet result = db.query("sql", "SELECT `my.getBeerId`('Hocus Pocus') as beerRid");
4646
assertThat(result.hasNext()).isTrue();
47-
47+
4848
final Object beerRid = result.next().getProperty("beerRid");
4949
assertThat(beerRid).isNotNull();
5050
System.out.println("Case 1 - Beer RID: " + beerRid);
@@ -56,11 +56,11 @@ void testCase2_SQLFunctionReturningInput() throws Exception {
5656
TestHelper.executeInNewDatabase("testCase2", (db) -> {
5757
// Define function as in the issue
5858
db.command("sql", "DEFINE FUNCTION my.returnInput \"SELECT :a AS result\" PARAMETERS [a] LANGUAGE sql");
59-
59+
6060
// Call the function - should NOT return null
6161
final ResultSet result = db.query("sql", "SELECT `my.returnInput`('Hocus Pocus') as output");
6262
assertThat(result.hasNext()).isTrue();
63-
63+
6464
final Object output = result.next().getProperty("output");
6565
assertThat(output).isNotNull();
6666
assertThat(output.toString()).isEqualTo("Hocus Pocus");
@@ -73,28 +73,28 @@ void testCase3_JavaScriptFunctionReturningInput() throws Exception {
7373
TestHelper.executeInNewDatabase("testCase3", (db) -> {
7474
// Define JS function as in the issue - should NOT cause ClassCastException
7575
db.command("sql", "DEFINE FUNCTION my.returnInputJS \"return a\" PARAMETERS [a] LANGUAGE js");
76-
76+
7777
// Call the function
7878
final ResultSet result = db.query("sql", "SELECT `my.returnInputJS`('Hocus Pocus') as output");
7979
assertThat(result.hasNext()).isTrue();
80-
80+
8181
final Object output = result.next().getProperty("output");
8282
assertThat(output).isNotNull();
8383
assertThat(output.toString()).isEqualTo("Hocus Pocus");
8484
System.out.println("Case 3 - Output: " + output);
8585
});
8686
}
87-
87+
8888
@Test
8989
void testIssueObservation_NoDoubleQuotingNeeded() throws Exception {
9090
TestHelper.executeInNewDatabase("testObservation", (db) -> {
9191
// Test that strings don't need to be double quoted
9292
db.command("sql", "DEFINE FUNCTION my.echo \"SELECT :a AS result\" PARAMETERS [a] LANGUAGE sql");
93-
93+
9494
// Single quotes should work fine (not double quotes)
9595
final ResultSet result = db.query("sql", "SELECT `my.echo`('Hello World') as output");
9696
assertThat(result.hasNext()).isTrue();
97-
97+
9898
final String output = result.next().getProperty("output");
9999
assertThat(output).isEqualTo("Hello World");
100100
System.out.println("Observation - No double quoting needed: " + output);

0 commit comments

Comments
 (0)