Skip to content

Commit

Permalink
ADH-5242
Browse files Browse the repository at this point in the history
- added support adb array type
- added support adb hstore (trino map) type
- fixed types tests
  • Loading branch information
VitekArkhipov committed Dec 19, 2024
1 parent 3470969 commit 599b9c2
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 164 deletions.
12 changes: 12 additions & 0 deletions plugin/trino-adb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<groupId>io.airlift</groupId>
<artifactId>http-server</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -199,6 +205,12 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@

public final class TypeUtil
{
public static final String ARRAY_TYPE_ELEMENT_DELIMITER = ",";
public static final String MAP_TYPE_VALUE_SEPARATOR = "=>";
public static final String MAP_TYPE_NULL_VALUE = "NULL";
public static final String MAP_TYPE_ENTRY_SEPARATOR = ", ";
public static final char MAP_TYPE_VALUE_QUOTE = '"';
public static final int POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION = 6;
public static final DateTimeFormatter TIMESTAMP_TYPE_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR_OF_ERA, 4, 9, SignStyle.NORMAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ public ColumnDataType getColumnDataType(ConnectorSession session, JdbcTypeHandle
return dataTypeMapper.getColumnDataType(session, typeHandle);
}

public List<ColumnDataType> getColumnDataTypes(ConnectorSession session, List<JdbcColumnHandle> jdbcColumnHandles)
{
return dataTypeMapper.getColumnDataTypes(session, jdbcColumnHandles);
}

@Override
public WriteMapping toWriteMapping(ConnectorSession session, Type type)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.trino.plugin.adb.connector.datatype;

import io.trino.spi.type.ArrayType;

import static com.google.common.base.Preconditions.checkArgument;

public class ArrayDataType
implements ColumnDataType
{
private final String name;
private final ArrayType arrayType;
private final ColumnDataType elementType;

public ArrayDataType(ArrayType arrayType, ColumnDataType elementType)
{
checkArgument(arrayType != null, "arrayType is null");
checkArgument(elementType != null, "elementType is null");
this.name = elementType.getName() + "[]";
this.arrayType = arrayType;
this.elementType = elementType;
}

@Override
public String getName()
{
return name;
}

@Override
public ConnectorDataType getType()
{
return ConnectorDataType.ARRAY;
}

public ArrayType getArrayType()
{
return arrayType;
}

public ColumnDataType getElementType()
{
return elementType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ public enum ConnectorDataType
TIMESTAMP_WITHOUT_TIME_ZONE,
ENUM,
ARRAY,
MAP,
UNSUPPORTED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.trino.plugin.adb.connector.datatype;

import io.trino.spi.type.MapType;

public class MapDataType
implements ColumnDataType
{
private final String name;
private final MapType mapType;

public MapDataType(MapType mapType)
{
this.name = "hstore";
this.mapType = mapType;
}

@Override
public String getName()
{
return name;
}

@Override
public ConnectorDataType getType()
{
return ConnectorDataType.MAP;
}

public MapType getTrinoMapType()
{
return mapType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import io.trino.plugin.adb.connector.datatype.ColumnDataType;
import io.trino.plugin.jdbc.ColumnMapping;
import io.trino.plugin.jdbc.JdbcColumnHandle;
import io.trino.plugin.jdbc.JdbcOutputTableHandle;
import io.trino.plugin.jdbc.JdbcTypeHandle;
import io.trino.plugin.jdbc.WriteMapping;
Expand All @@ -35,5 +36,7 @@ public interface DataTypeMapper

List<ColumnDataType> getColumnDataTypes(ConnectorSession session, JdbcOutputTableHandle outputTableHandle);

Optional<ColumnDataType> fromTrinoType(Type type);
List<ColumnDataType> getColumnDataTypes(ConnectorSession session, List<JdbcColumnHandle> jdbcColumnHandles);

Optional<ColumnDataType> fromTrinoType(ConnectorSession session, Type type);
}
Loading

0 comments on commit 599b9c2

Please sign in to comment.