Skip to content

Commit b767788

Browse files
committed
Restore back modules
1 parent dabb27c commit b767788

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3224
-0
lines changed

trino-rest-base/pom.xml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Licensed under the Apache License, Version 2.0 (the "License");
4+
~ you may not use this file except in compliance with the License.
5+
~ You may obtain a copy of the License at
6+
~
7+
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~
9+
~ Unless required by applicable law or agreed to in writing, software
10+
~ distributed under the License is distributed on an "AS IS" BASIS,
11+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
~ See the License for the specific language governing permissions and
13+
~ limitations under the License.
14+
-->
15+
16+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17+
<modelVersion>4.0.0</modelVersion>
18+
19+
<parent>
20+
<groupId>rocks.trino</groupId>
21+
<artifactId>trino-rest</artifactId>
22+
<version>0.1-SNAPSHOT</version>
23+
</parent>
24+
25+
<artifactId>trino-rest-base</artifactId>
26+
<description>Presto rest base</description>
27+
<packaging>jar</packaging>
28+
<version>0.1-SNAPSHOT</version>
29+
30+
<properties>
31+
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
32+
</properties>
33+
34+
<dependencies>
35+
<!-- Presto SPI -->
36+
<dependency>
37+
<groupId>io.trino</groupId>
38+
<artifactId>trino-spi</artifactId>
39+
<scope>provided</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>io.airlift</groupId>
44+
<artifactId>slice</artifactId>
45+
<scope>provided</scope>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>com.fasterxml.jackson.core</groupId>
50+
<artifactId>jackson-annotations</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.google.guava</groupId>
55+
<artifactId>guava</artifactId>
56+
<scope>provided</scope>
57+
</dependency>
58+
</dependencies>
59+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rocks.trino.rest;
16+
17+
import io.trino.spi.connector.ColumnMetadata;
18+
import io.trino.spi.connector.ConnectorTableMetadata;
19+
import io.trino.spi.connector.SchemaTableName;
20+
import io.trino.spi.type.Type;
21+
22+
import java.util.Collection;
23+
import java.util.List;
24+
import java.util.function.Consumer;
25+
26+
import static java.util.stream.Collectors.toList;
27+
28+
public interface Rest
29+
{
30+
ConnectorTableMetadata getTableMetadata(SchemaTableName schemaTableName);
31+
32+
List<String> listSchemas();
33+
34+
default List<SchemaTableName> listTables()
35+
{
36+
return listSchemas().stream()
37+
.flatMap(schema -> listTables(schema).stream())
38+
.collect(toList());
39+
}
40+
41+
List<SchemaTableName> listTables(String schema);
42+
43+
Collection<? extends List<?>> getRows(SchemaTableName schemaTableName);
44+
45+
Consumer<List> createRowSink(SchemaTableName schemaTableName);
46+
47+
default List<Type> getTypes(SchemaTableName schemaTableName)
48+
{
49+
return getTableMetadata(schemaTableName).getColumns().stream()
50+
.map(ColumnMetadata::getType)
51+
.collect(toList());
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rocks.trino.rest;
16+
17+
import com.fasterxml.jackson.annotation.JsonCreator;
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
import io.trino.spi.connector.ColumnHandle;
20+
import io.trino.spi.type.Type;
21+
22+
import java.util.Objects;
23+
24+
public class RestColumnHandle
25+
implements ColumnHandle
26+
{
27+
private final String name;
28+
private final Type type;
29+
30+
@JsonCreator
31+
public RestColumnHandle(
32+
@JsonProperty("name") String name,
33+
@JsonProperty("type") Type type)
34+
{
35+
this.name = name;
36+
this.type = type;
37+
}
38+
39+
@JsonProperty("name")
40+
public String getName()
41+
{
42+
return name;
43+
}
44+
45+
@JsonProperty("type")
46+
public Type getType()
47+
{
48+
return type;
49+
}
50+
51+
@Override
52+
public boolean equals(Object o)
53+
{
54+
if (this == o) {
55+
return true;
56+
}
57+
if (o == null || getClass() != o.getClass()) {
58+
return false;
59+
}
60+
RestColumnHandle that = (RestColumnHandle) o;
61+
return Objects.equals(name, that.name);
62+
}
63+
64+
@Override
65+
public int hashCode()
66+
{
67+
return Objects.hash(name);
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rocks.trino.rest;
16+
17+
import io.trino.spi.NodeManager;
18+
import io.trino.spi.connector.Connector;
19+
import io.trino.spi.connector.ConnectorMetadata;
20+
import io.trino.spi.connector.ConnectorRecordSetProvider;
21+
import io.trino.spi.connector.ConnectorSplitManager;
22+
import io.trino.spi.connector.ConnectorTransactionHandle;
23+
import io.trino.spi.transaction.IsolationLevel;
24+
25+
public class RestConnector
26+
implements Connector
27+
{
28+
private final NodeManager nodeManager;
29+
private final Rest rest;
30+
31+
public RestConnector(NodeManager nodeManager, Rest rest)
32+
{
33+
this.nodeManager = nodeManager;
34+
this.rest = rest;
35+
}
36+
37+
@Override
38+
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly)
39+
{
40+
return new RestTransactionHandle(0);
41+
}
42+
43+
@Override
44+
public ConnectorMetadata getMetadata(ConnectorTransactionHandle transaction)
45+
{
46+
return new RestMetadata(rest);
47+
}
48+
49+
@Override
50+
public ConnectorSplitManager getSplitManager()
51+
{
52+
return new RestSplitManager(nodeManager);
53+
}
54+
55+
@Override
56+
public ConnectorRecordSetProvider getRecordSetProvider()
57+
{
58+
return new RestRecordSetProvider(rest);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package rocks.trino.rest;
16+
17+
import io.trino.spi.NodeManager;
18+
import io.trino.spi.connector.ColumnHandle;
19+
import io.trino.spi.connector.Connector;
20+
import io.trino.spi.connector.ConnectorContext;
21+
import io.trino.spi.connector.ConnectorFactory;
22+
import io.trino.spi.connector.ConnectorHandleResolver;
23+
import io.trino.spi.connector.ConnectorInsertTableHandle;
24+
import io.trino.spi.connector.ConnectorSplit;
25+
import io.trino.spi.connector.ConnectorTableHandle;
26+
import io.trino.spi.connector.ConnectorTableLayoutHandle;
27+
import io.trino.spi.connector.ConnectorTransactionHandle;
28+
29+
import java.util.Map;
30+
31+
public class RestConnectorFactory
32+
implements ConnectorFactory
33+
{
34+
private final RestFactory restFactory;
35+
private final String name;
36+
37+
public RestConnectorFactory(String name, RestFactory restFactory)
38+
{
39+
this.restFactory = restFactory;
40+
this.name = name;
41+
}
42+
43+
@Override
44+
public String getName()
45+
{
46+
return name;
47+
}
48+
49+
@Override
50+
public Connector create(String s, Map<String, String> config, ConnectorContext context)
51+
{
52+
NodeManager nodeManager = context.getNodeManager();
53+
54+
return new RestConnector(nodeManager, restFactory.create(config));
55+
}
56+
57+
@Override
58+
public ConnectorHandleResolver getHandleResolver()
59+
{
60+
return new ConnectorHandleResolver()
61+
{
62+
public Class<? extends ConnectorTableHandle> getTableHandleClass()
63+
{
64+
return RestTableHandle.class;
65+
}
66+
67+
public Class<? extends ColumnHandle> getColumnHandleClass()
68+
{
69+
return RestColumnHandle.class;
70+
}
71+
72+
public Class<? extends ConnectorSplit> getSplitClass()
73+
{
74+
return RestConnectorSplit.class;
75+
}
76+
77+
public Class<? extends ConnectorTableLayoutHandle> getTableLayoutHandleClass()
78+
{
79+
return RestConnectorTableLayoutHandle.class;
80+
}
81+
82+
@Override
83+
public Class<? extends ConnectorTransactionHandle> getTransactionHandleClass()
84+
{
85+
return RestTransactionHandle.class;
86+
}
87+
88+
@Override
89+
public Class<? extends ConnectorInsertTableHandle> getInsertTableHandleClass()
90+
{
91+
return RestInsertTableHandle.class;
92+
}
93+
};
94+
}
95+
}

0 commit comments

Comments
 (0)