Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Markup performance improved, SQL init and test script added, import b…
Browse files Browse the repository at this point in the history
…ug fixed
  • Loading branch information
Camilleh9 committed Dec 6, 2014
1 parent 92df4d1 commit 725a694
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 527 deletions.
Binary file modified OSM2Hive.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions res/sql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- SQL Init file for OSM2Hive
-- Initializes OSM2Hive functions
-- Command: hive -i /path/to/init.sql

-- Define project path
SET O2H_PATH=/home/adrien/Documents/Programmation/Java/OSM2Hive;

-- Add JAR
ADD JAR ${hiveconf:O2H_PATH}/OSM2Hive.jar;

-- Create functions
CREATE TEMPORARY FUNCTION OSMImportNodes AS 'info.pavie.osm2hive.controller.HiveNodeImporter';
CREATE TEMPORARY FUNCTION OSMImportWays AS 'info.pavie.osm2hive.controller.HiveWayImporter';
CREATE TEMPORARY FUNCTION OSMImportRelations AS 'info.pavie.osm2hive.controller.HiveRelationImporter';
36 changes: 36 additions & 0 deletions res/sql/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- SQL Test file for OSM2Hive
-- Creates and loads OSM data from res/xml/sample.osm file
-- Command: hive -f /path/to/test.sql

-- Define project path
SET O2H_PATH=/home/adrien/Documents/Programmation/Java/OSM2Hive;

-- Add JAR
ADD JAR ${hiveconf:O2H_PATH}/OSM2Hive.jar;

-- Create functions
CREATE TEMPORARY FUNCTION OSMImportNodes AS 'info.pavie.osm2hive.controller.HiveNodeImporter';
CREATE TEMPORARY FUNCTION OSMImportWays AS 'info.pavie.osm2hive.controller.HiveWayImporter';
CREATE TEMPORARY FUNCTION OSMImportRelations AS 'info.pavie.osm2hive.controller.HiveRelationImporter';

-- Load data
DROP TABLE o2h_test;
CREATE TABLE o2h_test(osm_content STRING) STORED AS TEXTFILE;
LOAD DATA LOCAL INPATH '${hiveconf:O2H_PATH}/res/xml/sample.osm' OVERWRITE INTO TABLE o2h_test;

-- Create test tables
-- Check XML file to compare with created tables
-- Nodes, must contain 4 nodes (N298884269, N261728686, N1831881213, N298884272)
DROP TABLE o2h_test_nodes;
CREATE TABLE o2h_test_nodes AS SELECT OSMImportNodes(osm_content) FROM o2h_test;
SELECT * FROM o2h_test_nodes;

-- Ways, must contain 1 way (W26659127)
DROP TABLE o2h_test_ways;
CREATE TABLE o2h_test_ways AS SELECT OSMImportWays(osm_content) FROM o2h_test;
SELECT * FROM o2h_test_ways;

-- Relations, must contain 1 relation (R56688)
DROP TABLE o2h_test_relations;
CREATE TABLE o2h_test_relations AS SELECT OSMImportRelations(osm_content) FROM o2h_test;
SELECT * FROM o2h_test_relations;
2 changes: 1 addition & 1 deletion src/main/info/pavie/osm2hive/controller/HiveImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected Element preprocess(Object[] args, String markups) throws InvalidMarkup
//Parse the received line if necessary
String line = (String) stringOI.getPrimitiveJavaObject(args[0]);

if(line.matches(".*("+markups+").*")) {
if(line.matches(".*?\\x3C\\x2F?("+markups+").*?")) {
parser.parse(line);
result = (parser.isElementReady()) ? parser.getCurrentElement() : null;
}
Expand Down
31 changes: 28 additions & 3 deletions src/main/info/pavie/osm2hive/controller/OSMParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import info.pavie.osm2hive.model.xml.InvalidMarkupException;
import info.pavie.osm2hive.model.xml.Markup;

import java.util.LinkedList;
import java.util.List;

/**
* This class parses OSM XML file, line by line.
* It uses the XML {@link Markup} parser, and create {@link Element}s objects.
Expand All @@ -20,13 +23,21 @@ public class OSMParser {
/** Is the current element ready (ie completely parsed) ? **/
private boolean isCurrentReady;

//TODO Remove, debug purposes only
/** Last read lines **/
private List<String> lastLines;
//ENDTODO

//CONSTRUCTORS
/**
* Class constructor
*/
public OSMParser() {
current = null;
isCurrentReady = false;
//TODO Remove, debug purposes only
lastLines = new LinkedList<String>();
//ENDTODO
}

//ACCESSORS
Expand Down Expand Up @@ -79,6 +90,13 @@ public static String getId(String type, String ref) {
public void parse(String line) throws InvalidMarkupException {
Markup m = new Markup(line); //Parse the line

//TODO Remove, debug purposes only
lastLines.add(line);
if(lastLines.size() > 20) {
lastLines.remove(0);
}
//ENDTODO

switch(m.getType()) {
//Opening markup, for example <node>
case Markup.START:
Expand Down Expand Up @@ -220,12 +238,19 @@ private void endMarkup(Markup m) {
if(m.getName().equals("node") || m.getName().equals("way") || m.getName().equals("relation")) {
//Add element to list, and delete current
if(current != null) {
if( (m.getName().equals("way") && ((Way) current).getNodes().size() >= 2)
|| m.getName().equals("node")
|| (m.getName().equals("relation") && ((Relation) current).getMembers().size() > 0)) {
if( (m.getName().equals("way") && current instanceof Way && ((Way) current).getNodes().size() >= 2)
|| (m.getName().equals("node") && current instanceof Node)
|| (m.getName().equals("relation") && current instanceof Relation && ((Relation) current).getMembers().size() > 0)) {

isCurrentReady = true;
}
} else {
//TODO Remove, debug purposes only
System.err.println("End markup not matching: "+m.getName()+" with current object "+current);
for(String s : lastLines) {
System.err.println(s);
}
//ENDTODO
}
} else {
isCurrentReady = false;
Expand Down
Loading

0 comments on commit 725a694

Please sign in to comment.