forked from apache/calcite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-884] Web adapter (Henry Olson)
Some fix-ups (Julian Hyde): * Upgrade calcite; * Upgrade natty, jsoup; * Rename files, and move to org.apache.calcite.adapter.file package; * Add file adapter documentation and history (based on original README and HISTORY); * Add EMPS.html and DEPTS.html examples.
- Loading branch information
1 parent
1b11385
commit cf46d3b
Showing
32 changed files
with
2,490 additions
and
19 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
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,112 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to you 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. | ||
--> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.calcite</groupId> | ||
<artifactId>calcite</artifactId> | ||
<version>1.12.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<!-- The basics. --> | ||
<artifactId>calcite-file</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.12.0-SNAPSHOT</version> | ||
<name>Calcite File</name> | ||
<description>Calcite provider that reads files and URIs</description> | ||
|
||
<properties> | ||
<top.dir>${project.basedir}/..</top.dir> | ||
<build.timestamp>${maven.build.timestamp}</build.timestamp> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.joestelmach</groupId> | ||
<artifactId>natty</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.calcite</groupId> | ||
<artifactId>calcite-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.calcite</groupId> | ||
<artifactId>calcite-linq4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jsoup</groupId> | ||
<artifactId>jsoup</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>jalopy-maven-plugin</artifactId> | ||
<version>1.0-alpha-1</version> | ||
<configuration> | ||
<srcExcludesPattern>**/CsvTableScan.java</srcExcludesPattern> | ||
<failOnError>false</failOnError> | ||
<convention>${top.dir}src/main/config/jalopy.xml</convention> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.18</version> | ||
<configuration> | ||
<includes> | ||
<include>org/apache/calcite/adapter/file/FileSuite.java</include> | ||
</includes> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.8</version> | ||
<executions> | ||
<execution> | ||
<id>copy-dependencies</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/dependencies/</outputDirectory> | ||
<overWriteReleases>false</overWriteReleases> | ||
<overWriteSnapshots>false</overWriteSnapshots> | ||
<overWriteIfNewer>true</overWriteIfNewer> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
94 changes: 94 additions & 0 deletions
94
file/src/main/java/org/apache/calcite/adapter/file/FileEnumerator.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,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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 org.apache.calcite.adapter.file; | ||
|
||
import org.apache.calcite.linq4j.Enumerator; | ||
|
||
import org.jsoup.select.Elements; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* Wraps WebReader and FileRowConverter, enumerates tr Elements as | ||
* table rows. | ||
*/ | ||
class FileEnumerator implements Enumerator<Object> { | ||
|
||
private final Iterator<Elements> iterator; | ||
private final FileRowConverter converter; | ||
private final int[] fields; | ||
private Object current; | ||
|
||
public FileEnumerator(Iterator<Elements> iterator, | ||
FileRowConverter converter) { | ||
this.iterator = iterator; | ||
this.converter = converter; | ||
this.fields = identityList(this.converter.width()); | ||
} | ||
|
||
public FileEnumerator(Iterator<Elements> iterator, FileRowConverter converter, | ||
int[] fields) { | ||
this.iterator = iterator; | ||
this.converter = converter; | ||
this.fields = fields; | ||
} | ||
|
||
public Object current() { | ||
if (current == null) { | ||
this.moveNext(); | ||
} | ||
return current; | ||
} | ||
|
||
public boolean moveNext() { | ||
try { | ||
if (this.iterator.hasNext()) { | ||
final Elements row = this.iterator.next(); | ||
current = this.converter.toRow(row, this.fields); | ||
return true; | ||
} else { | ||
current = null; | ||
return false; | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
// required by linq4j Enumerator interface | ||
public void reset() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
// required by linq4j Enumerator interface | ||
public void close() { | ||
} | ||
|
||
/** Returns an array of integers {0, ..., n - 1}. */ | ||
private static int[] identityList(int n) { | ||
int[] integers = new int[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
integers[i] = i; | ||
} | ||
|
||
return integers; | ||
} | ||
|
||
} | ||
|
||
// End FileEnumerator.java |
86 changes: 86 additions & 0 deletions
86
file/src/main/java/org/apache/calcite/adapter/file/FileFieldType.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,86 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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 org.apache.calcite.adapter.file; | ||
|
||
import org.apache.calcite.adapter.java.JavaTypeFactory; | ||
import org.apache.calcite.linq4j.tree.Primitive; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Type of a field in a Web (HTML) table. | ||
* | ||
* <p>Usually, and unless specified explicitly in the header row, a field is | ||
* of type {@link #STRING}. But specifying the field type in the fields | ||
* makes it easier to write SQL. | ||
* | ||
* <p>Trivially modified from CsvFieldType. | ||
*/ | ||
enum FileFieldType { | ||
STRING(null, String.class), | ||
BOOLEAN(Primitive.BOOLEAN), | ||
BYTE(Primitive.BYTE), | ||
CHAR(Primitive.CHAR), | ||
SHORT(Primitive.SHORT), | ||
INT(Primitive.INT), | ||
LONG(Primitive.LONG), | ||
FLOAT(Primitive.FLOAT), | ||
DOUBLE(Primitive.DOUBLE), | ||
DATE(null, java.sql.Date.class), | ||
TIME(null, java.sql.Time.class), | ||
TIMESTAMP(null, java.sql.Timestamp.class); | ||
|
||
private final Primitive primitive; | ||
private final Class clazz; | ||
|
||
private static final Map<String, FileFieldType> MAP; | ||
|
||
static { | ||
ImmutableMap.Builder<String, FileFieldType> builder = | ||
ImmutableMap.builder(); | ||
for (FileFieldType value : values()) { | ||
builder.put(value.clazz.getSimpleName(), value); | ||
|
||
if (value.primitive != null) { | ||
builder.put(value.primitive.primitiveClass.getSimpleName(), value); | ||
} | ||
} | ||
MAP = builder.build(); | ||
} | ||
|
||
FileFieldType(Primitive primitive) { | ||
this(primitive, primitive.boxClass); | ||
} | ||
|
||
FileFieldType(Primitive primitive, Class clazz) { | ||
this.primitive = primitive; | ||
this.clazz = clazz; | ||
} | ||
|
||
public RelDataType toType(JavaTypeFactory typeFactory) { | ||
return typeFactory.createJavaType(clazz); | ||
} | ||
|
||
public static FileFieldType of(String typeString) { | ||
return MAP.get(typeString); | ||
} | ||
} | ||
|
||
// End FileFieldType.java |
Oops, something went wrong.