-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make transform ready for multi value aggregations and add support for…
… percentile
- Loading branch information
Hendrik Muhs
committed
Feb 3, 2020
1 parent
ff00052
commit 481b219
Showing
7 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...sform/src/main/java/org/elasticsearch/xpack/transform/utils/OutputFieldNameConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.transform.utils; | ||
|
||
public final class OutputFieldNameConverter { | ||
|
||
private OutputFieldNameConverter() {} | ||
|
||
public static String fromDouble(double d) { | ||
if (d == (long) d) return String.valueOf((long) d); | ||
else return String.valueOf(d).replace('.', '_'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../src/test/java/org/elasticsearch/xpack/transform/utils/OutputFieldNameConverterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.transform.utils; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class OutputFieldNameConverterTests extends ESTestCase { | ||
|
||
public void testFromDouble() { | ||
assertEquals("42_42", OutputFieldNameConverter.fromDouble(42.42)); | ||
// remove '.0' if possible | ||
assertEquals("42", OutputFieldNameConverter.fromDouble(42.0)); | ||
// digit limit | ||
assertEquals("42_42424242424242", OutputFieldNameConverter.fromDouble(42.4242424242424242424242424242424242)); | ||
// scientific notation keep the '.0' | ||
assertEquals("1_0E-100", OutputFieldNameConverter.fromDouble(1.0E-100)); | ||
// scientific with digits | ||
assertEquals("1_12345E-100", OutputFieldNameConverter.fromDouble(1.12345E-100)); | ||
// NaN (OutputFieldNameConverter clients should disallow that) | ||
assertEquals("NaN", OutputFieldNameConverter.fromDouble(Double.NaN)); | ||
// infinity | ||
assertEquals("-Infinity", OutputFieldNameConverter.fromDouble(Double.NEGATIVE_INFINITY)); | ||
} | ||
} |