Skip to content

Commit

Permalink
1.0.0.RC2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jprante committed Feb 3, 2014
1 parent d4f6bc1 commit 79ba3d0
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ES version Plugin Release date Command
------------- ----------- ----------------- -----------------------------------------------------------
0.90.3 0.90.3.1 Jan 31, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1emqDH9
0.90.10 0.90.10.2 Jan 31, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1a8Mcve
1.0.0.RC1 1.0.0.RC1.4 Jan 31, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1emNr9I
1.0.0.RC2 1.0.0.RC2.1 Feb 3, 2014 ./bin/plugin -install river-jdbc -url http://bit.ly/1bWPLzS
============= =========== ================= ===========================================================

Do not forget to restart the node after installing.
Expand Down
44 changes: 35 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.xbib.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-river-jdbc</artifactId>
<version>1.0.0.RC1.4</version>
<version>1.0.0.RC2.1</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -69,7 +69,7 @@
<properties>
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<elasticsearch.version>1.0.0.RC1</elasticsearch.version>
<elasticsearch.version>1.0.0.RC2</elasticsearch.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -107,6 +107,22 @@
</dependencies>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>es-plugin.properties</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>es-plugin.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -139,13 +155,6 @@
<skip>false</skip>
<forkMode>once</forkMode>
<useSystemClassLoader>false</useSystemClassLoader>
<!--
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
<log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
</systemPropertyVariables>
-->
<includes>
<include>**/*Tests.java</include>
</includes>
Expand Down Expand Up @@ -195,6 +204,23 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/org/xbib/elasticsearch/plugin/river/jdbc/Build.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

package org.xbib.elasticsearch.plugin.river.jdbc;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Properties;

public class Build {

private static final Build INSTANCE;

static {
String version = "NA";
String hash = "NA";
String hashShort = "NA";
String timestamp = "NA";
String date = "NA";

try {
InputStream in = Build.class.getResourceAsStream("/es-plugin.properties");
if (in == null) {
System.err.println("no es-plugin.properties in class path");
} else {
ByteArrayOutputStream out = new ByteArrayOutputStream();
copy(in, out);
Properties props = new Properties();
props.load(new StringReader(new String(out.toByteArray())));
version = props.getProperty("version");
hash = props.getProperty("hash");
if (!"NA".equals(hash)) {
hashShort = hash.substring(0, 7);
}
timestamp = props.getProperty("timestamp");
date = props.getProperty("date");
}
} catch (Throwable e) {
// just ignore...
}
INSTANCE = new Build(version, hash, hashShort, timestamp, date);
}

public static void copy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
}

private String version;

private String hash;

private String hashShort;

private String timestamp;

private String date;

Build(String version, String hash, String hashShort, String timestamp, String date) {
this.version = version;
this.hash = hash;
this.hashShort = hashShort;
this.timestamp = timestamp;
this.date = date;
}

public static Build getInstance() {
return INSTANCE;
}

public String getVersion() {
return version;
}

public String getHash() {
return hash;
}

public String getShortHash() {
return hashShort;
}

public String getTimestamp() {
return timestamp;
}

public String getDate() {
return date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public JDBCRiverPlugin() {

@Override
public String name() {
return JDBCRiver.NAME;
return JDBCRiver.NAME + "-" + Build.getInstance().getVersion();
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/xbib/elasticsearch/river/jdbc/RiverMouth.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public interface RiverMouth {

/**
* Set settings for Elasticsearch to be used in index creation
* @param settings
* @return
* @param settings the settings
* @return this river mouth
*/
RiverMouth setSettings(Map<String,Object> settings);

/**
* Set mapping for Elasticsearch to be used in mapping creation
* @param mapping
* @return
* @param mapping the mapping
* @return this river mouth
*/
RiverMouth setMapping(Map<String,Object> mapping);
RiverMouth setMapping(Map<String,Object> mapping);

/**
* Set index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ public Object parseType(ResultSet result, Integer i, int type, Locale locale)
* ResultSet object.
*/
case Types.ARRAY: {
Array a = result.getArray(i);
return a != null ? a.toString() : null;
return result.getArray(i).getArray();
}
/**
* The JDBC type BIGINT represents a 64-bit signed integer value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public StructuredObjectKeyValueStreamListener values(Collection<? extends Object
i = 0;
for (Object o : values) {
Map map = null;
// JSON?
try {
map = JsonXContent.jsonXContent.createParser(o.toString()).mapAndClose();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ public Values(Object values, O value, boolean sequence) {
this.value = vals;
}
}
O[] newValues = sequence && value != null ?
(O[]) value.toString().split(",") :
(O[]) new Object[]{value};
O[] newValues = null;
if (sequence && value != null) {
newValues = (O[]) value.toString().split(",");
} else if (value instanceof Object[]) {
newValues = (O[]) value;
} else {
newValues = (O[]) new Object[]{value};
}
for (O v : newValues) {
addValue(v);
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/es-plugin.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
plugin=org.xbib.elasticsearch.plugin.river.jdbc.JDBCRiverPlugin

version=${project.version}
hash=${buildNumber}
timestamp=${timestamp}
date=${tstamp}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
Expand Down Expand Up @@ -121,4 +122,48 @@ public void index(StructuredObject object, boolean create) throws IOException {
source.close(results);
source.close(statement);
}


/**
* Test JDBC Array to structured object array
*
* @param sql the array select statement
* @throws Exception
*/
@Test
@Parameters({"sql4", "res1", "res2"})
public void testArray(@Optional String sql, @Optional String res1, @Optional String res2) throws Exception {
if (sql == null) {
return;
}
List<? extends Object> params = newLinkedList();
final List<StructuredObject> result = newLinkedList();
RiverMouth mouth = new MockRiverMouth() {
@Override
public void index(StructuredObject object, boolean create) throws IOException {
if (object == null || object.source() == null) {
throw new IllegalArgumentException("object missing");
}
result.add(object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
KeyValueStreamListener listener = new StructuredObjectKeyValueStreamListener()
.output(mouth);
long rows = 0L;
source.beforeRows(results, listener);
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 2);
source.close(results);
source.close(statement);
Iterator<StructuredObject> it = result.iterator();
assertEquals(it.next().source().toString(), res1);
assertEquals(it.next().source().toString(), res2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand All @@ -25,7 +25,7 @@

public abstract class AbstractRiverTest extends Assert {

private static final ESLogger logger = Loggers.getLogger(AbstractRiverTest.class.getSimpleName());
private static final ESLogger logger = ESLoggerFactory.getLogger(AbstractRiverTest.class.getName());

protected static RiverSource source;

Expand Down Expand Up @@ -120,14 +120,17 @@ private void sqlScript(Connection connection, String resourceName) throws Except
BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String sql;
while ((sql = br.readLine()) != null) {

try {
logger.debug("executing {}", sql);
logger.trace("executing {}", sql);
Statement p = connection.createStatement();
p.execute(sql);
p.close();
} catch (SQLException e) {
// ignore
logger.error(sql + " failed. Reason: " + e.getMessage());
} finally {
connection.commit();
}
}
br.close();
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
log4j.rootLogger=INFO, out

# set this to DEBUG or TRACE for debugging the JDBC river
log4j.logger.org.xbib.elasticsearch=DEBUG
log4j.logger.org.xbib.elasticsearch=INFO

# race condition or something? suppress myriads of warnings...
log4j.logger.org.elasticsearch.discovery.zen.ping.multicast=ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ insert into "orders" ("customer", "department", "product", "quantity", "created"
insert into "orders" ("customer", "department", "product", "quantity", "created") values('Large', 'German Fruits', 'Bananas', 1, current_timestamp)
insert into "orders" ("customer", "department", "product", "quantity", "created") values('Huge', 'German Fruits', 'Oranges', 2, current_timestamp)
insert into "orders" ("customer", "department", "product", "quantity", "created") values('Good', 'German Fruits', 'Apples', 2, {ts '2012-06-01 15:52:25'})
insert into "orders" ("customer", "department", "product", "quantity", "created") values('Bad', 'English Fruits', 'Oranges', 3, {ts '2012-06-01 16:31:24'})
insert into "orders" ("customer", "department", "product", "quantity", "created") values('Bad', 'English Fruits', 'Oranges', 3, {ts '2012-06-01 16:31:24'})
create table "sal_emp" ("name" text, "pay_by_quarter" integer[])
INSERT INTO "sal_emp" VALUES ('Bill', ARRAY[10000, 10000, 10000, 10000])
INSERT INTO "sal_emp" VALUES ('Carol', ARRAY[20000, 25000, 25000, 25000])
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ drop table "departments"
drop table "customers"
drop table "products"
drop table "orders"
drop table "sal_emp"
Loading

0 comments on commit 79ba3d0

Please sign in to comment.