-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support MS SQL in Jdbc SQL connector [HZ-2694] #25071
Merged
Merged
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1be42c7
add MSSQLAllTypesInsertJdbcSqlConnectorTest
Edizc d3be4ed
Add MSSQLGenericMapStoreTest
Edizc 490204e
Add HazelcastMSSQlDialect and Update, SelectJdbcConnectorTest for Mic…
Edizc e5bb270
Unnecessary import and a comment corrected in HazelcastMSSQLDialect
Edizc 7001339
Add the rest of the tests
Edizc 7a43387
Add MSSQL's LEN function
Edizc c055b2d
Fixed Checkstyle Issues
Edizc 2529e52
Make Length to LEN translation
TomaszGaweda 149c3fe
Removed commented out tests and unused import
Edizc 96419a8
Changed the upsert statement from IF to MERGE
Edizc a12e698
Merge branch 'hazelcast:master' into add-mssqlTests
Edizc 764b40c
Updated MSSQLUpsertQueryBuilder and removed unnecessary code
Edizc ac78843
Merge branch 'add-mssqlTests' of github.com:Edizc/hazelcast into add-…
Edizc fa1b867
Add After annotation to close mocks
Edizc 51c6ede
added GETTERS to serialization in readData and writeData
Edizc 5277e6a
updated initializeGetters function
Edizc b6f8f6e
Add missing predicate tests
frant-hartm 0c9fa89
Fix test for TIME data type
frant-hartm 38f23f6
Cleanup bit/boolean support
frant-hartm b37d4ea
Fix CreateDataConnectionJdbcSqlConnectorTest
frant-hartm 1dd1464
Cleanup duplication
frant-hartm c7add0a
Add BIT back - needed for MySQL boolean support
frant-hartm 075e21b
Organized MSSQLUpsertQueryBuilder
Edizc 50fc63d
Merge branch 'add-mssqlTests' of github.com:Edizc/hazelcast into add-…
Edizc 46f4df2
add GettersProvider
Edizc 19728c0
fixed GettersProvider
Edizc 5294505
removed commented code in SelectProcessorSupplier
Edizc b954cec
Sorted the supported Sql dialect names
Edizc 1a42b7f
Add BIT back (needed for MySQL boolean support)
frant-hartm 9160aa7
Cleanup getters
frant-hartm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
extensions/mapstore/src/test/java/com/hazelcast/mapstore/mssql/MSSQLGenericMapStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2023 Hazelcast Inc. | ||
* | ||
* Licensed under the Hazelcast Community License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://hazelcast.com/hazelcast-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.mapstore.mssql; | ||
|
||
import com.hazelcast.mapstore.GenericMapStoreTest; | ||
import com.hazelcast.nio.serialization.genericrecord.GenericRecord; | ||
import com.hazelcast.test.annotation.NightlyTest; | ||
import com.hazelcast.test.jdbc.MSSQLDatabaseProvider; | ||
import com.hazelcast.test.jdbc.MySQLDatabaseProvider; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import java.util.Properties; | ||
|
||
import static com.hazelcast.mapstore.GenericMapLoader.DATA_CONNECTION_REF_PROPERTY; | ||
import static com.hazelcast.mapstore.GenericMapLoader.EXTERNAL_NAME_PROPERTY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assume.assumeFalse; | ||
|
||
@Category(NightlyTest.class) | ||
public class MSSQLGenericMapStoreTest extends GenericMapStoreTest { | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
initialize(new MSSQLDatabaseProvider()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../src/main/java/com/hazelcast/jet/sql/impl/connector/jdbc/mssql/HazelcastMSSQLDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 Hazelcast Inc. | ||
* | ||
* Licensed under the Hazelcast Community License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://hazelcast.com/hazelcast-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.jet.sql.impl.connector.jdbc.mssql; | ||
|
||
import com.hazelcast.jet.sql.impl.validate.operators.string.HazelcastConcatOperator; | ||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlNode; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.SqlWriter.Frame; | ||
import org.apache.calcite.sql.SqlWriter.FrameTypeEnum; | ||
import org.apache.calcite.sql.dialect.MssqlSqlDialect; | ||
|
||
/** | ||
* Custom dialect for MSSQL which allows correct unparsing of MSSQL specific operators, like CONCAT | ||
*/ | ||
public class HazelcastMSSQLDialect extends MssqlSqlDialect { | ||
|
||
/** | ||
* Creates a HazelcastMSSQLDialect. | ||
*/ | ||
public HazelcastMSSQLDialect(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public void unparseCall(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { | ||
switch (call.getKind()) { | ||
case OTHER: | ||
if (call.getOperator() instanceof HazelcastConcatOperator) { | ||
unparseConcat(writer, call); | ||
break; | ||
} else { | ||
super.unparseCall(writer, call, leftPrec, rightPrec); | ||
break; | ||
} | ||
|
||
default: | ||
super.unparseCall(writer, call, leftPrec, rightPrec); | ||
} | ||
} | ||
|
||
private void unparseConcat(SqlWriter writer, SqlCall call) { | ||
writer.print("CONCAT"); | ||
Frame frame = writer.startList(FrameTypeEnum.PARENTHESES, "(", ")"); | ||
for (SqlNode operand : call.getOperandList()) { | ||
writer.sep(","); | ||
operand.unparse(writer, 0, 0); | ||
} | ||
writer.endList(frame); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../hazelcast/jet/sql/impl/connector/jdbc/mssql/MSSQLAllTypesInsertJdbcSqlConnectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2023 Hazelcast Inc. | ||
* | ||
* Licensed under the Hazelcast Community License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://hazelcast.com/hazelcast-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.jet.sql.impl.connector.jdbc.mssql; | ||
|
||
import com.hazelcast.jet.sql.impl.connector.jdbc.AllTypesInsertJdbcSqlConnectorTest; | ||
import com.hazelcast.test.annotation.NightlyTest; | ||
import com.hazelcast.test.jdbc.MSSQLDatabaseProvider; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import static org.assertj.core.api.Assumptions.assumeThat; | ||
|
||
@Category(NightlyTest.class) | ||
public class MSSQLAllTypesInsertJdbcSqlConnectorTest extends AllTypesInsertJdbcSqlConnectorTest { | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
initialize(new MSSQLDatabaseProvider()); | ||
} | ||
|
||
|
||
@Before | ||
public void setUp() throws Exception { | ||
// MSSQL doesn't support BOOLEAN but BIT can be used instead and, uses FLOAT as 8-byte floating point type | ||
frant-hartm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// For Float in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql?view=sql-server-ver16 | ||
// For BIT in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16 | ||
// For TIMESTAMP in MSSQL see https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2005/ms182776(v=sql.90)?redirectedfrom=MSDN | ||
// For DATETIMEOFFSET in MSSQL see https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetimeoffset-transact-sql?view=sql-server-ver16 | ||
if (type.equals("BOOLEAN")) { | ||
type = "BIT"; | ||
} | ||
if (type.equals("DOUBLE")) { | ||
type = "FLOAT"; | ||
} | ||
if (type.equals("TIMESTAMP")) { | ||
type = "DATETIME"; | ||
} | ||
if (type.equals("TIMESTAMP WITH TIME ZONE")) { | ||
type = "DATETIMEOFFSET"; | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...java/com/hazelcast/jet/sql/impl/connector/jdbc/mssql/MSSQLSelectJdbcSqlConnectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2023 Hazelcast Inc. | ||
* | ||
* Licensed under the Hazelcast Community License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://hazelcast.com/hazelcast-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.jet.sql.impl.connector.jdbc.mssql; | ||
|
||
import com.hazelcast.jet.sql.impl.connector.jdbc.SelectJdbcSqlConnectorTest; | ||
import com.hazelcast.test.annotation.NightlyTest; | ||
import com.hazelcast.test.jdbc.MSSQLDatabaseProvider; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category(NightlyTest.class) | ||
public class MSSQLSelectJdbcSqlConnectorTest extends SelectJdbcSqlConnectorTest { | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
initialize(new MSSQLDatabaseProvider()); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...java/com/hazelcast/jet/sql/impl/connector/jdbc/mssql/MSSQLUpdateJdbcSqlConnectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2023 Hazelcast Inc. | ||
* | ||
* Licensed under the Hazelcast Community License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://hazelcast.com/hazelcast-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.jet.sql.impl.connector.jdbc.mssql; | ||
|
||
import com.hazelcast.jet.sql.impl.connector.jdbc.UpdateJdbcSqlConnectorTest; | ||
import com.hazelcast.test.annotation.NightlyTest; | ||
import com.hazelcast.test.jdbc.MSSQLDatabaseProvider; | ||
import org.junit.BeforeClass; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category(NightlyTest.class) | ||
public class MSSQLUpdateJdbcSqlConnectorTest extends UpdateJdbcSqlConnectorTest { | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
initialize(new MSSQLDatabaseProvider()); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.