You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/06/09 19:01:41 UTC
svn commit: r1601440 - in /db/derby/code/trunk/java:
optional/org/apache/derby/optional/lucene/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: rhillegas
Date: Mon Jun 9 17:01:40 2014
New Revision: 1601440
URL: http://svn.apache.org/r1601440
Log:
DERBY-6602: Make the lucene plugin handle null keys; commit derby-6602-01-aa-handleNullKeys.diff.
Modified:
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java?rev=1601440&r1=1601439&r2=1601440&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java Mon Jun 9 17:01:40 2014
@@ -102,6 +102,9 @@ public class LuceneQueryVTI extends Stri
private int _maxKeyID;
private int _docIDColumnID;
private int _scoreColumnID;
+
+ // true if last column read was null
+ private boolean _wasNull;
/////////////////////////////////////////////////////////////////////
//
@@ -144,6 +147,8 @@ public class LuceneQueryVTI extends Stri
*/
public String getRawColumn( int columnid ) throws SQLException
{
+ _wasNull = false;
+
try {
ScoreDoc scoreDoc = getScoreDoc();
int docID = scoreDoc.doc;
@@ -154,6 +159,22 @@ public class LuceneQueryVTI extends Stri
catch (IOException e) { throw LuceneSupport.wrap( e ); }
}
+ /** Handle boolean columns */
+ public boolean getBoolean( int columnid ) throws SQLException
+ {
+ String stringValue = getRawColumn( columnid );
+
+ if ( stringValue == null )
+ {
+ _wasNull = true;
+ return false;
+ }
+ else
+ {
+ return Boolean.valueOf( stringValue );
+ }
+ }
+
/** Handle float columns */
public float getFloat( int columnid ) throws SQLException
{
@@ -274,6 +295,8 @@ public class LuceneQueryVTI extends Stri
/** Handle integer columns */
public int getInt( int columnid ) throws SQLException
{
+ _wasNull = false;
+
try {
ScoreDoc scoreDoc = getScoreDoc();
int docID = scoreDoc.doc;
@@ -293,9 +316,14 @@ public class LuceneQueryVTI extends Stri
{
IndexableField field = _searcher.doc( getScoreDoc().doc ).getField( getColumnName( columnid ) );
- if ( field == null ) { return null; }
+ if ( field == null )
+ {
+ _wasNull = true;
+ return null;
+ }
else
{
+ _wasNull = false;
Number number = field.numericValue();
return number;
@@ -321,6 +349,7 @@ public class LuceneQueryVTI extends Stri
if ( ref != null ) { return ref.bytes; }
}
+ _wasNull = true;
return null;
}
else { throw invalidColumnPosition( columnid ); }
@@ -346,6 +375,7 @@ public class LuceneQueryVTI extends Stri
public boolean next()
throws SQLException
{
+ _wasNull = false;
if ( _schema == null ) { initScan(); }
_hitIndex++;
@@ -365,7 +395,12 @@ public class LuceneQueryVTI extends Stri
closeReader();
}
-
+
+ public boolean wasNull() throws SQLException
+ {
+ return _wasNull;
+ }
+
/**
* Be sure to close the Lucene IndexReader
*/
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java?rev=1601440&r1=1601439&r2=1601440&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java Mon Jun 9 17:01:40 2014
@@ -801,6 +801,9 @@ public class LuceneSupport implements Op
throw newSQLException( SQLState.LUCENE_UNSUPPORTED_TYPE, keyDescriptor.typeName );
}
+ // Lucene fields do not allow null values
+ if ( rs.wasNull() ) { field = null; }
+
if ( field != null ) { doc.add( field ); }
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java?rev=1601440&r1=1601439&r2=1601440&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java Mon Jun 9 17:01:40 2014
@@ -1009,6 +1009,84 @@ public class LuceneSupportPermsTest exte
dboConnection = DriverManager.getConnection( decryptDatabaseURL );
}
+ /**
+ * <p>
+ * Test that nulls are allowed in keys. See DERBY-6602.
+ * </p>
+ */
+ public void test_6602()
+ throws Exception
+ {
+ CD[] columnDescriptors = new CD[]
+ {
+ new CD( "bigintCol", "bigint" ),
+ new CD( "blobCol", "blob" ),
+ new CD( "booleanCol", "boolean" ),
+ new CD( "charCol", "char( 10 )" ),
+ new CD( "clobCol", "clob" ),
+ new CD( "dataCol", "date" ),
+ new CD( "decimalCol", "decimal" ),
+ new CD( "doubleCol", "double" ),
+ new CD( "floatCol", "float" ),
+ new CD( "intCol", "int" ),
+ new CD( "longvarcharCol", "long varchar" ),
+ new CD( "longvarcharforbitdataCol", "long varchar for bit data" ),
+ new CD( "numericCol", "numeric" ),
+ new CD( "realCol", "real" ),
+ new CD( "smallintCol", "smallint" ),
+ new CD( "timeCol", "time" ),
+ new CD( "varcharCol", "varchar( 10 )" ),
+ new CD( "varcharforbitdataCol", "varchar( 10 ) for bit data" ),
+ };
+
+ StringBuilder buffer = new StringBuilder();
+ buffer.append( "create table t_6602\n(\ttextcol clob" );
+ for ( CD cd : columnDescriptors )
+ {
+ buffer.append( ",\n\t" + cd.name + " " + cd.type );
+ }
+ buffer.append( "\n)" );
+
+ Connection dboConnection = openUserConnection( TEST_DBO );
+
+ goodStatement( dboConnection, LOAD_TOOL );
+ goodStatement( dboConnection, buffer.toString() );
+ goodStatement( dboConnection, "insert into t_6602( textcol ) values ( 'abc'), ( 'def')" );
+
+ for ( CD cd : columnDescriptors )
+ {
+ vet6602( dboConnection, cd );
+ }
+
+ goodStatement( dboConnection, "drop table t_6602" );
+ goodStatement( dboConnection, UNLOAD_TOOL );
+ }
+ private void vet6602( Connection conn, CD cd ) throws Exception
+ {
+ PreparedStatement ps = chattyPrepare
+ (
+ conn,
+ "call lucenesupport.createindex\n" +
+ "( 'TEST_DBO', 't_6602', 'textcol', 'org.apache.derby.optional.api.LuceneUtils.standardAnalyzer', ? )\n"
+ );
+ ps.setString( 1, cd.name );
+ ps.execute();
+
+ assertResults
+ (
+ conn,
+ "select * from table( t_6602__textcol( 'abc or def', null, 3, null ) ) tc order by documentid",
+ new String[][]
+ {
+ { null, "0", "0.35355338" },
+ { null, "1", "0.35355338" },
+ },
+ false
+ );
+
+ goodStatement( conn, "call lucenesupport.dropIndex( 'TEST_DBO', 't_6602', 'textcol' )" );
+ }
+
///////////////////////////////////////////////////////////////////////////////////
//
// MINIONS
@@ -1356,4 +1434,18 @@ public class LuceneSupportPermsTest exte
}
}
+ public static class CD
+ {
+ public final String name;
+ public final String type;
+
+ public CD( String Name, String Type )
+ {
+ name = Name;
+ type = Type;
+ }
+
+ public String toString() { return "[ " + name + ", " + type + " ]"; }
+ }
+
}