Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions presto-docs/src/main/sphinx/connector/singlestore.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ For :doc:`/sql/create-table` statement, the default table type is ``columnstore`
The table type can be configured by setting the ``default_table_type`` engine variable, see
`Creating a Columnstore Table <https://docs.singlestore.com/cloud/create-a-database/creating-a-columnstore-table/>`_.

SingleStore to PrestoDB type mapping
------------------------------------

Map of SingleStore types to the relevant PrestoDB types:

.. list-table:: SingleStore to PrestoDB type mapping
:widths: 50, 50
:header-rows: 1

* - SingleStore type
- PrestoDB type
* - ``BOOLEAN``
- ``BOOLEAN``
* - ``INTEGER``
- ``INTEGER``
* - ``FLOAT``
- ``REAL``
* - ``DOUBLE``
- ``DOUBLE``
* - ``DECIMAL``
- ``DECIMAL``
* - ``LARGETEXT``
- ``VARCHAR (unbounded)``
* - ``VARCHAR(len)``
- ``VARCHAR(len) len < 21845``
* - ``CHAR(len)``
- ``CHAR(len)``
* - ``MEDIUMTEXT``
- ``VARCHAR(len) 21845 <= len < 5592405``
* - ``LARGETEXT``
- ``VARCHAR(len) 5592405 <= len < 1431655765``
* - ``MEDIUMBLOB``
- ``VARBINARY``
* - ``UUID``
- ``UUID``
* - ``DATE``
- ``DATE``
* - ``TIME``
- ``TIME``
* - ``DATETIME``
- ``TIMESTAMP``

No other types are supported.

The following SQL statements are not supported:

* :doc:`/sql/alter-schema`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.facebook.presto.plugin.jdbc.JdbcConnectorId;
import com.facebook.presto.plugin.jdbc.JdbcIdentity;
import com.facebook.presto.plugin.jdbc.JdbcTableHandle;
import com.facebook.presto.plugin.jdbc.JdbcTypeHandle;
import com.facebook.presto.plugin.jdbc.mapping.ReadMapping;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.ConnectorTableMetadata;
import com.facebook.presto.spi.PrestoException;
Expand All @@ -34,6 +36,7 @@
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
Expand All @@ -44,8 +47,11 @@
import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.common.type.UuidType.UUID;
import static com.facebook.presto.common.type.VarbinaryType.VARBINARY;
import static com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType;
import static com.facebook.presto.common.type.Varchars.isVarcharType;
import static com.facebook.presto.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
import static com.facebook.presto.plugin.jdbc.mapping.StandardColumnMappings.varbinaryReadMapping;
import static com.facebook.presto.plugin.jdbc.mapping.StandardColumnMappings.varcharReadMapping;
import static com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS;
import static com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
Expand Down Expand Up @@ -143,21 +149,36 @@ protected String toSqlType(Type type)
if (varcharType.isUnbounded()) {
return "longtext";
}
if (varcharType.getLengthSafe() <= 255) {
return "tinytext";
if (varcharType.getLengthSafe() <= 21844) {
// 21844 is the maximum length a singlestore varchar supports.
return super.toSqlType(type);
}
if (varcharType.getLengthSafe() <= 65535) {
return "text";
}
if (varcharType.getLengthSafe() <= 16777215) {
if (varcharType.getLengthSafe() <= 5592405) { // 16MB
return "mediumtext";
}
return "longtext";
if (varcharType.getLengthSafe() <= 1431655765) { // 100MB to 1GB
return "longtext"; // max = 1431655765
}
else {
throw new PrestoException(NOT_SUPPORTED, "Unsupported column width: " + varcharType.getLengthSafe());
}
}

return super.toSqlType(type);
}

@Override
public Optional<ReadMapping> toPrestoType(ConnectorSession session, JdbcTypeHandle typeHandle)
{
switch (typeHandle.getJdbcType()) {
case Types.CLOB:
return Optional.of(varcharReadMapping(createUnboundedVarcharType()));
case Types.BLOB:
return Optional.of(varbinaryReadMapping());
}
return super.toPrestoType(session, typeHandle);
}

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,17 @@ public final void destroy()
public void testShowColumns(@Optional("PARQUET") String storageFormat)
{
MaterializedResult actual = computeActual("SHOW COLUMNS FROM orders");

MaterializedResult expectedParametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
.row("orderkey", "bigint", "", "", 19L, null, null)
.row("custkey", "bigint", "", "", 19L, null, null)
.row("orderstatus", "varchar(85)", "", "", null, null, 85L)//utf8
.row("orderstatus", "varchar(1)", "", "", null, null, 1L)//utf8
.row("totalprice", "double", "", "", 53L, null, null)
.row("orderdate", "date", "", "", null, null, null)
.row("orderpriority", "varchar(85)", "", "", null, null, 85L)
.row("clerk", "varchar(85)", "", "", null, null, 85L)
.row("orderpriority", "varchar(15)", "", "", null, null, 15L)
.row("clerk", "varchar(15)", "", "", null, null, 15L)
.row("shippriority", "integer", "", "", 10L, null, null)
.row("comment", "varchar(85)", "", "", null, null, 85L)
.row("comment", "varchar(79)", "", "", null, null, 79L)
.build();

assertEquals(actual, expectedParametrizedVarchar);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ public void testDescribeTable()
{
// we need specific implementation of this tests due to specific Presto<->SingleStore varchar length mapping.
MaterializedResult actualColumns = computeActual("DESC ORDERS").toTestTypes();

MaterializedResult expectedColumns = MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
.row("orderkey", "bigint", "", "", 19L, null, null)
.row("custkey", "bigint", "", "", 19L, null, null)
.row("orderstatus", "varchar(85)", "", "", null, null, 85L)//utf-8
.row("orderstatus", "varchar(1)", "", "", null, null, 1L)//utf-8
.row("totalprice", "double", "", "", 53L, null, null)
.row("orderdate", "date", "", "", null, null, null)
.row("orderpriority", "varchar(85)", "", "", null, null, 85L)
.row("clerk", "varchar(85)", "", "", null, null, 85L)
.row("orderpriority", "varchar(15)", "", "", null, null, 15L)
.row("clerk", "varchar(15)", "", "", null, null, 15L)
.row("shippriority", "integer", "", "", 10L, null, null)
.row("comment", "varchar(85)", "", "", null, null, 85L)
.row("comment", "varchar(79)", "", "", null, null, 79L)
.build();
assertEquals(actualColumns, expectedColumns);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public void testBasicTypes()
public void testPrestoCreatedParameterizedVarchar()
{
DataTypeTest.create()
.addRoundTrip(stringDataType("varchar(10)", createVarcharType(255 / 3)), "text_a")//utf-8
.addRoundTrip(stringDataType("varchar(255)", createVarcharType(255 / 3)), "text_b")
.addRoundTrip(stringDataType("varchar(256)", createVarcharType(65535 / 3)), "text_c")
.addRoundTrip(stringDataType("varchar(65535)", createVarcharType(65535 / 3)), "text_d")
.addRoundTrip(stringDataType("varchar(65536)", createVarcharType(16777215 / 3)), "text_e")
.addRoundTrip(stringDataType("varchar(16777215)", createVarcharType(16777215 / 3)), "text_f")
.addRoundTrip(stringDataType("varchar(10)", createVarcharType(10)), "text_a")//utf-8
.addRoundTrip(stringDataType("varchar(255)", createVarcharType(255)), "text_b")
.addRoundTrip(stringDataType("varchar(21844)", createVarcharType(21844)), "text_c")
.addRoundTrip(stringDataType("varchar(21846)", createVarcharType(5592405)), "text_d")
.addRoundTrip(stringDataType("varchar(65536)", createVarcharType(5592405)), "text_e")
.addRoundTrip(stringDataType("varchar(16777215)", createVarcharType(1431655765)), "text_f")
.execute(getQueryRunner(), prestoCreateAsSelect("presto_test_parameterized_varchar"));
}

Expand Down
Loading