paul-rogers commented on a change in pull request #1858: DRILL-4303: ESRI Shapefile (shp) Format Plugin URL: https://github.com/apache/drill/pull/1858#discussion_r336791821
########## File path: contrib/format-esri/src/main/java/org/apache/drill/exec/store/esri/ShpBatchReader.java ########## @@ -0,0 +1,334 @@ +/* + * 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.drill.exec.store.esri; + +import com.esri.core.geometry.Geometry; +import com.esri.core.geometry.GeometryCursor; +import com.esri.core.geometry.ShapefileReader; +import com.esri.core.geometry.SpatialReference; +import com.esri.core.geometry.ogc.OGCGeometry; +import org.apache.drill.common.exceptions.UserException; +import org.apache.drill.common.types.TypeProtos; +import org.apache.drill.exec.physical.impl.scan.file.FileScanFramework.FileSchemaNegotiator; +import org.apache.drill.exec.physical.impl.scan.framework.ManagedReader; +import org.apache.drill.exec.physical.resultSet.ResultSetLoader; +import org.apache.drill.exec.physical.resultSet.RowSetLoader; +import org.apache.drill.exec.record.metadata.ColumnMetadata; +import org.apache.drill.exec.record.metadata.MetadataUtils; +import org.apache.drill.exec.record.metadata.SchemaBuilder; +import org.apache.drill.exec.vector.accessor.ScalarWriter; +import org.apache.drill.exec.vector.accessor.TupleWriter; +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.mapred.FileSplit; +import org.jamel.dbf.DbfReader; +import org.jamel.dbf.structure.DbfField; +import org.joda.time.Instant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ShpBatchReader implements ManagedReader<FileSchemaNegotiator> { + + private FileSplit split; + private BufferedReader reader; + private ResultSetLoader loader; + private ShpReaderConfig readerConfig; + private Path hadoopShp; + private Path hadoopDbf; + private Path hadoopPrj; + private FSDataInputStream fileReaderShp = null; + private FSDataInputStream fileReaderDbf = null; + private FSDataInputStream fileReaderPrj = null; + private GeometryCursor geomCursor = null; + private DbfReader dbfReader = null; + private ScalarWriter gidWriter; + private ScalarWriter sridWriter; + private ScalarWriter shapeTypeWriter; + private ScalarWriter geomWriter; + private RowSetLoader rowWriter; + + + private int srid; + private SpatialReference spatialReference; + private static final Logger logger = LoggerFactory.getLogger(ShpBatchReader.class); + + public static class ShpReaderConfig { + protected final ShpFormatPlugin plugin; + + public ShpReaderConfig(ShpFormatPlugin plugin) { + this.plugin = plugin; + } + } + + public ShpBatchReader(ShpReaderConfig readerConfig) { + this.readerConfig = readerConfig; + } + + @Override + public boolean open(FileSchemaNegotiator negotiator) { + this.split = negotiator.split(); + this.hadoopShp = split.getPath(); + this.hadoopDbf = new Path(split.getPath().toString().replace("shp", "dbf")); + this.hadoopPrj = new Path(split.getPath().toString().replace("shp", "prj")); + + openFile(negotiator); + SchemaBuilder builder = new SchemaBuilder(); + builder.addNullable("gid", TypeProtos.MinorType.INT); + builder.addNullable("srid", TypeProtos.MinorType.INT); + builder.addNullable("shapeType", TypeProtos.MinorType.VARCHAR); + builder.addNullable("geom", TypeProtos.MinorType.VARBINARY); + + negotiator.setTableSchema(builder.buildSchema(), false); Review comment: Nit: because the schema is fixed, you can do something like: ``` BatchSchema schema = new SchemaBuilder() .addNullable("gid", TypeProtos.MinorType.INT) ... .build(); ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services