Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Upgrade to Scala 2.12.0 (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelapena authored Nov 22, 2016
1 parent 44628d8 commit 88c692f
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 158 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## 3.9.2 (Upcoming)
## 3.9.3 (Upcoming)

* Upgrade to Scala 2.12.0
* Avoid not required string interpolations in logging
* Avoid not required string interpolations in tracing

Expand Down
6 changes: 3 additions & 3 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
<description>Cassandra Lucene Index plugin</description>

<properties>
<scala.version>2.11.8</scala.version>
<scala.binary.version>2.11</scala.binary.version>
<scala.version>2.12.0</scala.version>
<scala.binary.version>2.12</scala.binary.version>
<scala.logging.version>3.5.0</scala.logging.version>
<scalatest.version>3.0.0</scalatest.version>
<scalatest.version>3.0.1</scalatest.version>
<cassandra.version>3.9</cassandra.version>
<lucene.version>5.5.1</lucene.version>
<jts.version>1.14.0</jts.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public class Schema implements Closeable {
public final Map<String, Mapper> mappers;

/** The wrapping all-in-one {@link Analyzer}. */
private final SchemaAnalyzer analyzer;
public final SchemaAnalyzer analyzer;

/** The default {@link Analyzer}. */
public final Analyzer defaultAnalyzer;

/** The names of the mapped cells. */
private final Set<String> mappedCells;
Expand All @@ -60,6 +63,7 @@ public class Schema implements Closeable {
*/
public Schema(Analyzer defaultAnalyzer, Map<String, Mapper> mappers, Map<String, Analyzer> analyzers) {
this.mappers = mappers;
this.defaultAnalyzer = defaultAnalyzer;
this.analyzer = new SchemaAnalyzer(defaultAnalyzer, analyzers, mappers);
mappedCells = mappers.values()
.stream()
Expand All @@ -68,24 +72,6 @@ public Schema(Analyzer defaultAnalyzer, Map<String, Mapper> mappers, Map<String,
.collect(Collectors.toSet());
}

/**
* Returns the used {@link Analyzer}.
*
* @return the used {@link Analyzer}
*/
public Analyzer analyzer() {
return analyzer;
}

/**
* Returns the default {@link Analyzer}.
*
* @return the default {@link Analyzer}
*/
public Analyzer defaultAnalyzer() {
return analyzer.getDefaultAnalyzer().analyzer();
}

/**
* Returns the {@link Analyzer} identified by the specified field name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author Andres de la Pena {@literal <[email protected]>}
*/
public class SchemaAnalyzer extends DelegatingAnalyzerWrapper {

private final TokenLengthAnalyzer defaultAnalyzer;
private final Map<String, TokenLengthAnalyzer> fieldAnalyzers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public SnowballAnalyzer(String language, CharArraySet stopwords) {

/** {@inheritDoc} */
@Override
protected TokenStreamComponents createComponents(String fieldName) {
protected Analyzer.TokenStreamComponents createComponents(String fieldName) {
final Tokenizer source = new StandardTokenizer();
TokenStream result = new StandardFilter(source);
result = new LowerCaseFilter(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Set<String> postProcessingFields() {
@Override
public Query doQuery(Schema schema) {
try {
Analyzer analyzer = schema.analyzer();
Analyzer analyzer = schema.analyzer;
QueryParser queryParser = new QueryParser(defaultField, analyzer);
queryParser.setAllowLeadingWildcard(true);
queryParser.setLowercaseExpandedTerms(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final Query doQuery(Schema schema) {
SingleColumnMapper.class.getSimpleName(),
mapper);
}
return doQuery((SingleColumnMapper<?>) mapper, schema.analyzer());
return doQuery((SingleColumnMapper<?>) mapper, schema.analyzer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final Query doQuery(Schema schema) {
} else if (!type.isAssignableFrom(mapper.getClass())) {
throw new IndexException("Field '{}' requires a mapper of type '{}' but found '{}'", field, type, mapper);
}
return doQuery((T) mapper, schema.analyzer());
return doQuery((T) mapper, schema.analyzer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import java.util.{Collections, Optional}
import java.{util => java}

import com.stratio.cassandra.lucene.search.Search
import com.stratio.cassandra.lucene.util.JavaConversions._
import com.stratio.cassandra.lucene.util.Logging
import org.apache.cassandra.config.{CFMetaData, ColumnDefinition}
import org.apache.cassandra.cql3.Operator
Expand Down Expand Up @@ -117,7 +116,7 @@ class Index(table: ColumnFamilyStore, indexMetadata: IndexMetadata)
*
* @return the Index's backing storage table
*/
override def getBackingTable: Optional[ColumnFamilyStore] = None
override def getBackingTable: Optional[ColumnFamilyStore] = Optional.empty()

/** Return a task which performs a blocking flush of the index's data to persistent storage.
*
Expand Down Expand Up @@ -310,10 +309,7 @@ class Index(table: ColumnFamilyStore, indexMetadata: IndexMetadata)
override def searcherFor(command: ReadCommand): Searcher = {
logger.trace(s"Getting searcher for $command")
try {
new Searcher {
override def search(controller: ReadExecutionController): UnfilteredPartitionIterator =
service.search(command, controller)
}
controller => service.search(command, controller)
} catch {
case e: Exception =>
logger.error(s"Error getting searcher for command: $command", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ class IndexPagingState(var remaining: Int) {
val cfs = Keyspace.open(command.metadata.ksName).getColumnFamilyStore(command.metadata.cfName)
for (expr <- command.rowFilter.getExpressions.asScala) {
for (index <- cfs.indexManager.listIndexes.asScala) {
if (index.isInstanceOf[Index] && index.supportsExpression(
expr.column,
expr.operator)) return expr
if (index.isInstanceOf[Index] && index.supportsExpression(expr.column, expr.operator))
return expr
}
}
throw new IndexException("Not found expression")
Expand All @@ -86,7 +85,7 @@ class IndexPagingState(var remaining: Int) {
@throws[ReflectiveOperationException]
def rewrite(query: ReadQuery): Unit = query match {
case group: SinglePartitionReadCommand.Group =>
group.commands.asScala.foreach(rewrite)
group.commands.forEach(rewrite)
case read: ReadCommand =>
val expression = indexExpression(read)
val oldValue = expressionValueField.get(expression).asInstanceOf[ByteBuffer]
Expand Down Expand Up @@ -123,7 +122,7 @@ class IndexPagingState(var remaining: Int) {
while (partition.hasNext) {
val newRowIterator = new SingleRowIterator(partition)
rowIterators += newRowIterator
entries.put(key, newRowIterator.row.clustering)
entries.put(key, newRowIterator.row.clustering())
if (remaining > 0) remaining -= 1
count += 1
}
Expand Down Expand Up @@ -175,7 +174,7 @@ class IndexPagingState(var remaining: Int) {
if (hasMorePages) new PagingState(toByteBuffer, null, remaining, remaining) else null
}

/** @inheritdoc */
/** @inheritdoc*/
override def toString: String = {
MoreObjects.toStringHelper(this).add("remaining", remaining).add("entries", entries).toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ sealed abstract class IndexPostProcessor[A <: ReadQuery](service: IndexService)
val doc = new Document
val cols = service.columns(key, row)
service.keyIndexableFields(key, row).foreach(doc.add)
service.schema.postProcessingIndexableFields(cols, search).asScala.foreach(doc.add)
service.schema.postProcessingIndexableFields(cols, search).forEach(doc add _)
doc
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ class IndexQueryHandler extends QueryHandler with Logging {
val expressions = select.getRowFilter(options).getExpressions
val cfs = Keyspace.open(select.keyspace).getColumnFamilyStore(select.columnFamily)
val indexes = cfs.indexManager.listIndexes.asScala.collect { case index: Index => index }
expressions.asScala.foreach {
expressions.forEach {
case expression: CustomExpression =>
val clazz = expression.getTargetIndex.options.get(IndexTarget.CUSTOM_INDEX_OPTION_NAME)
if (clazz == classOf[Index].getCanonicalName) {
val index = cfs.indexManager.getIndex(expression.getTargetIndex).asInstanceOf[Index]
map += expression -> index
}
case expr =>
case expr: Expression =>
indexes.filter(_.supportsExpression(expr.column, expr.operator)).foreach(map.put(expr, _))
}
map.toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class IndexService(val table: ColumnFamilyStore, val indexMetadata: Ind
val lucene = new FSIndex(
idxName,
options.path,
options.schema.analyzer(),
options.schema.analyzer,
options.refreshSeconds,
options.ramBufferMB,
options.maxMergeMB,
Expand Down Expand Up @@ -227,7 +227,7 @@ abstract class IndexService(val table: ColumnFamilyStore, val indexMetadata: Ind
} else {
val doc = new Document
keyIndexableFields(key, row).foreach(doc.add)
fields.asScala.foreach(doc.add)
fields.forEach(doc add _)
lucene.upsert(t, doc)
}
})
Expand Down Expand Up @@ -358,7 +358,7 @@ abstract class IndexService(val table: ColumnFamilyStore, val indexMetadata: Ind
*/
def validate(update: PartitionUpdate) {
val key = update.partitionKey
update.asScala.foreach(row => schema.validate(columns(key, row)))
update.forEach(row => schema.validate(columns(key, row)))
}

/** @inheritdoc */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ class IndexWriterWide(
read(key, clusterings)
.asScala
.map(_.asInstanceOf[Row])
.foreach(row => rows.put(row.clustering, row))
.foreach(row => rows.put(row.clustering(), row))

// Write rows
for ((clustering, row) <- rows.asScala) {
rows.forEach((clustering, row) => {
if (row.hasLiveData(nowInSec)) {
tracer.trace("Lucene index writing document")
service.upsert(key, row, nowInSec)
} else {
tracer.trace("Lucene index deleting document")
service.delete(key, row)
}
}
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ClusteringMapper(metadata: CFMetaData) {
* @return a byte buffer representing `clustering`
*/
def byteBuffer(clustering: Clustering): ByteBuffer = {
(clusteringType.builder /: clustering.getRawValues) (_ add _) build
(clusteringType.builder /: clustering.getRawValues) (_ add _) build()
}

/** Returns the [[String]] human-readable representation of the specified [[ClusteringPrefix]].
Expand Down Expand Up @@ -168,7 +168,7 @@ class ClusteringMapper(metadata: CFMetaData) {
*/
def query(key: DecoratedKey, filter: ClusteringIndexSliceFilter): Query = {
(new BooleanQuery.Builder /: filter.requestedSlices.asScala) (
(builder, slice) => builder.add(query(key, slice), SHOULD)) build
(builder, slice) => builder.add(query(key, slice), SHOULD)).build()
}

}
Expand Down Expand Up @@ -247,23 +247,15 @@ object ClusteringMapper {
* @param mapper the primary key mapper to be used
*/
class ClusteringSort(mapper: ClusteringMapper) extends SortField(
FIELD_NAME, new FieldComparatorSource {
override def newComparator(
field: String,
hits: Int,
sortPos: Int,
reversed: Boolean): FieldComparator[_] = {
new TermValComparator(hits, field, false) {
override def compareValues(t1: BytesRef, t2: BytesRef): Int = {
val comp = compareUnsigned(t1.bytes, 0, PREFIX_SIZE, t2.bytes, 0, PREFIX_SIZE)
if (comp != 0) return comp
val bb1 = ByteBuffer.wrap(t1.bytes, PREFIX_SIZE, t1.length - PREFIX_SIZE)
val bb2 = ByteBuffer.wrap(t2.bytes, PREFIX_SIZE, t2.length - PREFIX_SIZE)
val clustering1 = mapper.clustering(bb1)
val clustering2 = mapper.clustering(bb2)
mapper.comparator.compare(clustering1, clustering2)
}
}
FIELD_NAME, (field, hits, sortPos, reversed) => new TermValComparator(hits, field, false) {
override def compareValues(t1: BytesRef, t2: BytesRef): Int = {
val comp = compareUnsigned(t1.bytes, 0, PREFIX_SIZE, t2.bytes, 0, PREFIX_SIZE)
if (comp != 0) return comp
val bb1 = ByteBuffer.wrap(t1.bytes, PREFIX_SIZE, t1.length - PREFIX_SIZE)
val bb2 = ByteBuffer.wrap(t2.bytes, PREFIX_SIZE, t2.length - PREFIX_SIZE)
val clustering1 = mapper.clustering(bb1)
val clustering2 = mapper.clustering(bb2)
mapper.comparator.compare(clustering1, clustering2)
}
}) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ case class ExpressionMapper(tableMetadata: CFMetaData, indexMetadata: IndexMetad

// Copy row
val builder = BTreeRow.unsortedBuilder(nowInSec)
builder.newRow(row.clustering)
builder.newRow(row.clustering())
builder.addRowDeletion(row.deletion)
builder.addPrimaryKeyLivenessInfo(row.primaryKeyLivenessInfo)
row.cells.asScala.foreach(builder.addCell)
row.cells.forEach(builder addCell _)

// Add score cell
val timestamp = row.primaryKeyLivenessInfo.timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class KeyMapper(metadata: CFMetaData) {
* @return the byte buffer representing `clustering`
*/
private def byteBuffer(clustering: Clustering): ByteBuffer = {
(clusteringType.builder /: clustering.getRawValues) (_ add _) build
(clusteringType.builder /: clustering.getRawValues) (_ add _) build()
}

/** Returns the Lucene [[IndexableField]] representing the specified primary key.
Expand Down Expand Up @@ -98,7 +98,7 @@ class KeyMapper(metadata: CFMetaData) {
*/
def query(key: DecoratedKey, filter: ClusteringIndexNamesFilter): Query = {
(new BooleanQuery.Builder /: filter.requestedRows.asScala) (
(builder, clustering) => builder.add(query(key, clustering), SHOULD)) build
(builder, clustering) => builder.add(query(key, clustering), SHOULD)) build()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,11 @@ object PartitionMapper {
* @author Andres de la Pena `[email protected]`
*/
class PartitionSort(mapper: PartitionMapper) extends SortField(
FIELD_NAME, new FieldComparatorSource {
override def newComparator(
field: String,
hits: Int,
sortPos: Int,
reversed: Boolean): FieldComparator[_] = {
new TermValComparator(hits, field, false) {
override def compareValues(t1: BytesRef, t2: BytesRef): Int = {
val bb1 = ByteBufferUtils.byteBuffer(t1)
val bb2 = ByteBufferUtils.byteBuffer(t2)
mapper.validator.compare(bb1, bb2)
}
}
FIELD_NAME, (field, hits, sortPos, reversed) => new TermValComparator(hits, field, false) {
override def compareValues(t1: BytesRef, t2: BytesRef): Int = {
val bb1 = ByteBufferUtils.byteBuffer(t1)
val bb2 = ByteBufferUtils.byteBuffer(t2)
mapper.validator.compare(bb1, bb2)
}
}) {

Expand Down
Loading

0 comments on commit 88c692f

Please sign in to comment.