Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@

public class CascadeExtractionFn implements ExtractionFn
{
private final ExtractionFn extractionFns[];
private final ChainedExtractionFn chainedExtractionFn;
private final ChainedExtractionFn DEFAULT_CHAINED_EXTRACTION_FN = new ChainedExtractionFn(
private static final ExtractionFn DEFAULT_CHAINED_EXTRACTION_FN = new ChainedExtractionFn(
new ExtractionFn()
{
public byte[] getCacheKey()
{
return new byte[0];
}

public String apply(Object value)
{
return null;
}

public String apply(String value)
{
return null;
Expand Down Expand Up @@ -73,6 +66,9 @@ public String toString()
null
);

private final ExtractionFn extractionFns[];
private final ExtractionFn chainedExtractionFn;

@JsonCreator
public CascadeExtractionFn(
@JsonProperty("extractionFns") ExtractionFn[] extractionFn
Expand Down Expand Up @@ -106,12 +102,6 @@ public byte[] getCacheKey()
return Bytes.concat(cacheKey, chainedExtractionFn.getCacheKey());
}

@Override
public String apply(Object value)
{
return chainedExtractionFn.apply(value);
}

@Override
public String apply(String value)
{
Expand Down Expand Up @@ -171,7 +161,7 @@ public String toString()
"extractionFns=[" + chainedExtractionFn.toString() + "]}";
}

private class ChainedExtractionFn
private static class ChainedExtractionFn implements ExtractionFn
{
private final ExtractionFn fn;
private final ChainedExtractionFn child;
Expand All @@ -189,19 +179,14 @@ public byte[] getCacheKey()
return (child != null) ? Bytes.concat(fnCacheKey, child.getCacheKey()) : fnCacheKey;
}

public String apply(Object value)
{
return fn.apply((child != null) ? child.apply(value) : value);
}

public String apply(String value)
{
return fn.apply((child != null) ? child.apply(value) : value);
}

public String apply(long value)
{
return fn.apply((child != null) ? child.apply(value) : value);
return child != null ? fn.apply(child.apply(value)) : fn.apply(value);
}

public boolean preservesOrdering()
Expand All @@ -219,6 +204,7 @@ public ExtractionType getExtractionType()
}
}

@Override
public boolean equals(Object o)
{
if (this == o) {
Expand All @@ -240,6 +226,7 @@ public boolean equals(Object o)
return true;
}

@Override
public int hashCode()
{
int result = fn.hashCode();
Expand All @@ -249,6 +236,7 @@ public int hashCode()
return result;
}

@Override
public String toString()
{
return (child != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@

public abstract class DimExtractionFn implements ExtractionFn
{
@Override
public String apply(Object value)
{
return apply(value == null ? null : value.toString());
}

@Override
public String apply(long value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public interface ExtractionFn
*
* @return a value that should be used instead of the original
*/
public String apply(Object value);

public String apply(String value);

public String apply(long value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ public byte[] getCacheKey()
return new byte[]{ExtractionCacheHelper.CACHE_TYPE_ID_IDENTITY};
}

@Override
public String apply(Object value)
{
return value == null ? null : Strings.emptyToNull(value.toString());
}

@Override
public String apply(String value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,16 @@ public byte[] getCacheKey()
.array();
}

@Override
public String apply(Object value)
{
return Strings.emptyToNull(fn.apply(value));
}

@Override
public String apply(String value)
{
return this.apply((Object) value);
return Strings.emptyToNull(fn.apply(value));
}

@Override
public String apply(long value)
{
return this.apply((Long) value);
return Strings.emptyToNull(fn.apply(value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,4 @@ public byte[] getCacheKey()
.put(localeBytes)
.array();
}

@Override
public String apply(Object value)
{
return apply(String.valueOf(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,10 @@ public String apply(long value)
return formatter.print(value);
}

@Override
public String apply(Object value)
{
return formatter.print(new DateTime(value));
}

@Override
public String apply(String value)
{
return apply((Object) value);
return formatter.print(new DateTime(value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,4 @@ public byte[] getCacheKey()
.put(localeBytes)
.array();
}

@Override
public String apply(Object value)
{
return apply(String.valueOf(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public Row apply(Row input)
Map<String, Object> event = Maps.newHashMap(preMapRow.getEvent());
for (String dim : optimizedDims) {
final Object eventVal = event.get(dim);
event.put(dim, extractionFnMap.get(dim).apply(eventVal));
event.put(dim, extractionFnMap.get(dim).apply((String)eventVal));
}
return new MapBasedRow(preMapRow.getTimestamp(), event);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.druid.jackson.DefaultObjectMapper;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Iterator;
Expand Down Expand Up @@ -69,11 +70,12 @@ public void testLongs() throws Exception
Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false).apply(1234L));
}

@Test
// we don't have float type dimension. no need to test what is not possible
@Ignore
public void testFloats() throws Exception
{
String typeOf = "function(x) {\nreturn typeof x\n}";
Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false).apply(1234.0));
// String typeOf = "function(x) {\nreturn typeof x\n}";
// Assert.assertEquals("number", new JavaScriptExtractionFn(typeOf, false).apply(1234.0F));
}

@Test
Expand Down