-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow INSERT null for SQL Server varbinary type
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
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
78 changes: 78 additions & 0 deletions
78
presto-sqlserver/src/test/java/io/prestosql/plugin/sqlserver/TestSqlServerTypeMapping.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,78 @@ | ||
/* | ||
* Licensed 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 io.prestosql.plugin.sqlserver; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.prestosql.Session; | ||
import io.prestosql.testing.AbstractTestQueryFramework; | ||
import io.prestosql.testing.QueryRunner; | ||
import io.prestosql.testing.datatype.CreateAsSelectDataSetup; | ||
import io.prestosql.testing.datatype.DataSetup; | ||
import io.prestosql.testing.datatype.DataTypeTest; | ||
import io.prestosql.testing.sql.PrestoSqlExecutor; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.Test; | ||
|
||
import static io.prestosql.plugin.sqlserver.SqlServerQueryRunner.createSqlServerQueryRunner; | ||
import static io.prestosql.testing.datatype.DataType.varbinaryDataType; | ||
import static java.nio.charset.StandardCharsets.UTF_16LE; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class TestSqlServerTypeMapping | ||
extends AbstractTestQueryFramework | ||
{ | ||
private TestingSqlServer sqlServer; | ||
|
||
@Override | ||
protected QueryRunner createQueryRunner() | ||
throws Exception | ||
{ | ||
sqlServer = new TestingSqlServer(); | ||
sqlServer.start(); | ||
return createSqlServerQueryRunner( | ||
sqlServer, | ||
ImmutableMap.of(), | ||
ImmutableList.of()); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public final void destroy() | ||
{ | ||
sqlServer.close(); | ||
} | ||
|
||
@Test | ||
public void testVarbinary() | ||
{ | ||
DataTypeTest.create() | ||
.addRoundTrip(varbinaryDataType(), null) | ||
.addRoundTrip(varbinaryDataType(), "hello".getBytes(UTF_8)) | ||
.addRoundTrip(varbinaryDataType(), "Piękna łąka w 東京都".getBytes(UTF_8)) | ||
.addRoundTrip(varbinaryDataType(), "Bag full of 💰".getBytes(UTF_16LE)) | ||
.addRoundTrip(varbinaryDataType(), new byte[] {}) | ||
.addRoundTrip(varbinaryDataType(), new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 13, -7, 54, 122, -89, 0, 0, 0}) | ||
.execute(getQueryRunner(), prestoCreateAsSelect("test_varbinary")); | ||
} | ||
|
||
private DataSetup prestoCreateAsSelect(String tableNamePrefix) | ||
{ | ||
return prestoCreateAsSelect(getSession(), tableNamePrefix); | ||
} | ||
|
||
private DataSetup prestoCreateAsSelect(Session session, String tableNamePrefix) | ||
{ | ||
return new CreateAsSelectDataSetup(new PrestoSqlExecutor(getQueryRunner(), session), tableNamePrefix); | ||
} | ||
} |