-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support short and long type in data frame
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
- Loading branch information
Showing
12 changed files
with
257 additions
and
2 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
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
47 changes: 47 additions & 0 deletions
47
common/src/main/java/org/opensearch/ml/common/dataframe/LongValue.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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataframe; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.FieldDefaults; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor | ||
@ToString | ||
public class LongValue implements ColumnValue { | ||
long value; | ||
|
||
@Override | ||
public ColumnType columnType() { | ||
return ColumnType.LONG; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return Long.valueOf(value).doubleValue(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeEnum(columnType()); | ||
out.writeLong(value); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
common/src/main/java/org/opensearch/ml/common/dataframe/ShortValue.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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataframe; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.FieldDefaults; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor | ||
@ToString | ||
public class ShortValue implements ColumnValue { | ||
short value; | ||
|
||
@Override | ||
public ColumnType columnType() { | ||
return ColumnType.SHORT; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public short shortValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return Short.valueOf(value).doubleValue(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeEnum(columnType()); | ||
out.writeShort(value); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
common/src/test/java/org/opensearch/ml/common/dataframe/LongValueTest.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,39 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataframe; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
import org.opensearch.common.xcontent.XContentType; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class LongValueTest { | ||
|
||
@Test | ||
public void longValue() { | ||
LongValue longValue = new LongValue((long)2); | ||
assertEquals(ColumnType.LONG, longValue.columnType()); | ||
assertEquals(2L, longValue.getValue()); | ||
assertEquals(2.0d, longValue.doubleValue(), 1e-5); | ||
} | ||
|
||
@Test | ||
public void testToXContent() throws IOException { | ||
LongValue longValue = new LongValue((long)2); | ||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); | ||
longValue.toXContent(builder); | ||
|
||
assertNotNull(builder); | ||
String jsonStr = Strings.toString(builder); | ||
assertEquals("{\"column_type\":\"LONG\",\"value\":2}", jsonStr); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
common/src/test/java/org/opensearch/ml/common/dataframe/ShortValueTest.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,39 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.dataframe; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
import org.opensearch.common.xcontent.XContentType; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class ShortValueTest { | ||
|
||
@Test | ||
public void shortValue() { | ||
ShortValue shortValue = new ShortValue((short)2); | ||
assertEquals(ColumnType.SHORT, shortValue.columnType()); | ||
assertEquals(2, shortValue.getValue()); | ||
assertEquals(2.0d, shortValue.doubleValue(), 1e-5); | ||
} | ||
|
||
@Test | ||
public void testToXContent() throws IOException { | ||
ShortValue shortValue = new ShortValue((short)2); | ||
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); | ||
shortValue.toXContent(builder); | ||
|
||
assertNotNull(builder); | ||
String jsonStr = Strings.toString(builder); | ||
assertEquals("{\"column_type\":\"SHORT\",\"value\":2}", jsonStr); | ||
} | ||
} |