Skip to content

Commit aa5fa74

Browse files
2321 - snowflake improved insert,update and delete
1 parent 7af8315 commit aa5fa74

17 files changed

+358
-150
lines changed

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/SnowflakeComponentHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/action/SnowflakeDeleteRowAction.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import static com.bytechef.component.definition.ComponentDsl.action;
2020
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
2121
import static com.bytechef.component.definition.ComponentDsl.string;
22-
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.COLUMN;
2322
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.CONDITION;
2423
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.DATABASE;
2524
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.DATABASE_PROPERTY;
@@ -31,7 +30,6 @@
3130

3231
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3332
import com.bytechef.component.definition.Context;
34-
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
3533
import com.bytechef.component.definition.Parameters;
3634
import com.bytechef.component.snowflake.util.SnowflakeUtils;
3735

@@ -47,14 +45,9 @@ public class SnowflakeDeleteRowAction {
4745
DATABASE_PROPERTY,
4846
SCHEMA_PROPERTY,
4947
TABLE_PROPERTY,
50-
string(COLUMN)
51-
.label("Column")
52-
.description("Column name that will be checked for condition.")
53-
.options((ActionOptionsFunction<String>) SnowflakeUtils::getColumnOptions)
54-
.required(true),
5548
string(CONDITION)
5649
.label("Condition")
57-
.description("Condition that will be checked in the column.")
50+
.description("Condition that will be checked in the column. Example: column1=5")
5851
.required(true))
5952
.output(outputSchema(SQL_STATEMENT_RESPONSE))
6053
.perform(SnowflakeDeleteRowAction::perform);
@@ -63,11 +56,10 @@ private SnowflakeDeleteRowAction() {
6356
}
6457

6558
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
66-
String sqlStatement = "DELETE FROM %s.%s.%s WHERE %s = %s".formatted(
59+
String sqlStatement = "DELETE FROM %s.%s.%s WHERE %s".formatted(
6760
inputParameters.getRequiredString(DATABASE),
6861
inputParameters.getRequiredString(SCHEMA),
6962
inputParameters.getRequiredString(TABLE),
70-
inputParameters.getRequiredString(COLUMN),
7163
inputParameters.getRequiredString(CONDITION));
7264

7365
return SnowflakeUtils.executeStatement(context, sqlStatement);

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/action/SnowflakeExecuteSqlAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/action/SnowflakeInsertRowAction.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import com.bytechef.component.definition.Context;
3333
import com.bytechef.component.definition.Parameters;
3434
import com.bytechef.component.snowflake.util.SnowflakeUtils;
35+
import java.util.stream.Collectors;
3536

3637
/**
3738
* @author Nikolina Spehar
@@ -45,10 +46,6 @@ public class SnowflakeInsertRowAction {
4546
DATABASE_PROPERTY,
4647
SCHEMA_PROPERTY,
4748
TABLE_PROPERTY,
48-
// string(VALUES)
49-
// .label("Values")
50-
// .description("Values to insert into the table. Seperated by comma.")
51-
// .required(true),
5249
VALUES_DYNAMIC_PROPERTY)
5350
.output(outputSchema(SQL_STATEMENT_RESPONSE))
5451
.perform(SnowflakeInsertRowAction::perform);
@@ -57,14 +54,24 @@ private SnowflakeInsertRowAction() {
5754
}
5855

5956
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
60-
String columns = SnowflakeUtils.getTableColumns(inputParameters, context);
57+
String columns = inputParameters.getRequiredMap(VALUES)
58+
.keySet()
59+
.stream()
60+
.map(Object::toString)
61+
.collect(Collectors.joining(","));
62+
63+
String values = inputParameters.getRequiredMap(VALUES)
64+
.values()
65+
.stream()
66+
.map(Object::toString)
67+
.collect(Collectors.joining(","));
6168

6269
String sqlStatement = "INSERT INTO %s.%s.%s(%s) VALUES(%s)".formatted(
6370
inputParameters.getRequiredString(DATABASE),
6471
inputParameters.getRequiredString(SCHEMA),
6572
inputParameters.getRequiredString(TABLE),
6673
columns,
67-
inputParameters.getRequiredString(VALUES));
74+
values);
6875

6976
return SnowflakeUtils.executeStatement(context, sqlStatement);
7077
}

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/action/SnowflakeUpdateRowAction.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import static com.bytechef.component.definition.ComponentDsl.action;
2020
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
2121
import static com.bytechef.component.definition.ComponentDsl.string;
22-
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.COLUMN;
2322
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.CONDITION;
2423
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.DATABASE;
2524
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.DATABASE_PROPERTY;
@@ -29,12 +28,13 @@
2928
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.TABLE;
3029
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.TABLE_PROPERTY;
3130
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.VALUES;
31+
import static com.bytechef.component.snowflake.constant.SnowflakeConstants.VALUES_DYNAMIC_PROPERTY;
3232
import static com.bytechef.component.snowflake.util.SnowflakeUtils.getColumnUpdateStatement;
3333

3434
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3535
import com.bytechef.component.definition.Context;
36-
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
3736
import com.bytechef.component.definition.Parameters;
37+
import com.bytechef.component.definition.Property.ControlType;
3838
import com.bytechef.component.snowflake.util.SnowflakeUtils;
3939

4040
/**
@@ -49,34 +49,24 @@ public class SnowflakeUpdateRowAction {
4949
DATABASE_PROPERTY,
5050
SCHEMA_PROPERTY,
5151
TABLE_PROPERTY,
52-
string(COLUMN)
53-
.label("Column")
54-
.description("Column name that will be checked for condition.")
55-
.options((ActionOptionsFunction<String>) SnowflakeUtils::getColumnOptions)
56-
.required(true),
5752
string(CONDITION)
5853
.label("Condition")
59-
.description("Condition that will be checked in the column.")
54+
.description("Condition that will be checked in the column. Example: column1=5")
55+
.controlType(ControlType.TEXT_AREA)
6056
.required(true),
61-
string(VALUES)
62-
.label("Values")
63-
.description("Updated values of the table. Seperated by comma.")
64-
.required(true))
57+
VALUES_DYNAMIC_PROPERTY)
6558
.output(outputSchema(SQL_STATEMENT_RESPONSE))
6659
.perform(SnowflakeUpdateRowAction::perform);
6760

6861
private SnowflakeUpdateRowAction() {
6962
}
7063

7164
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
72-
String values = inputParameters.getRequiredString(VALUES);
73-
74-
String sqlStatement = "UPDATE %s.%s.%s SET %s WHERE %s = %s".formatted(
65+
String sqlStatement = "UPDATE %s.%s.%s SET %s WHERE %s".formatted(
7566
inputParameters.getRequiredString(DATABASE),
7667
inputParameters.getRequiredString(SCHEMA),
7768
inputParameters.getRequiredString(TABLE),
78-
getColumnUpdateStatement(SnowflakeUtils.getTableColumns(inputParameters, context), values),
79-
inputParameters.getRequiredString(COLUMN),
69+
getColumnUpdateStatement(inputParameters.getRequiredMap(VALUES)),
8070
inputParameters.getRequiredString(CONDITION));
8171

8272
return SnowflakeUtils.executeStatement(context, sqlStatement);

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/connection/SnowflakeConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

server/libs/modules/components/snowflake/src/main/java/com/bytechef/component/snowflake/constant/SnowflakeConstants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-present ByteChef Inc.
2+
* Copyright 2025 ByteChef
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import com.bytechef.component.definition.ComponentDsl.ModifiableObjectProperty;
2929
import com.bytechef.component.definition.ComponentDsl.ModifiableStringProperty;
3030
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
31+
import com.bytechef.component.snowflake.util.SnowflakePropertiesUtils;
3132
import com.bytechef.component.snowflake.util.SnowflakeUtils;
3233

3334
/**
@@ -39,6 +40,8 @@ public class SnowflakeConstants {
3940
public static final String COLUMN = "column";
4041
public static final String CONDITION = "condition";
4142
public static final String DATABASE = "database";
43+
public static final String DATATYPE = "datatype";
44+
public static final String NAME = "name";
4245
public static final String SCHEMA = "schema";
4346
public static final String STATEMENT = "statement";
4447
public static final String TABLE = "table";
@@ -63,7 +66,7 @@ public class SnowflakeConstants {
6366

6467
public static final ModifiableDynamicPropertiesProperty VALUES_DYNAMIC_PROPERTY = dynamicProperties(VALUES)
6568
.propertiesLookupDependsOn(TABLE)
66-
// .properties()
69+
.properties(SnowflakePropertiesUtils::createPropertiesForColumn)
6770
.required(true);
6871

6972
public static final ModifiableObjectProperty SQL_STATEMENT_RESPONSE = object()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.snowflake.constant;
18+
19+
/**
20+
* @author Nikolina Spehar
21+
*/
22+
public enum SnowflakeDataType {
23+
NUMBER("NUMBER"),
24+
DECIMAL("DECIMAL"),
25+
NUMERIC("NUMERIC"),
26+
INT("INT"),
27+
INTEGER("INTEGER"),
28+
BIGINT("BIGINT"),
29+
SMALLINT("SMALLINT"),
30+
TINYINT("TINYINT"),
31+
BYTEINT("BYTEINT"),
32+
FLOAT("FLOAT"),
33+
FLOAT4("FLOAT4"),
34+
FLOAT8("FLOAT8"),
35+
DOUBLE("DOUBLE"),
36+
DOUBLE_PRECISION("DOUBLE PRECISION"),
37+
REAL("REAL"),
38+
39+
VARCHAR("VARCHAR"),
40+
CHAR("CHAR"),
41+
CHARACTER("CHARACTER"),
42+
STRING("STRING"),
43+
TEXT("TEXT"),
44+
NVARCHAR("NVARCHAR"),
45+
NVARCHAR2("NVARCHAR2"),
46+
NCHAR("NCHAR"),
47+
48+
BINARY("BINARY"),
49+
VARBINARY("VARBINARY"),
50+
51+
BOOLEAN("BOOLEAN"),
52+
53+
DATE("DATE"),
54+
TIME("TIME"),
55+
TIMESTAMP("TIMESTAMP"),
56+
TIMESTAMP_NTZ("TIMESTAMP_NTZ"),
57+
TIMESTAMP_LTZ("TIMESTAMP_LTZ"),
58+
TIMESTAMP_TZ("TIMESTAMP_TZ"),
59+
DATETIME("DATETIME"),
60+
61+
VARIANT("VARIANT"),
62+
OBJECT("OBJECT"),
63+
ARRAY("ARRAY"),
64+
65+
GEOGRAPHY("GEOGRAPHY"),
66+
GEOMETRY("GEOMETRY");
67+
68+
private final String name;
69+
70+
SnowflakeDataType(String name) {
71+
this.name = name;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
@Override
79+
public String toString() {
80+
return name;
81+
}
82+
83+
public static SnowflakeDataType getSnowflakeDataType(String text) {
84+
for (SnowflakeDataType type : values()) {
85+
if (type.name.equalsIgnoreCase(text)) {
86+
return type;
87+
}
88+
}
89+
throw new IllegalArgumentException("No SnowflakeDataType constant with text " + text + " found");
90+
}
91+
}

0 commit comments

Comments
 (0)