├── src ├── test │ ├── resources │ │ ├── data_join_a.csv │ │ ├── loader_test.csv │ │ ├── loader_test_header.csv │ │ ├── data_join_b.csv │ │ ├── data_index.csv │ │ ├── data_grouping.csv │ │ ├── users.csv │ │ ├── data_group_agg_result.csv │ │ ├── data_group_agg_pre.csv │ │ ├── legacy_meta.dfm │ │ └── loader_test.csv.meta │ └── java │ │ └── de │ │ └── unknownreality │ │ └── dataframe │ │ ├── value │ │ ├── impl │ │ │ ├── NumberValueTypeTest.java │ │ │ ├── ByteValueTypeTest.java │ │ │ ├── LongValueTypeTest.java │ │ │ ├── FloatValueTypeTest.java │ │ │ ├── ShortValueTypeTest.java │ │ │ ├── DoubleValueTypeTest.java │ │ │ ├── StringValueTypeTest.java │ │ │ ├── BooleanValueTypeTest.java │ │ │ ├── IntegerValueTypeTest.java │ │ │ ├── CharacterValueTypeTest.java │ │ │ └── AbstractValueTypeTest.java │ │ └── ValueTypeTest.java │ │ ├── DataFrameWriterTest.java │ │ ├── ColumnConverterTest.java │ │ └── DataFrameConverterTest.java └── main │ ├── java │ └── de │ │ └── unknownreality │ │ └── dataframe │ │ ├── join │ │ ├── JoinOperation.java │ │ ├── JoinedDataFrame.java │ │ ├── JoinColumn.java │ │ ├── JoinUtil.java │ │ └── impl │ │ │ ├── LeftJoin.java │ │ │ └── RightJoin.java │ │ ├── common │ │ ├── header │ │ │ ├── TypeHeader.java │ │ │ └── Header.java │ │ ├── KeyValueGetter.java │ │ ├── RowIterable.java │ │ ├── RowIterator.java │ │ ├── StringUtil.java │ │ ├── mapping │ │ │ └── MappedColumn.java │ │ ├── DataContainer.java │ │ ├── row │ │ │ └── BasicRow.java │ │ └── math │ │ │ └── Quantiles.java │ │ ├── type │ │ ├── ValueTypeRuntimeException.java │ │ ├── impl │ │ │ ├── ComparableType.java │ │ │ ├── NumberType.java │ │ │ ├── LongType.java │ │ │ ├── ByteType.java │ │ │ ├── FloatType.java │ │ │ ├── ShortType.java │ │ │ ├── DoubleType.java │ │ │ ├── IntegerType.java │ │ │ ├── CharacterType.java │ │ │ ├── BooleanType.java │ │ │ └── StringType.java │ │ ├── ValueTypeNotFoundException.java │ │ └── ValueType.java │ │ ├── filter │ │ ├── DataFrameFilterRuntimeException.java │ │ ├── compile │ │ │ ├── PredicateCompilerException.java │ │ │ ├── BooleanFilterVisitor.java │ │ │ ├── PredicateCompileErrorListener.java │ │ │ ├── PredicateOperation.java │ │ │ ├── RegexFilterVisitor.java │ │ │ ├── FieldFilterOperation.java │ │ │ ├── PredicateCompiler.java │ │ │ └── ColumnPredicateFilterVisitor.java │ │ └── MatchPredicate.java │ │ ├── io │ │ ├── FormatSettings.java │ │ ├── WriteFormat.java │ │ ├── WriterBuilder.java │ │ ├── ReadFormat.java │ │ ├── FileFormat.java │ │ ├── DataIterator.java │ │ ├── ReaderBuilder.java │ │ ├── GZipUtil.java │ │ ├── ColumnInformation.java │ │ └── DataReader.java │ │ ├── print │ │ ├── ValueFormatter.java │ │ ├── PrintFormat.java │ │ ├── DefaultValueFormatter.java │ │ ├── DefaultNumberFormatter.java │ │ └── ColumnPrintSettings.java │ │ ├── group │ │ ├── GroupUtil.java │ │ ├── aggr │ │ │ └── AggregateFunction.java │ │ └── GroupRow.java │ │ ├── MapFunction.java │ │ ├── csv │ │ ├── CSVRow.java │ │ ├── CSVException.java │ │ ├── CSVRuntimeException.java │ │ ├── ColumnSettings.java │ │ ├── CSVHeader.java │ │ ├── CSVFormat.java │ │ ├── TSVFormat.java │ │ ├── CSVReader.java │ │ └── CSVWriterBuilder.java │ │ ├── DataFrameException.java │ │ ├── ColumnAppender.java │ │ ├── DataFrameRuntimeException.java │ │ ├── transform │ │ ├── ColumnTransform.java │ │ ├── DataFrameTransform.java │ │ ├── ColumnDataFrameTransform.java │ │ ├── CountTransformer.java │ │ └── StringColumnConverter.java │ │ ├── DataRows.java │ │ ├── index │ │ ├── interval │ │ │ ├── Interval.java │ │ │ └── IntervalNode.java │ │ └── Index.java │ │ ├── sort │ │ ├── SortColumn.java │ │ └── RowColumnComparator.java │ │ ├── column │ │ ├── CharacterColumn.java │ │ ├── LongColumn.java │ │ ├── ShortColumn.java │ │ ├── FloatColumn.java │ │ ├── DoubleColumn.java │ │ ├── ByteColumn.java │ │ ├── StringColumn.java │ │ └── IntegerColumn.java │ │ └── Values.java │ └── antlr4 │ └── de │ └── unknownreality │ └── dataframe │ └── generated │ └── Predicate.g4 ├── .travis.yml ├── LICENSE.txt └── .gitignore /src/test/resources/data_join_a.csv: -------------------------------------------------------------------------------- 1 | GENE_ID;FPKM;CHR 2 | A;5;1 3 | B;4;2 4 | C;6;3 5 | D;6;1 -------------------------------------------------------------------------------- /src/test/resources/loader_test.csv: -------------------------------------------------------------------------------- 1 | 1;1.2;A 2 | 2;1.4;B 3 | 3;1.6;C 4 | 4;1.1;D 5 | 5;1.2;E -------------------------------------------------------------------------------- /src/test/resources/loader_test_header.csv: -------------------------------------------------------------------------------- 1 | 1;1.2;A 2 | 2;1.4;B 3 | 3;1.6;C 4 | 4;1.1;D 5 | 5;1.2;E -------------------------------------------------------------------------------- /src/test/resources/data_join_b.csv: -------------------------------------------------------------------------------- 1 | TRANSCRIPT_ID;GENE_ID;FPKM;TRANSCRIPT_NUMBER 2 | TA;A;7;1 3 | TB;A;3;2 4 | TC;B;6;1 5 | TD;E;4;1 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk8 5 | 6 | 7 | after_success: 8 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /src/test/resources/data_index.csv: -------------------------------------------------------------------------------- 1 | ID;NAME;UID 2 | 1;A;1 3 | 1;B;2 4 | 2;A;3 5 | 3;A;4 6 | 3;B;5 7 | 3;C;6 8 | 4;A;7 9 | 3;A;8 10 | -------------------------------------------------------------------------------- /src/test/resources/data_grouping.csv: -------------------------------------------------------------------------------- 1 | ID;NAME;VALUE 2 | 1;A;1 3 | 1;B;2 4 | 2;A;3 5 | 3;B;4 6 | 2;C;5 7 | 1;A;6 8 | 4;B;7 9 | 3;B;8 10 | -------------------------------------------------------------------------------- /src/test/resources/users.csv: -------------------------------------------------------------------------------- 1 | name;age;country 2 | Schmitt;24;Germany 3 | Parker;45;USA 4 | Meier;20;Germany 5 | Schmitt;30;France 6 | Peter;44;Germany 7 | Meier;24;Germany 8 | Green;33;UK 9 | Schmitt;30;Germany 10 | Meier;30;Germany 11 | -------------------------------------------------------------------------------- /src/test/resources/data_group_agg_result.csv: -------------------------------------------------------------------------------- 1 | #name;count;mean;max;na_count;filter_count;first;nfirst;x_25;desc 2 | a;3;2.0;3.0;0;2;1.0;1;1.0;name=a 3 | b;3;2.0;2.0;3;3;2.0;NA;2.0;name=b 4 | c;2;3.0;3.0;2;2;3.0;NA;3.0;name=c 5 | d;2;4.0;4.0;0;1;4.0;1;4.0;name=d -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/JoinOperation.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.join; 2 | 3 | import de.unknownreality.dataframe.DataFrame; 4 | 5 | public interface JoinOperation { 6 | JoinedDataFrame join(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/header/TypeHeader.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.common.header; 2 | 3 | import de.unknownreality.dataframe.type.ValueType; 4 | 5 | public interface TypeHeader extends Header { 6 | ValueType getValueType(int index); 7 | 8 | ValueType getValueType(T name); 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/NumberValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.NumberType; 4 | 5 | public abstract class NumberValueTypeTest, V extends NumberType> extends AbstractValueTypeTest { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/test/resources/data_group_agg_pre.csv: -------------------------------------------------------------------------------- 1 | name;x;y;z;v;r;n 2 | a;1.0;5;true;true;abc123;1 3 | b;2.0;4;true;false;abc/123;NA 4 | c;3.0;3;false;true;abc;NA 5 | d;4.0;2;false;false;123;1 6 | a;2.0;5;true;true;abc123;1 7 | b;2.0;4;true;false;abc/123;NA 8 | c;3.0;3;false;true;abc;NA 9 | d;4.0;2;false;false;a123;1 10 | a;3.0;5;true;true;1bc123;1 11 | b;2.0;4;true;false;abc/123;NA -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/ByteValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.ByteType; 4 | 5 | public class ByteValueTypeTest extends NumberValueTypeTest { 6 | @Override 7 | public ByteType getValueType() { 8 | return new ByteType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/LongValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.LongType; 4 | 5 | public class LongValueTypeTest extends AbstractValueTypeTest { 6 | @Override 7 | public LongType getValueType() { 8 | return new LongType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/FloatValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.FloatType; 4 | 5 | public class FloatValueTypeTest extends NumberValueTypeTest { 6 | @Override 7 | public FloatType getValueType() { 8 | return new FloatType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/ShortValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.ShortType; 4 | 5 | public class ShortValueTypeTest extends AbstractValueTypeTest { 6 | @Override 7 | public ShortType getValueType() { 8 | return new ShortType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/DoubleValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.DoubleType; 4 | 5 | public class DoubleValueTypeTest extends NumberValueTypeTest { 6 | @Override 7 | public DoubleType getValueType() { 8 | return new DoubleType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/StringValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.StringType; 4 | 5 | public class StringValueTypeTest extends AbstractValueTypeTest { 6 | @Override 7 | public StringType getValueType() { 8 | return new StringType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/BooleanValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.BooleanType; 4 | 5 | public class BooleanValueTypeTest extends AbstractValueTypeTest { 6 | @Override 7 | public BooleanType getValueType() { 8 | return new BooleanType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/IntegerValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.IntegerType; 4 | 5 | public class IntegerValueTypeTest extends NumberValueTypeTest { 6 | @Override 7 | public IntegerType getValueType() { 8 | return new IntegerType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/CharacterValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.impl.CharacterType; 4 | 5 | public class CharacterValueTypeTest extends AbstractValueTypeTest { 6 | @Override 7 | public CharacterType getValueType() { 8 | return new CharacterType(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/ValueTypeRuntimeException.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type; 2 | 3 | import de.unknownreality.dataframe.DataFrameRuntimeException; 4 | 5 | public class ValueTypeRuntimeException extends DataFrameRuntimeException { 6 | public ValueTypeRuntimeException(String message) { 7 | super(message); 8 | } 9 | 10 | public ValueTypeRuntimeException(String message, Throwable throwable) { 11 | super(message, throwable); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/DataFrameFilterRuntimeException.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.filter; 2 | 3 | import de.unknownreality.dataframe.DataFrameRuntimeException; 4 | 5 | public class DataFrameFilterRuntimeException extends DataFrameRuntimeException { 6 | public DataFrameFilterRuntimeException(String message) { 7 | super(message); 8 | } 9 | 10 | public DataFrameFilterRuntimeException(String message, Throwable throwable) { 11 | super(message, throwable); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/resources/legacy_meta.dfm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/test/resources/loader_test.csv.meta: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/ComparableType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import de.unknownreality.dataframe.type.ValueType; 4 | 5 | import java.util.Comparator; 6 | 7 | public abstract class ComparableType> extends ValueType { 8 | private final Comparator defaultComparator = (o1, o2) -> { 9 | if (o1 == null && o2 == null) { 10 | return 0; 11 | } 12 | if (o1 == null) { 13 | return -1; 14 | } 15 | if (o2 == null) { 16 | return 1; 17 | } 18 | return o1.compareTo(o2); 19 | }; 20 | 21 | @Override 22 | public Comparator getComparator() { 23 | return defaultComparator; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/NumberType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import de.unknownreality.dataframe.common.NumberUtil; 4 | 5 | public abstract class NumberType> extends ComparableType { 6 | @Override 7 | public T convertRaw(Object o) { 8 | if (o instanceof Number) { 9 | return NumberUtil.convert((Number) o, getType()); 10 | } 11 | return super.convertRaw(o); 12 | } 13 | 14 | @Override 15 | public int compareRaw(Object a, Object b) { 16 | if (a instanceof Number && b instanceof Number) { 17 | return NumberUtil.compare((Number) a, (Number) b); 18 | } 19 | return super.compareRaw(a, b); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alexander Grün 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/LongType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class LongType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Long.class; 13 | } 14 | 15 | 16 | @Override 17 | public Long read(DataInputStream dis) throws IOException { 18 | return dis.readLong(); 19 | } 20 | 21 | @Override 22 | public Long read(ByteBuffer buf) { 23 | return buf.getLong(); 24 | } 25 | 26 | @Override 27 | public Long parse(String s) { 28 | assertNotNull(s); 29 | return Long.parseLong(s); 30 | } 31 | 32 | @Override 33 | public void write(Writer writer, Long value) throws IOException { 34 | writer.write(toString(value)); 35 | } 36 | 37 | @Override 38 | public String toString(Long value) { 39 | assertNotNull(value); 40 | return Long.toString(value); 41 | } 42 | 43 | @Override 44 | public int write(DataOutputStream dos, Long value) throws IOException { 45 | assertNotNull(value); 46 | dos.writeLong(value); 47 | return Long.BYTES; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/ByteType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class ByteType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Byte.class; 13 | } 14 | 15 | 16 | @Override 17 | public Byte read(DataInputStream dis) throws IOException { 18 | dis.readByte(); 19 | return dis.readByte(); 20 | } 21 | 22 | @Override 23 | public Byte read(ByteBuffer buf) { 24 | return buf.get(); 25 | } 26 | 27 | @Override 28 | public Byte parse(String s) { 29 | assertNotNull(s); 30 | return Byte.parseByte(s); 31 | } 32 | 33 | @Override 34 | public void write(Writer writer, Byte value) throws IOException { 35 | writer.write(toString(value)); 36 | } 37 | 38 | @Override 39 | public String toString(Byte value) { 40 | assertNotNull(value); 41 | return Byte.toString(value); 42 | } 43 | 44 | @Override 45 | public int write(DataOutputStream dos, Byte value) throws IOException { 46 | assertNotNull(value); 47 | dos.writeByte(value); 48 | return 1; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/FloatType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class FloatType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Float.class; 13 | } 14 | 15 | 16 | @Override 17 | public Float read(DataInputStream dis) throws IOException { 18 | return dis.readFloat(); 19 | } 20 | 21 | @Override 22 | public Float read(ByteBuffer buf) { 23 | return buf.getFloat(); 24 | } 25 | 26 | @Override 27 | public Float parse(String s) { 28 | assertNotNull(s); 29 | return Float.parseFloat(s); 30 | } 31 | 32 | @Override 33 | public void write(Writer writer, Float value) throws IOException { 34 | writer.write(toString(value)); 35 | } 36 | 37 | @Override 38 | public String toString(Float value) { 39 | assertNotNull(value); 40 | return Float.toString(value); 41 | } 42 | 43 | @Override 44 | public int write(DataOutputStream dos, Float value) throws IOException { 45 | assertNotNull(value); 46 | dos.writeFloat(value); 47 | return Float.BYTES; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/ShortType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class ShortType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Short.class; 13 | } 14 | 15 | @Override 16 | public Short read(DataInputStream dis) throws IOException { 17 | return dis.readShort(); 18 | } 19 | 20 | @Override 21 | public Short read(ByteBuffer buf) { 22 | return buf.getShort(); 23 | } 24 | 25 | @Override 26 | public Short parse(String s) { 27 | assertNotNull(s); 28 | return Short.parseShort(s); 29 | } 30 | 31 | @Override 32 | public void write(Writer writer, Short value) throws IOException { 33 | writer.write(toString(value)); 34 | } 35 | 36 | @Override 37 | public String toString(Short value) { 38 | assertNotNull(value); 39 | return Short.toString(value); 40 | } 41 | 42 | @Override 43 | public int write(DataOutputStream dos, Short value) throws IOException { 44 | assertNotNull(value); 45 | dos.writeShort(value); 46 | return Short.BYTES; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/DoubleType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class DoubleType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Double.class; 13 | } 14 | 15 | 16 | @Override 17 | public Double read(DataInputStream dis) throws IOException { 18 | return dis.readDouble(); 19 | } 20 | 21 | @Override 22 | public Double read(ByteBuffer buf) { 23 | return buf.getDouble(); 24 | } 25 | 26 | @Override 27 | public Double parse(String s) { 28 | assertNotNull(s); 29 | return Double.parseDouble(s); 30 | } 31 | 32 | @Override 33 | public void write(Writer writer, Double value) throws IOException { 34 | writer.write(toString(value)); 35 | } 36 | 37 | @Override 38 | public String toString(Double value) { 39 | assertNotNull(value); 40 | return Double.toString(value); 41 | } 42 | 43 | @Override 44 | public int write(DataOutputStream dos, Double value) throws IOException { 45 | assertNotNull(value); 46 | dos.writeDouble(value); 47 | return Double.BYTES; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/IntegerType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class IntegerType extends NumberType { 10 | @Override 11 | public Class getType() { 12 | return Integer.class; 13 | } 14 | 15 | 16 | @Override 17 | public Integer read(DataInputStream dis) throws IOException { 18 | return dis.readInt(); 19 | } 20 | 21 | @Override 22 | public Integer read(ByteBuffer buf) { 23 | return buf.getInt(); 24 | } 25 | 26 | @Override 27 | public Integer parse(String s) { 28 | assertNotNull(s); 29 | return Integer.parseInt(s); 30 | } 31 | 32 | @Override 33 | public void write(Writer writer, Integer value) throws IOException { 34 | writer.write(toString(value)); 35 | } 36 | 37 | @Override 38 | public String toString(Integer value) { 39 | assertNotNull(value); 40 | return Integer.toString(value); 41 | } 42 | 43 | @Override 44 | public int write(DataOutputStream dos, Integer value) throws IOException { 45 | assertNotNull(value); 46 | dos.writeInt(value); 47 | return Integer.BYTES; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/CharacterType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | 9 | public class CharacterType extends ComparableType { 10 | @Override 11 | public Class getType() { 12 | return Character.class; 13 | } 14 | 15 | @Override 16 | public Character read(DataInputStream dis) throws IOException { 17 | return dis.readChar(); 18 | } 19 | 20 | @Override 21 | public Character read(ByteBuffer buf) { 22 | return buf.getChar(); 23 | } 24 | 25 | @Override 26 | public Character parse(String s) { 27 | assertNotNull(s); 28 | return s.charAt(0); 29 | } 30 | 31 | @Override 32 | public void write(Writer writer, Character value) throws IOException { 33 | writer.write(toString(value)); 34 | } 35 | 36 | @Override 37 | public String toString(Character value) { 38 | assertNotNull(value); 39 | return Character.toString(value); 40 | } 41 | 42 | @Override 43 | public int write(DataOutputStream dos, Character value) throws IOException { 44 | assertNotNull(value); 45 | dos.writeChar(value); 46 | return Character.BYTES; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/KeyValueGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common; 26 | 27 | public interface KeyValueGetter { 28 | V get(K name); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/FormatSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | /** 28 | * Created by Alex on 17.06.2017. 29 | */ 30 | public interface FormatSettings { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/WriteFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | /** 28 | * Created by Alex on 17.06.2017. 29 | */ 30 | public interface WriteFormat { 31 | WriterBuilder getWriterBuilder(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/WriterBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | /** 28 | * Created by Alex on 17.06.2017. 29 | */ 30 | public interface WriterBuilder{ 31 | D build(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/RowIterable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common; 26 | 27 | /** 28 | * Created by Alex on 10.03.2016. 29 | */ 30 | public interface RowIterable> extends Iterable { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/RowIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common; 26 | 27 | import java.util.Iterator; 28 | 29 | /** 30 | * Created by Alex on 17.06.2017. 31 | */ 32 | public interface RowIterator> extends Iterator { 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/print/ValueFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.print; 26 | 27 | import de.unknownreality.dataframe.type.ValueType; 28 | 29 | public interface ValueFormatter { 30 | String format(ValueType type, Object value, int maxWidth); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/group/GroupUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.group; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | 29 | /** 30 | * Created by Alex on 12.06.2017. 31 | */ 32 | public interface GroupUtil { 33 | DataGrouping groupBy(DataFrame df, String... columns); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/ReadFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | 29 | /** 30 | * Created by Alex on 17.06.2017. 31 | */ 32 | public interface ReadFormat, B extends ReaderBuilder> { 33 | B getReaderBuilder(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/print/PrintFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.print; 26 | 27 | import de.unknownreality.dataframe.io.WriteFormat; 28 | 29 | public class PrintFormat implements WriteFormat { 30 | @Override 31 | public PrinterBuilder getWriterBuilder() { 32 | return PrinterBuilder.create(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/group/aggr/AggregateFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.group.aggr; 26 | 27 | import de.unknownreality.dataframe.group.DataGroup; 28 | 29 | /** 30 | * Created by Alex on 13.06.2017. 31 | */ 32 | @FunctionalInterface 33 | public interface AggregateFunction { 34 | T aggregate(DataGroup group); 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /src/main/java/Runner.java 2 | # Created by .ignore support plugin (hsz.mobi) 3 | ### Maven template 4 | target/ 5 | pom.xml.tag 6 | pom.xml.releaseBackup 7 | pom.xml.versionsBackup 8 | pom.xml.next 9 | release.properties 10 | dependency-reduced-pom.xml 11 | buildNumber.properties 12 | .mvn/timing.properties 13 | ### JetBrains template 14 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 15 | 16 | *.iml 17 | 18 | ## Directory-based project format: 19 | .idea/ 20 | # if you remove the above rule, at least ignore the following: 21 | 22 | # User-specific stuff: 23 | # .idea/workspace.xml 24 | # .idea/tasks.xml 25 | # .idea/dictionaries 26 | 27 | # Sensitive or high-churn files: 28 | # .idea/dataSources.ids 29 | # .idea/dataSources.xml 30 | # .idea/sqlDataSources.xml 31 | # .idea/dynamic.xml 32 | # .idea/uiDesigner.xml 33 | 34 | # Gradle: 35 | # .idea/gradle.xml 36 | # .idea/libraries 37 | 38 | # Mongo Explorer plugin: 39 | # .idea/mongoSettings.xml 40 | 41 | ## File-based project format: 42 | *.ipr 43 | *.iws 44 | 45 | ## Plugin-specific files: 46 | 47 | # IntelliJ 48 | /out/ 49 | 50 | # mpeltonen/sbt-idea plugin 51 | .idea_modules/ 52 | 53 | # JIRA plugin 54 | atlassian-ide-plugin.xml 55 | 56 | # Crashlytics plugin (for Android Studio and IntelliJ) 57 | com_crashlytics_export_strings.xml 58 | crashlytics.properties 59 | crashlytics-build.properties 60 | ### Java template 61 | *.class 62 | 63 | # Mobile Tools for Java (J2ME) 64 | .mtj.tmp/ 65 | 66 | # Package Files # 67 | *.jar 68 | *.war 69 | *.ear 70 | 71 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 72 | hs_err_pid* 73 | 74 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/MapFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | /** 28 | * Created by Alex on 10.03.2016. 29 | */ 30 | @FunctionalInterface 31 | public interface MapFunction { 32 | /** 33 | * Applies a function to an input value and returns the resulting value. 34 | * @param value input value 35 | * @return resulting value 36 | */ 37 | T map(T value); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVRow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.common.row.StringRow; 28 | 29 | /** 30 | * Created by Alex on 09.03.2016. 31 | */ 32 | public class CSVRow extends StringRow { 33 | public CSVRow(CSVHeader header, String[] values, int rowNumber) { 34 | super(header,values,rowNumber); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/impl/AbstractValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value.impl; 2 | 3 | import de.unknownreality.dataframe.type.ValueType; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.DataOutputStream; 9 | import java.io.StringWriter; 10 | 11 | abstract class AbstractValueTypeTest> { 12 | public abstract T getValueType(); 13 | 14 | @Test 15 | public void nullTest() { 16 | T valueType = getValueType(); 17 | 18 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.parse(null)); 19 | Assert.assertNull(valueType.parseOrNull(null)); 20 | 21 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.toString(null)); 22 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.toStringRaw(null)); 23 | 24 | StringWriter writer = new StringWriter(); 25 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.write(writer, null)); 26 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.writeRaw(writer, null)); 27 | 28 | DataOutputStream dos = new DataOutputStream(new ByteArrayOutputStream()); 29 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.write(dos, null)); 30 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.writeRaw(dos, null)); 31 | 32 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.convertRaw(null)); 33 | Assert.assertThrows(IllegalArgumentException.class, () -> valueType.compareRaw(null, null)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/DataFrameException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | /** 28 | * Created by Alex on 07.07.2016. 29 | */ 30 | public class DataFrameException extends Exception { 31 | public DataFrameException(String message) { 32 | super(message); 33 | } 34 | 35 | public DataFrameException(String message, Throwable throwable) { 36 | super(message, throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/ValueTypeNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.type; 26 | 27 | import de.unknownreality.dataframe.DataFrameException; 28 | 29 | /** 30 | * Created by Alex on 04.06.2015. 31 | */ 32 | public class ValueTypeNotFoundException extends DataFrameException { 33 | public ValueTypeNotFoundException(Class c) { 34 | super("no type found for " + c.getName()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/ColumnAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | /** 28 | * Created by Alex on 13.03.2016. 29 | */ 30 | @FunctionalInterface 31 | public interface ColumnAppender { 32 | /** 33 | * Creates the value for a new column in a row 34 | * 35 | * @param row row containing values of the other columns 36 | * @return value for new column 37 | */ 38 | T createRowValue(DataRow row); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/DataFrameRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | /** 28 | * Created by Alex on 07.07.2016. 29 | */ 30 | public class DataFrameRuntimeException extends RuntimeException { 31 | public DataFrameRuntimeException(String message) { 32 | super(message); 33 | } 34 | 35 | public DataFrameRuntimeException(String message, Throwable throwable) { 36 | super(message, throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.DataFrameException; 28 | 29 | /** 30 | * Created by Alex on 09.03.2016. 31 | */ 32 | public class CSVException extends DataFrameException { 33 | public CSVException(String message) { 34 | super(message); 35 | } 36 | 37 | public CSVException(String message, Throwable throwable) { 38 | super(message, throwable); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/FileFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.csv.CSVFormat; 28 | import de.unknownreality.dataframe.csv.TSVFormat; 29 | import de.unknownreality.dataframe.print.PrintFormat; 30 | 31 | /** 32 | * Created by Alex on 17.06.2017. 33 | */ 34 | public interface FileFormat { 35 | CSVFormat CSV = new CSVFormat(); 36 | TSVFormat TSV = new TSVFormat(); 37 | PrintFormat Print = new PrintFormat(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/PredicateCompilerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | /** 28 | * Created by Alex on 21.05.2017. 29 | */ 30 | public class PredicateCompilerException extends RuntimeException { 31 | public PredicateCompilerException(String message) { 32 | super(message); 33 | } 34 | 35 | public PredicateCompilerException(String message, Throwable throwable) { 36 | super(message, throwable); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/DataIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.common.RowIterable; 29 | import de.unknownreality.dataframe.common.RowIterator; 30 | 31 | import java.util.List; 32 | 33 | /** 34 | * Created by Alex on 17.06.2017. 35 | */ 36 | public interface DataIterator> extends RowIterator, RowIterable { 37 | List getColumnsInformation(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/ReaderBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | 29 | import java.util.Map; 30 | 31 | /** 32 | * Created by Alex on 17.06.2017. 33 | */ 34 | public interface ReaderBuilder, D extends DataReader>> { 35 | D build(); 36 | 37 | ReaderBuilder loadSettings(Map map) throws Exception; 38 | 39 | ReaderBuilder selectColumn(String col); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.DataFrameRuntimeException; 28 | 29 | /** 30 | * Created by Alex on 09.03.2016. 31 | */ 32 | public class CSVRuntimeException extends DataFrameRuntimeException { 33 | public CSVRuntimeException(String message) { 34 | super(message); 35 | } 36 | 37 | public CSVRuntimeException(String message, Throwable throwable) { 38 | super(message, throwable); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/group/GroupRow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.group; 26 | 27 | import de.unknownreality.dataframe.DataRow; 28 | 29 | /** 30 | * Created by algru on 11.06.2017. 31 | */ 32 | public class GroupRow extends DataRow { 33 | private final DataGroup group; 34 | public GroupRow(DataGroup group, DataGrouping grouping,int index) { 35 | super(grouping, index); 36 | this.group = group; 37 | } 38 | 39 | public DataGroup getGroup() { 40 | return group; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/transform/ColumnTransform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.transform; 26 | 27 | import de.unknownreality.dataframe.DataFrameColumn; 28 | 29 | /** 30 | * Created by algru on 06.09.2016. 31 | */ 32 | @FunctionalInterface 33 | public interface ColumnTransform, R extends DataFrameColumn> { 34 | /** 35 | * Transforms an input column into a new column 36 | * 37 | * @param source input column 38 | * @return resulting column 39 | */ 40 | R transform(I source); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/transform/DataFrameTransform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.transform; 26 | 27 | import de.unknownreality.dataframe.DefaultDataFrame; 28 | 29 | /** 30 | * Created by algru on 06.09.2016. 31 | */ 32 | @FunctionalInterface 33 | public interface DataFrameTransform { 34 | /** 35 | * Transforms an input dataframe into a new data frame 36 | * 37 | * @param DataFrame type 38 | * @param source input dataframe 39 | * @return resulting dataframe 40 | */ 41 | D transform(D source); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/StringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common; 26 | 27 | public class StringUtil { 28 | /** 29 | * Puts a string in quotes. 30 | * All occurrences of quotes chars in the string are escaped. 31 | * 32 | * @param input string to put in quotes 33 | * @param quoteChar quote char 34 | * @return string between quote chars 35 | */ 36 | public static String putInQuotes(String input, Character quoteChar) { 37 | return quoteChar + input.replace(quoteChar.toString(), "\\" + quoteChar) + quoteChar; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/transform/ColumnDataFrameTransform.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.transform; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | import de.unknownreality.dataframe.DataFrameColumn; 29 | 30 | /** 31 | * Created by algru on 06.09.2016. 32 | */ 33 | @FunctionalInterface 34 | public interface ColumnDataFrameTransform> { 35 | /** 36 | * Transforms an input column into a data frame 37 | * 38 | * @param source input column 39 | * @return resulting dataframe 40 | */ 41 | DataFrame transform(I source); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/mapping/MappedColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common.mapping; 26 | 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.RetentionPolicy; 29 | 30 | /** 31 | * Annotation that defines a mapped column. 32 | * If a header is defined, the right value is found by using the header name in a data container row. 33 | * If an index is defined, the value is found by using the value at this index from each data container row. 34 | */ 35 | @Retention(RetentionPolicy.RUNTIME) 36 | public @interface MappedColumn { 37 | String header() default ""; 38 | 39 | int index() default -1; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/BooleanType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | import java.text.ParseException; 9 | 10 | public class BooleanType extends ComparableType { 11 | @Override 12 | public Class getType() { 13 | return Boolean.class; 14 | } 15 | 16 | @Override 17 | public Boolean read(DataInputStream dis) throws IOException { 18 | return dis.readBoolean(); 19 | } 20 | 21 | @Override 22 | public Boolean read(ByteBuffer buf) { 23 | return buf.get() == 1; 24 | } 25 | 26 | @Override 27 | public Boolean parse(String s) throws ParseException { 28 | assertNotNull(s); 29 | if (!( 30 | "false".equals((s = s.toLowerCase())) 31 | || "true".equals(s) 32 | || "f".equals(s) 33 | || "t".equals(s) 34 | )) { 35 | throw new ParseException(String.format("illegal boolean value: %s", s), 0); 36 | } 37 | if (s.equals("f")) { 38 | return false; 39 | } 40 | if ("t".equals(s)) { 41 | return true; 42 | } 43 | return Boolean.parseBoolean(s); 44 | } 45 | 46 | @Override 47 | public void write(Writer writer, Boolean value) throws IOException { 48 | writer.write(toString(value)); 49 | } 50 | 51 | @Override 52 | public String toString(Boolean value) { 53 | assertNotNull(value); 54 | return Boolean.toString(value); 55 | } 56 | 57 | @Override 58 | public int write(DataOutputStream dos, Boolean value) throws IOException { 59 | assertNotNull(value); 60 | dos.writeBoolean(value); 61 | return 1; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/print/DefaultValueFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.print; 26 | 27 | 28 | import de.unknownreality.dataframe.type.ValueType; 29 | 30 | public class DefaultValueFormatter implements ValueFormatter { 31 | @Override 32 | public String format(ValueType valueType, Object value, int maxWidth) { 33 | if ((value instanceof String)) { 34 | String strVal = (String) value; 35 | if (strVal.length() > maxWidth) { 36 | value = strVal.substring(0, maxWidth - 3); 37 | value += "..."; 38 | } 39 | } 40 | return String.format("%." + maxWidth + "s", value); 41 | 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/impl/StringType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type.impl; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | import java.nio.charset.Charset; 9 | import java.nio.charset.StandardCharsets; 10 | 11 | public class StringType extends ComparableType { 12 | private final Charset charSet = StandardCharsets.UTF_8; 13 | 14 | @Override 15 | public Class getType() { 16 | return String.class; 17 | } 18 | 19 | 20 | @Override 21 | public String read(DataInputStream dis) throws IOException { 22 | int length = dis.readInt(); 23 | byte[] data = new byte[length]; 24 | dis.read(data); 25 | return new String(data, charSet); 26 | } 27 | 28 | @Override 29 | public String read(ByteBuffer buf) { 30 | int length = buf.getInt(); 31 | byte[] data = new byte[length]; 32 | return new String(data, charSet); 33 | } 34 | 35 | @Override 36 | public String convertRaw(Object o) { 37 | return super.convertRaw(o == null ? null : String.valueOf(o)); 38 | } 39 | 40 | @Override 41 | public String parse(String s) { 42 | assertNotNull(s); 43 | return s; 44 | } 45 | 46 | @Override 47 | public void write(Writer writer, String value) throws IOException { 48 | assertNotNull(value); 49 | writer.write(value); 50 | } 51 | 52 | @Override 53 | public String toString(String value) { 54 | assertNotNull(value); 55 | return value; 56 | } 57 | 58 | @Override 59 | public int write(DataOutputStream dos, String value) throws IOException { 60 | assertNotNull(value); 61 | byte[] data = value.getBytes(charSet); 62 | dos.writeInt(data.length); 63 | dos.write(data); 64 | return Integer.BYTES + data.length; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/ColumnSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import java.util.ArrayList; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | /** 33 | * Created by Alex on 17.06.2017. 34 | */ 35 | public class ColumnSettings { 36 | private final List ignoreColumns = new ArrayList<>(); 37 | private final List selectColumns = new ArrayList<>(); 38 | private final Map> columnTypeMap = new HashMap<>(); 39 | 40 | 41 | public List getIgnoreColumns() { 42 | return ignoreColumns; 43 | } 44 | 45 | public List getSelectColumns() { 46 | return selectColumns; 47 | } 48 | 49 | public Map> getColumnTypeMap() { 50 | return columnTypeMap; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/BooleanFilterVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import de.unknownreality.dataframe.filter.FilterPredicate; 28 | import de.unknownreality.dataframe.generated.PredicateBaseVisitor; 29 | import de.unknownreality.dataframe.generated.PredicateParser; 30 | 31 | /** 32 | * Created by Alex on 21.05.2017. 33 | */ 34 | public class BooleanFilterVisitor extends PredicateBaseVisitor { 35 | 36 | @Override 37 | public FilterPredicate visitBoolean_filter(PredicateParser.Boolean_filterContext ctx) { 38 | String colName = FieldFilterVisitor.getColname(ctx.variable().getText()); 39 | if(ctx.NEGATE() != null){ 40 | return FilterPredicate.eq(colName,false); 41 | } 42 | return FilterPredicate.eq(colName,true); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/JoinedDataFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.join; 26 | 27 | import de.unknownreality.dataframe.DefaultDataFrame; 28 | 29 | /** 30 | * Created by Alex on 13.03.2016. 31 | */ 32 | public class JoinedDataFrame extends DefaultDataFrame { 33 | private final JoinInfo joinInfo; 34 | 35 | public JoinedDataFrame(JoinInfo info) { 36 | this.joinInfo = info; 37 | } 38 | 39 | /** 40 | * Returns the information about the joined columns 41 | * 42 | * @return join info 43 | */ 44 | public JoinInfo getJoinInfo() { 45 | return joinInfo; 46 | } 47 | 48 | 49 | @Override 50 | public JoinedDataFrame copy() { 51 | JoinedDataFrame joinedDataFrame = new JoinedDataFrame(joinInfo); 52 | joinedDataFrame.set(getRows(),getIndices()); 53 | return joinedDataFrame; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/DataContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common; 26 | 27 | import de.unknownreality.dataframe.common.header.Header; 28 | import de.unknownreality.dataframe.common.mapping.DataMapper; 29 | 30 | import java.util.List; 31 | 32 | /** 33 | * Created by Alex on 14.03.2016. 34 | */ 35 | public interface DataContainer, R extends Row> extends RowIterable { 36 | /** 37 | * Returns the header of this data container 38 | * 39 | * @return data container header 40 | */ 41 | H getHeader(); 42 | 43 | /** 44 | * Maps this data container to a list of entities. 45 | * 46 | * @param cl class of resulting entities 47 | * @param type of entities 48 | * @return list of mapped entities 49 | * @see DataMapper#map(DataContainer, Class) 50 | */ 51 | List map(Class cl); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/row/BasicRow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common.row; 26 | 27 | import de.unknownreality.dataframe.common.header.TypeHeader; 28 | 29 | /** 30 | * Created by Alex on 19.05.2017. 31 | */ 32 | public class BasicRow, V> extends AbstractHeaderRow { 33 | private final V[] values; 34 | 35 | public BasicRow(H header, V[] values, int index) { 36 | super(header, index); 37 | this.values = values; 38 | } 39 | 40 | @Override 41 | public V get(int index) { 42 | return this.values[index]; 43 | } 44 | 45 | @Override 46 | public int size() { 47 | return values.length; 48 | } 49 | 50 | /** 51 | * Returns the values of this row as array 52 | * 53 | * @return values array 54 | */ 55 | protected V[] getValues() { 56 | return values; 57 | } 58 | 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVHeader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.common.header.BasicHeader; 28 | 29 | /** 30 | * Created by Alex on 09.03.2016. 31 | */ 32 | public class CSVHeader extends BasicHeader { 33 | 34 | private int emptyColumnIndex = 1; 35 | 36 | @Override 37 | public void add(String name) { 38 | super.add(name); 39 | emptyColumnIndex++; 40 | } 41 | 42 | /** 43 | * Adds a new column without specified name. 44 | * If no name is provided, names are created: V1,V2,V3... 45 | */ 46 | public void add() { 47 | String name = "V" + (emptyColumnIndex++); 48 | super.add(name); 49 | } 50 | 51 | protected String getNextEmptyColumnName(){ 52 | return "V" + (emptyColumnIndex); 53 | } 54 | 55 | protected void incrementEmptyColumnIndex(){ 56 | emptyColumnIndex++; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/PredicateCompileErrorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import org.antlr.v4.runtime.BaseErrorListener; 28 | import org.antlr.v4.runtime.RecognitionException; 29 | import org.antlr.v4.runtime.Recognizer; 30 | 31 | 32 | /** 33 | * Created by Alex on 21.05.2017. 34 | */ 35 | public class PredicateCompileErrorListener extends BaseErrorListener { 36 | private final String predicateString; 37 | 38 | public PredicateCompileErrorListener(String predicateString) { 39 | this.predicateString = predicateString; 40 | } 41 | 42 | @Override 43 | public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { 44 | throw new PredicateCompilerException(String.format("syntax error (%s : %s) line:%s, pos:%s ", msg, predicateString, line, charPositionInLine)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.io.FileFormat; 28 | import de.unknownreality.dataframe.io.ReadFormat; 29 | import de.unknownreality.dataframe.io.WriteFormat; 30 | 31 | /** 32 | * Created by Alex on 17.06.2017. 33 | */ 34 | public class CSVFormat implements FileFormat, ReadFormat, WriteFormat { 35 | @Override 36 | public CSVReaderBuilder getReaderBuilder() { 37 | return new CSVReaderBuilder().withSeparator(';'); 38 | } 39 | 40 | public static CSVReaderBuilder createReader() { 41 | return new CSVReaderBuilder().withSeparator(';'); 42 | } 43 | 44 | @Override 45 | public CSVWriterBuilder getWriterBuilder() { 46 | return CSVWriterBuilder.create().withSeparator(';'); 47 | } 48 | 49 | public static CSVWriterBuilder createWriter(){ 50 | return CSVWriterBuilder.create().withSeparator(';'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/TSVFormat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.io.FileFormat; 28 | import de.unknownreality.dataframe.io.ReadFormat; 29 | import de.unknownreality.dataframe.io.WriteFormat; 30 | 31 | /** 32 | * Created by Alex on 17.06.2017. 33 | */ 34 | public class TSVFormat implements FileFormat, ReadFormat, WriteFormat { 35 | @Override 36 | public CSVReaderBuilder getReaderBuilder() { 37 | return new CSVReaderBuilder().withSeparator('\t'); 38 | } 39 | 40 | public static CSVReaderBuilder createReader() { 41 | return new CSVReaderBuilder().withSeparator('\t'); 42 | } 43 | 44 | @Override 45 | public CSVWriterBuilder getWriterBuilder() { 46 | return CSVWriterBuilder.create().withSeparator('\t'); 47 | } 48 | 49 | public static CSVWriterBuilder createWriter() { 50 | return CSVWriterBuilder.create().withSeparator('\t'); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/print/DefaultNumberFormatter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.print; 26 | 27 | import de.unknownreality.dataframe.DataFrameRuntimeException; 28 | import de.unknownreality.dataframe.common.NumberUtil; 29 | import de.unknownreality.dataframe.type.ValueType; 30 | 31 | import java.util.Locale; 32 | 33 | public class DefaultNumberFormatter implements ValueFormatter { 34 | @Override 35 | public String format(ValueType valueType, Object value, int maxWidth) { 36 | if (!(value instanceof Number)) { 37 | throw new DataFrameRuntimeException(String.format("number type expected (%s)", value.getClass())); 38 | } 39 | Number num = (Number) value; 40 | if (!NumberUtil.isFloatOrDouble(num)) { 41 | return String.format("%." + maxWidth + "s", num.longValue()); 42 | } else { 43 | int n = maxWidth - 2; 44 | return String.format(Locale.US, "%." + n + "f", num.doubleValue()); 45 | } 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/JoinColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.join; 26 | 27 | /** 28 | * Created by Alex on 12.03.2016. 29 | */ 30 | public class JoinColumn { 31 | private final String columnA; 32 | private final String columnB; 33 | 34 | /** 35 | * Creates a join column for two different column names 36 | * 37 | * @param columnA column name in the first data frame 38 | * @param columnB column name in the second data frame 39 | */ 40 | public JoinColumn(String columnA, String columnB) { 41 | this.columnA = columnA; 42 | this.columnB = columnB; 43 | } 44 | 45 | /** 46 | * Creates a join column for the same column name in both data frames 47 | * 48 | * @param column column name 49 | */ 50 | public JoinColumn(String column) { 51 | this(column, column); 52 | } 53 | 54 | public String getColumnA() { 55 | return columnA; 56 | } 57 | 58 | public String getColumnB() { 59 | return columnB; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/header/Header.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common.header; 26 | 27 | /** 28 | * Created by Alex on 10.03.2016. 29 | */ 30 | public interface Header extends Iterable { 31 | 32 | /** 33 | * Returns the number of entries(columns) in this header 34 | * 35 | * @return number of entries 36 | */ 37 | int size(); 38 | 39 | /** 40 | * Gets the entry at a specific index 41 | * 42 | * @param index index of entry 43 | * @return entry at specific index 44 | */ 45 | T get(int index); 46 | 47 | /** 48 | * Returns true if the header contains a specific entry 49 | * 50 | * @param value entry to be tested 51 | * @return true if header contains entry 52 | */ 53 | boolean contains(T value); 54 | 55 | /** 56 | * Returns the index of a specific entry in this header 57 | * 58 | * @param name searched entry 59 | * @return index of the entry 60 | */ 61 | int getIndex(T name); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.io.DataReader; 28 | 29 | import java.io.BufferedReader; 30 | import java.io.Reader; 31 | import java.nio.charset.Charset; 32 | 33 | /** 34 | * Created by Alex on 17.06.2017. 35 | */ 36 | public class CSVReader extends DataReader { 37 | private CSVSettings settings; 38 | private final ColumnSettings columnSettings; 39 | 40 | protected CSVReader(CSVSettings settings, ColumnSettings columnSettings) { 41 | this.settings = settings; 42 | this.columnSettings = columnSettings; 43 | } 44 | 45 | @Override 46 | public Charset getCharset() { 47 | if (settings.getCharset() != null) { 48 | return settings.getCharset(); 49 | } 50 | return super.getCharset(); 51 | } 52 | 53 | @Override 54 | public CSVIterator load(Reader reader) { 55 | return new CSVIterator(new BufferedReader(reader), settings, columnSettings); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/DataRows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | public class DataRows extends ArrayList{ 31 | 32 | private final DataFrame dataFrame; 33 | 34 | public DataRows(DataFrame dataFrame, List rows){ 35 | this.dataFrame = dataFrame; 36 | addAll(rows); 37 | } 38 | 39 | public DataRows(DataFrame dataFrame){ 40 | this.dataFrame = dataFrame; 41 | } 42 | 43 | 44 | public DataFrame toDataFrame(){ 45 | DataFrame df = DataFrame.create(); 46 | df.set(dataFrame.getHeader().copy()); 47 | if(isEmpty()){ 48 | return df; 49 | } 50 | boolean compatible = df.isCompatible( 51 | get(0).getDataFrame() 52 | ); 53 | for(DataRow row : this){ 54 | if(compatible){ 55 | df.appendMatchingRow(row); 56 | } 57 | else{ 58 | df.append(row); 59 | } 60 | 61 | } 62 | return df; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/PredicateOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | /** 31 | * Created by Alex on 21.05.2017. 32 | */ 33 | public enum PredicateOperation { 34 | AND("AND","and","&","&&"), 35 | OR("OR","or","|","||"), 36 | NOR("NOR","nor"), 37 | XOR("XOR","xor"); 38 | 39 | private static final Map ALIASES_MAP = new HashMap<>(); 40 | 41 | private final String[] aliases; 42 | 43 | PredicateOperation(String... aliases){ 44 | this.aliases = aliases; 45 | } 46 | 47 | public String[] getAliases() { 48 | return aliases; 49 | } 50 | 51 | 52 | static{ 53 | for(PredicateOperation predicateOperation : values()){ 54 | for(String alias : predicateOperation.aliases){ 55 | ALIASES_MAP.put(alias,predicateOperation); 56 | } 57 | } 58 | } 59 | 60 | public static PredicateOperation find(String alias){ 61 | return ALIASES_MAP.get(alias); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/JoinUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.join; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | 29 | /** 30 | * Created by Alex on 12.06.2017. 31 | */ 32 | public interface JoinUtil { 33 | 34 | JoinedDataFrame innerJoin(DataFrame dfA, DataFrame dfB, JoinColumn... joinColumns); 35 | JoinedDataFrame innerJoin(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns); 36 | 37 | JoinedDataFrame outerJoin(DataFrame dfA, DataFrame dfB, JoinColumn... joinColumns); 38 | JoinedDataFrame outerJoin(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns); 39 | 40 | JoinedDataFrame rightJoin(DataFrame dfA, DataFrame dfB, JoinColumn... joinColumns); 41 | JoinedDataFrame rightJoin(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns); 42 | 43 | JoinedDataFrame leftJoin(DataFrame dfA, DataFrame dfB, JoinColumn... joinColumns); 44 | JoinedDataFrame leftJoin(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/value/ValueTypeTest.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.value; 2 | 3 | import de.unknownreality.dataframe.DataFrame; 4 | import de.unknownreality.dataframe.csv.CSVReader; 5 | import de.unknownreality.dataframe.csv.CSVReaderBuilder; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import java.io.StringWriter; 10 | 11 | public class ValueTypeTest { 12 | String expectedCSVNull = 13 | "byte\tboolean\tdouble\tfloat\tinteger\tlong\tshort\tstring" + System.lineSeparator() + 14 | "1\ttrue\t2.0\t3.0\t4\t5\t6\ttest" + System.lineSeparator() + 15 | "NA\tNA\tNA\tNA\tNA\tNA\tNA\tNA" + System.lineSeparator() + 16 | "2\tfalse\t2.1\t3.1\t7\t8\t9\ttest2" + System.lineSeparator(); 17 | 18 | @Test 19 | public void testNullValues() { 20 | DataFrame df = DataFrame.create() 21 | .addByteColumn("byte") 22 | .addBooleanColumn("boolean") 23 | .addDoubleColumn("double") 24 | .addFloatColumn("float") 25 | .addIntegerColumn("integer") 26 | .addLongColumn("long") 27 | .addShortColumn("short") 28 | .addStringColumn("string"); 29 | 30 | df.append(1, true, 2d, 3f, 4, 5L, 6, "test"); 31 | df.append(null, null, null, null, null, null, null, null); 32 | df.append(2, false, 2.1d, 3.1f, 7, 8L, 9, "test2"); 33 | 34 | 35 | StringWriter stringWriter = new StringWriter(); 36 | df.writeCSV(stringWriter, '\t', true); 37 | String csv = stringWriter.toString(); 38 | Assert.assertEquals(expectedCSVNull, csv); 39 | 40 | CSVReader reader = CSVReaderBuilder.create() 41 | .setColumnType("byte", Byte.class) 42 | .setColumnType("boolean", Boolean.class) 43 | .setColumnType("double", Double.class) 44 | .setColumnType("float", Float.class) 45 | .setColumnType("integer", Integer.class) 46 | .setColumnType("long", Long.class) 47 | .setColumnType("short", Short.class) 48 | .setColumnType("string", String.class) 49 | .withSeparator('\t') 50 | .withHeader(true) 51 | .build(); 52 | 53 | DataFrame parsedDF = DataFrame.load(csv, reader); 54 | Assert.assertEquals(df, parsedDF); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/index/interval/Interval.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.index.interval; 26 | 27 | import static de.unknownreality.dataframe.common.NumberUtil.*; 28 | 29 | public class Interval implements Comparable { 30 | public final Number low; 31 | public final Number high; 32 | 33 | public Interval(Number left, Number right) { 34 | this.low = left; 35 | this.high = right; 36 | } 37 | 38 | public Number getLow() { 39 | return low; 40 | } 41 | 42 | public Number getHigh() { 43 | return high; 44 | } 45 | 46 | public boolean contains(Number value) { 47 | return ge(value,low) && le(value,high); 48 | } 49 | 50 | public boolean intersects(Interval interval){ 51 | return le(low, interval.high) && ge(high, interval.low); 52 | } 53 | 54 | public int compareTo(Interval interval) { 55 | int c = compare(low, interval.getLow()); 56 | if(c == 0){ 57 | return compare(high, interval.getHigh()); 58 | } 59 | return c; 60 | } 61 | 62 | 63 | public String toString() { 64 | return "[" + low + ", " + high + "]"; 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/RegexFilterVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import de.unknownreality.dataframe.filter.FilterPredicate; 28 | import de.unknownreality.dataframe.generated.PredicateBaseVisitor; 29 | import de.unknownreality.dataframe.generated.PredicateParser; 30 | 31 | import java.util.regex.Pattern; 32 | 33 | /** 34 | * Created by Alex on 21.05.2017. 35 | */ 36 | public class RegexFilterVisitor extends PredicateBaseVisitor { 37 | 38 | @Override 39 | public FilterPredicate visitRegex_filter(PredicateParser.Regex_filterContext ctx) { 40 | String colName = FieldFilterVisitor.getColname(ctx.variable().getText()); 41 | return FilterPredicate.matches(colName,convertPattern(ctx.REGEX().getText())); 42 | } 43 | private static Pattern convertPattern(String text){ 44 | String regex = text; 45 | if(!regex.startsWith("/") || ! regex.endsWith("/")){ 46 | throw new PredicateCompilerException(String.format("wrong pattern format: %s",text)); 47 | } 48 | regex = regex.substring(1,regex.length()-1); 49 | return Pattern.compile(regex); 50 | 51 | } 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/common/math/Quantiles.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.common.math; 26 | 27 | import de.unknownreality.dataframe.common.NumberUtil; 28 | 29 | import java.util.Arrays; 30 | 31 | /** 32 | * Created by Alex on 17.07.2017. 33 | */ 34 | public class Quantiles { 35 | private final T[] values; 36 | private final Class cl; 37 | 38 | public Quantiles(T[] values, Class cl, boolean sorted) { 39 | if (values == null || values.length == 0) { 40 | throw new IllegalArgumentException("empty value arrays are not allowed for quantile calculations"); 41 | } 42 | this.values = values; 43 | this.cl = cl; 44 | if (!sorted) { 45 | Arrays.sort(values); 46 | } 47 | } 48 | 49 | public T getQuantile(double quantile) { 50 | int index = (int) Math.ceil(quantile * values.length) - 1; 51 | index = Math.max(index, 0); 52 | return values[index]; 53 | } 54 | public T median() { 55 | return NumberUtil.convert(values[values.length / 2], cl); 56 | } 57 | 58 | public T max(){ 59 | return values[values.length -1 ]; 60 | } 61 | 62 | public T min(){ 63 | return values[0]; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/DataFrameWriterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | import de.unknownreality.dataframe.io.FileFormat; 28 | import org.junit.Assert; 29 | import org.junit.Rule; 30 | import org.junit.Test; 31 | import org.junit.rules.ExpectedException; 32 | 33 | import java.io.IOException; 34 | import java.io.StringWriter; 35 | 36 | /** 37 | * Created by Alex on 12.03.2016. 38 | */ 39 | public class DataFrameWriterTest { 40 | @Rule 41 | public final ExpectedException exception = ExpectedException.none(); 42 | 43 | 44 | 45 | @Test 46 | public void writerTest() throws IOException { 47 | 48 | DataFrame res = DataFrame.fromCSV("loader_test.csv", DataFrameWriterTest.class.getClassLoader(), ';', false); 49 | Assert.assertEquals(5, res.size()); 50 | Assert.assertEquals(3, res.getColumns().size()); 51 | 52 | StringWriter stringWriter = new StringWriter(); 53 | res.write(stringWriter); 54 | String content = stringWriter.toString(); 55 | 56 | DataFrame res2 = DataFrame.load(content, FileFormat.TSV); 57 | 58 | Assert.assertEquals(res, res2); 59 | 60 | res2 = DataFrame.load(content.getBytes(), FileFormat.TSV); 61 | 62 | Assert.assertEquals(res, res2); 63 | } 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/FieldFilterOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | /** 31 | * Created by Alex on 21.05.2017. 32 | */ 33 | public enum FieldFilterOperation { 34 | 35 | EQ("EQ","eq","=","=="), 36 | NE("NE","ne","!="), 37 | LE("LE","le","<="), 38 | LT("LT","lt","<"), 39 | GE("GE","ge",">="), 40 | GT("GT","Gt",">"), 41 | LIKE("LIKE"); 42 | private final String[] aliases; 43 | 44 | FieldFilterOperation(String... aliases){ 45 | this.aliases = aliases; 46 | } 47 | 48 | /** 49 | * Getter for property 'aliases'. 50 | * 51 | * @return Value for property 'aliases'. 52 | */ 53 | public String[] getAliases() { 54 | return aliases; 55 | } 56 | 57 | 58 | private final static Map ALIASES_MAP = new HashMap<>(); 59 | static{ 60 | for(FieldFilterOperation fieldOperation : values()){ 61 | for(String alias : fieldOperation.aliases){ 62 | ALIASES_MAP.put(alias,fieldOperation); 63 | } 64 | } 65 | } 66 | 67 | public static FieldFilterOperation find(String alias){ 68 | return ALIASES_MAP.get(alias); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/sort/SortColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.sort; 26 | 27 | /** 28 | * Created by Alex on 09.03.2016. 29 | */ 30 | public class SortColumn { 31 | public enum Direction { 32 | Ascending, 33 | Descending 34 | } 35 | 36 | private final String name; 37 | private final Direction direction; 38 | 39 | /** 40 | * Creates a sort column from a column header name and a sort direction 41 | * 42 | * @param name column header name 43 | * @param direction sort direction 44 | */ 45 | public SortColumn(String name, Direction direction) { 46 | this.name = name; 47 | this.direction = direction; 48 | } 49 | 50 | /** 51 | * Creates a sort column from a header name using the default sort direction (ascending) 52 | * 53 | * @param name column header name 54 | */ 55 | public SortColumn(String name) { 56 | this.name = name; 57 | this.direction = Direction.Ascending; 58 | } 59 | 60 | /** 61 | * Returns the column name 62 | * 63 | * @return column name 64 | */ 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | /** 70 | * Returns the sort directions 71 | * 72 | * @return sort direction 73 | */ 74 | public Direction getDirection() { 75 | return direction; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/CharacterColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | 28 | import de.unknownreality.dataframe.type.impl.CharacterType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class CharacterColumn extends BasicColumn { 34 | 35 | private final static CharacterType valueType = new CharacterType(); 36 | 37 | public CharacterColumn() { 38 | super(Character.class); 39 | } 40 | 41 | public CharacterColumn(String name) { 42 | super(name, Character.class); 43 | } 44 | 45 | public CharacterColumn(String name, Character[] values) { 46 | super(name, values); 47 | } 48 | 49 | public CharacterColumn(String name, Character[] values, int size) { 50 | super(name, values, size); 51 | } 52 | 53 | 54 | @Override 55 | public CharacterType getValueType() { 56 | return valueType; 57 | } 58 | 59 | @Override 60 | protected CharacterColumn getThis() { 61 | return this; 62 | } 63 | 64 | 65 | @Override 66 | public CharacterColumn copy() { 67 | Character[] copyValues = new Character[values.length]; 68 | toArray(copyValues); 69 | return new CharacterColumn(getName(), copyValues, size()); 70 | } 71 | 72 | @Override 73 | public CharacterColumn copyEmpty() { 74 | return new CharacterColumn(getName()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/impl/LeftJoin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.join.impl; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | import de.unknownreality.dataframe.join.JoinColumn; 29 | import de.unknownreality.dataframe.join.JoinInfo; 30 | import de.unknownreality.dataframe.join.JoinOperation; 31 | import de.unknownreality.dataframe.join.JoinedDataFrame; 32 | 33 | import static de.unknownreality.dataframe.join.impl.DirectionJoinUtil.createDirectionJoin; 34 | import static de.unknownreality.dataframe.join.impl.JoinOperationUtil.createJoinInfo; 35 | 36 | /** 37 | * Created by Alex on 10.07.2016. 38 | */ 39 | public class LeftJoin implements JoinOperation { 40 | public LeftJoin() { 41 | } 42 | 43 | /** 44 | * Joins two data frames using the LEFT JOIN method 45 | * 46 | * @param dfA first data frame 47 | * @param dfB second data frame 48 | * @param joinSuffixA suffix used for columns from the first data frame 49 | * @param joinSuffixB suffix used for columns from the second data frame 50 | * @param joinColumns columns used for the join 51 | * @return joined data frame 52 | */ 53 | @Override 54 | public JoinedDataFrame join(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns) { 55 | JoinInfo joinInfo = createJoinInfo(dfA, dfB, joinColumns, joinSuffixA, joinSuffixB); 56 | return createDirectionJoin(dfA, dfB, joinInfo, joinColumns); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/join/impl/RightJoin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.join.impl; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | import de.unknownreality.dataframe.join.JoinColumn; 29 | import de.unknownreality.dataframe.join.JoinInfo; 30 | import de.unknownreality.dataframe.join.JoinOperation; 31 | import de.unknownreality.dataframe.join.JoinedDataFrame; 32 | 33 | import static de.unknownreality.dataframe.join.impl.DirectionJoinUtil.createDirectionJoin; 34 | import static de.unknownreality.dataframe.join.impl.JoinOperationUtil.createJoinInfo; 35 | 36 | /** 37 | * Created by Alex on 10.07.2016. 38 | */ 39 | public class RightJoin implements JoinOperation { 40 | public RightJoin() { 41 | } 42 | 43 | /** 44 | * Joins two data frames using the RIGHT JOIN method 45 | * 46 | * @param dfA first data frame 47 | * @param dfB second data frame 48 | * @param joinSuffixA suffix used for columns from the first data frame 49 | * @param joinSuffixB suffix used for columns from the second data frame 50 | * @param joinColumns columns used for the join 51 | * @return joined data frame 52 | */ 53 | @Override 54 | public JoinedDataFrame join(DataFrame dfA, DataFrame dfB, String joinSuffixA, String joinSuffixB, JoinColumn... joinColumns) { 55 | JoinInfo joinInfo = createJoinInfo(dfA, dfB, joinColumns, joinSuffixA, joinSuffixB); 56 | return createDirectionJoin(dfB, dfA, joinInfo, joinColumns); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/GZipUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | import java.io.*; 32 | import java.util.zip.GZIPInputStream; 33 | 34 | /** 35 | * Created by Alex on 02.06.2016. 36 | */ 37 | public class GZipUtil { 38 | private static final Logger log = LoggerFactory.getLogger(GZipUtil.class); 39 | 40 | /** 41 | * Returns true if the specified file is gzipped 42 | * 43 | * @param file file to test 44 | * @return true if file is gzipped 45 | */ 46 | public static boolean isGzipped(File file) { 47 | try { 48 | return isGzipped(new FileInputStream(file)); 49 | } catch (Exception e) { 50 | log.error("error opening file", e); 51 | } 52 | return false; 53 | } 54 | 55 | /** 56 | * Returns true if specified {@link InputStream} is gzipped 57 | * 58 | * @param is Input stream to test 59 | * @return true if input stream is gzipped 60 | */ 61 | public static boolean isGzipped(InputStream is) { 62 | if (!is.markSupported()) { 63 | is = new BufferedInputStream(is); 64 | } 65 | is.mark(2); 66 | int m; 67 | try { 68 | m = is.read() & 0xff | ((is.read() << 8) & 0xff00); 69 | is.reset(); 70 | } catch (IOException e) { 71 | return false; 72 | } 73 | return m == GZIPInputStream.GZIP_MAGIC; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/ColumnConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | import de.unknownreality.dataframe.DataFrameException; 29 | import de.unknownreality.dataframe.column.DoubleColumn; 30 | import de.unknownreality.dataframe.column.IntegerColumn; 31 | import de.unknownreality.dataframe.transform.StringColumnConverter; 32 | import org.junit.Assert; 33 | import org.junit.Test; 34 | 35 | /** 36 | * Created by Alex on 28.06.2017. 37 | */ 38 | public class ColumnConverterTest { 39 | @Test 40 | public void testColumnConverter() throws DataFrameException { 41 | DataFrame dataFrame = DataFrame.create(); 42 | dataFrame.addStringColumn("double"); 43 | dataFrame.addStringColumn("integer"); 44 | dataFrame.append("1","1"); 45 | dataFrame.append("2","2"); 46 | dataFrame.append("3","3"); 47 | dataFrame.append("3.5","4"); 48 | dataFrame.append("4.5","5"); 49 | 50 | 51 | DoubleColumn doubles = StringColumnConverter.convert(dataFrame.getStringColumn("double"), DoubleColumn.class); 52 | IntegerColumn integers = StringColumnConverter.convert(dataFrame.getStringColumn("integer"),IntegerColumn.class); 53 | 54 | for(int i = 0; i < dataFrame.size(); i++){ 55 | Assert.assertEquals((Double)Double.parseDouble(dataFrame.getRow(i).getString("double")), doubles.get(i)); 56 | Assert.assertEquals((Integer) Integer.parseInt(dataFrame.getRow(i).getString("integer")), integers.get(i)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/Values.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | /** 28 | * Created by Alex on 12.03.2016. 29 | */ 30 | public class Values { 31 | 32 | /** 33 | * Representation for 'not available'. 34 | * Null values in a row are returned as NA 35 | */ 36 | public static final NA NA = new NA(); 37 | 38 | 39 | private Values(){} 40 | 41 | 42 | /** 43 | * Representation for 'not available'. 44 | * Null values in a row are returned as NA 45 | */ 46 | public static class NA { 47 | 48 | 49 | /** 50 | * checks whether the input object is of type NA or null. 51 | * 52 | * @param o input object 53 | * @return true if the object is of type NA or null 54 | */ 55 | public boolean isNA(Object o) { 56 | if (o == null) { 57 | return true; 58 | } 59 | if (o == this) { 60 | return true; 61 | } 62 | if (o instanceof String) { 63 | return "NA".equals(o.toString()); 64 | } 65 | return false; 66 | } 67 | private NA() { 68 | 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "NA"; 74 | } 75 | 76 | @Override 77 | 78 | public boolean equals(Object o) { 79 | return o == this; 80 | } 81 | 82 | @Override 83 | public int hashCode(){ 84 | return super.hashCode(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/MatchPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | 29 | import java.util.regex.Pattern; 30 | 31 | /** 32 | * Created by Alex on 09.03.2016. 33 | */ 34 | public class MatchPredicate extends FilterPredicate { 35 | private final Pattern pattern; 36 | private final String headerName; 37 | 38 | /** 39 | * Creates a match predicate using a row column name and a pattern string 40 | * 41 | * @param headerName row column name 42 | * @param patternString pattern string 43 | */ 44 | public MatchPredicate(String headerName, String patternString) { 45 | this(headerName, Pattern.compile(patternString)); 46 | } 47 | 48 | /** 49 | * Creates a match predicate using a row column name and a {@link Pattern} 50 | * 51 | * @param headerName row column name 52 | * @param pattern input pattern 53 | */ 54 | public MatchPredicate(String headerName, Pattern pattern) { 55 | this.headerName = headerName; 56 | this.pattern = pattern; 57 | } 58 | 59 | /** 60 | * Returns true if the row column value matches the pattern 61 | * 62 | * @param row tested row 63 | * @return true of row column value matches pattern 64 | */ 65 | @Override 66 | public boolean valid(Row row) { 67 | return pattern.matcher(row.toString(headerName)).matches(); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return headerName + " =~ /" + pattern.toString() + "/"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/PredicateCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import de.unknownreality.dataframe.filter.FilterPredicate; 28 | import de.unknownreality.dataframe.generated.PredicateLexer; 29 | import de.unknownreality.dataframe.generated.PredicateParser; 30 | import org.antlr.v4.runtime.CharStream; 31 | import org.antlr.v4.runtime.CharStreams; 32 | import org.antlr.v4.runtime.CommonTokenStream; 33 | import org.antlr.v4.runtime.ConsoleErrorListener; 34 | 35 | /** 36 | * Created by Alex on 18.05.2017. 37 | */ 38 | public class PredicateCompiler { 39 | 40 | public static FilterPredicate compile(String predicateString){ 41 | predicateString = predicateString.trim(); 42 | if(predicateString.isEmpty()){ 43 | return FilterPredicate.empty(); 44 | } 45 | PredicateCompileErrorListener errorListener = new PredicateCompileErrorListener(predicateString); 46 | 47 | CharStream stream = CharStreams.fromString(predicateString); 48 | PredicateLexer lexer = new PredicateLexer(stream); 49 | lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); 50 | lexer.addErrorListener(errorListener); 51 | CommonTokenStream tokens = new CommonTokenStream(lexer); 52 | PredicateParser parser = new PredicateParser(tokens); 53 | parser.removeErrorListener(ConsoleErrorListener.INSTANCE); 54 | parser.addErrorListener(errorListener); 55 | FilterPredicateVisitor filterPredicateVisitor = new FilterPredicateVisitor(); 56 | return filterPredicateVisitor.visit(parser.compilationUnit()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/LongColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.impl.LongType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class LongColumn extends NumberColumn { 34 | 35 | private final LongType valueType = new LongType(); 36 | 37 | public LongColumn() { 38 | super(Long.class); 39 | } 40 | 41 | public LongColumn(String name) { 42 | super(name, Long.class); 43 | } 44 | 45 | public LongColumn(String name, Long[] values) { 46 | super(name, values); 47 | } 48 | 49 | public LongColumn(String name, Long[] values, int size) { 50 | super(name, values, size); 51 | } 52 | 53 | 54 | @Override 55 | protected LongColumn getThis() { 56 | return this; 57 | } 58 | 59 | @Override 60 | public LongType getValueType() { 61 | return valueType; 62 | } 63 | 64 | @Override 65 | public LongColumn copy() { 66 | Long[] copyValues = new Long[values.length]; 67 | toArray(copyValues); 68 | return new LongColumn(getName(), copyValues, size()); 69 | } 70 | 71 | @Override 72 | public Long getValueFromRow(Row row, H headerName) { 73 | return row.getLong(headerName); 74 | } 75 | 76 | @Override 77 | public Long getValueFromRow(Row row, int headerIndex) { 78 | return row.getLong(headerIndex); 79 | } 80 | 81 | @Override 82 | public LongColumn copyEmpty() { 83 | return new LongColumn(getName()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/ShortColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.impl.ShortType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class ShortColumn extends NumberColumn { 34 | 35 | private final ShortType valueType = new ShortType(); 36 | 37 | public ShortColumn() { 38 | super(Short.class); 39 | } 40 | 41 | public ShortColumn(String name) { 42 | super(name, Short.class); 43 | } 44 | 45 | public ShortColumn(String name, Short[] values) { 46 | super(name, values); 47 | } 48 | 49 | public ShortColumn(String name, Short[] values, int size) { 50 | super(name, values, size); 51 | } 52 | 53 | 54 | @Override 55 | public ShortType getValueType() { 56 | return valueType; 57 | } 58 | 59 | @Override 60 | protected ShortColumn getThis() { 61 | return this; 62 | } 63 | 64 | @Override 65 | public ShortColumn copy() { 66 | Short[] copyValues = new Short[values.length]; 67 | toArray(copyValues); 68 | return new ShortColumn(getName(), copyValues, size()); 69 | } 70 | @Override 71 | public Short getValueFromRow(Row row, H headerName) { 72 | return row.getShort(headerName); 73 | } 74 | 75 | @Override 76 | public Short getValueFromRow(Row row, int headerIndex) { 77 | return row.getShort(headerIndex); 78 | } 79 | 80 | @Override 81 | public ShortColumn copyEmpty() { 82 | return new ShortColumn(getName()); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/FloatColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.impl.FloatType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class FloatColumn extends NumberColumn { 34 | 35 | private final FloatType valueType = new FloatType(); 36 | 37 | @Override 38 | public FloatType getValueType() { 39 | return valueType; 40 | } 41 | 42 | public FloatColumn() { 43 | super(Float.class); 44 | } 45 | 46 | public FloatColumn(String name) { 47 | super(name, Float.class); 48 | } 49 | 50 | public FloatColumn(String name, Float[] values) { 51 | super(name, values); 52 | } 53 | 54 | public FloatColumn(String name, Float[] values, int size) { 55 | super(name, values, size); 56 | } 57 | 58 | 59 | @Override 60 | protected FloatColumn getThis() { 61 | return this; 62 | } 63 | 64 | 65 | @Override 66 | public FloatColumn copy() { 67 | Float[] copyValues = new Float[values.length]; 68 | toArray(copyValues); 69 | return new FloatColumn(getName(), copyValues, size()); 70 | } 71 | @Override 72 | public Float getValueFromRow(Row row, H headerName) { 73 | return row.getFloat(headerName); 74 | } 75 | 76 | @Override 77 | public Float getValueFromRow(Row row, int headerIndex) { 78 | return row.getFloat(headerIndex); 79 | } 80 | 81 | @Override 82 | public FloatColumn copyEmpty() { 83 | return new FloatColumn(getName()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/DoubleColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.impl.DoubleType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class DoubleColumn extends NumberColumn { 34 | 35 | private final DoubleType valueType = new DoubleType(); 36 | 37 | 38 | @Override 39 | public DoubleType getValueType() { 40 | return valueType; 41 | } 42 | 43 | public DoubleColumn() { 44 | super(Double.class); 45 | } 46 | 47 | public DoubleColumn(String name) { 48 | super(name, Double.class); 49 | } 50 | 51 | public DoubleColumn(String name, Double[] values) { 52 | super(name, values); 53 | } 54 | public DoubleColumn(String name, Double[] values, int size) { 55 | super(name, values, size); 56 | } 57 | 58 | @Override 59 | protected DoubleColumn getThis() { 60 | return this; 61 | } 62 | 63 | 64 | @Override 65 | public DoubleColumn copy() { 66 | Double[] copyValues = new Double[values.length]; 67 | toArray(copyValues); 68 | return new DoubleColumn(getName(), copyValues, size()); 69 | } 70 | @Override 71 | public Double getValueFromRow(Row row, H headerName) { 72 | return row.getDouble(headerName); 73 | } 74 | 75 | @Override 76 | public Double getValueFromRow(Row row, int headerIndex) { 77 | return row.getDouble(headerIndex); 78 | } 79 | 80 | @Override 81 | public DoubleColumn copyEmpty() { 82 | return new DoubleColumn(getName()); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/ByteColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.ValueType; 29 | import de.unknownreality.dataframe.type.impl.ByteType; 30 | 31 | /** 32 | * Created by Alex on 09.03.2016. 33 | */ 34 | public class ByteColumn extends NumberColumn { 35 | 36 | private static final ByteType valueType = new ByteType(); 37 | 38 | @Override 39 | public ValueType getValueType() { 40 | return valueType; 41 | } 42 | 43 | public ByteColumn() { 44 | super(Byte.class); 45 | } 46 | 47 | public ByteColumn(String name) { 48 | super(name, Byte.class); 49 | } 50 | 51 | public ByteColumn(String name, Byte[] values) { 52 | super(name, values); 53 | } 54 | 55 | public ByteColumn(String name, Byte[] values, int size) { 56 | super(name, values, size); 57 | } 58 | 59 | @Override 60 | protected ByteColumn getThis() { 61 | return this; 62 | } 63 | 64 | 65 | @Override 66 | public ByteColumn copy() { 67 | Byte[] copyValues = new Byte[values.length]; 68 | toArray(copyValues); 69 | return new ByteColumn(getName(), copyValues, size()); 70 | } 71 | 72 | @Override 73 | public Byte getValueFromRow(Row row, H headerName) { 74 | return row.getByte(headerName); 75 | } 76 | 77 | @Override 78 | public Byte getValueFromRow(Row row, int headerIndex) { 79 | return row.getByte(headerIndex); 80 | } 81 | 82 | @Override 83 | public ByteColumn copyEmpty() { 84 | return new ByteColumn(getName()); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/StringColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | 28 | import de.unknownreality.dataframe.common.Row; 29 | import de.unknownreality.dataframe.type.impl.StringType; 30 | 31 | /** 32 | * Created by Alex on 09.03.2016. 33 | */ 34 | public class StringColumn extends BasicColumn { 35 | 36 | private final static StringType valueType = new StringType(); 37 | 38 | public StringColumn() { 39 | super(String.class); 40 | } 41 | 42 | public StringColumn(String name) { 43 | super(name, String.class); 44 | } 45 | 46 | public StringColumn(String name, String[] values) { 47 | super(name, values); 48 | } 49 | 50 | public StringColumn(String name, String[] values, int size) { 51 | super(name, values, size); 52 | } 53 | 54 | 55 | @Override 56 | public StringType getValueType() { 57 | return valueType; 58 | } 59 | 60 | @Override 61 | protected StringColumn getThis() { 62 | return this; 63 | } 64 | 65 | 66 | @Override 67 | public StringColumn copy() { 68 | String[] copyValues = new String[values.length]; 69 | toArray(copyValues); 70 | return new StringColumn(getName(), copyValues, size()); 71 | } 72 | 73 | @Override 74 | public String getValueFromRow(Row row, H headerName) { 75 | return row.getString(headerName); 76 | } 77 | 78 | @Override 79 | public String getValueFromRow(Row row, int headerIndex) { 80 | return row.getString(headerIndex); 81 | } 82 | 83 | @Override 84 | public StringColumn copyEmpty() { 85 | return new StringColumn(getName()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/sort/RowColumnComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.sort; 26 | 27 | import de.unknownreality.dataframe.DataRow; 28 | 29 | import java.util.Comparator; 30 | 31 | /** 32 | * Created by Alex on 09.03.2016. 33 | */ 34 | public class RowColumnComparator implements Comparator { 35 | private final SortColumn[] sortColumns; 36 | 37 | /** 38 | * Creates a comparator using sort columns 39 | * 40 | * @param sortColumns sort columns 41 | */ 42 | public RowColumnComparator(SortColumn[] sortColumns) { 43 | this.sortColumns = sortColumns; 44 | 45 | } 46 | 47 | /** 48 | * Compares two rows using the sort columns 49 | * 50 | * @param r1 first row 51 | * @param r2 second row 52 | * @return comparison result 53 | */ 54 | @Override 55 | public int compare(DataRow r1, DataRow r2) { 56 | int c = 0; 57 | for (SortColumn sortColumn : sortColumns) { 58 | String name = sortColumn.getName(); 59 | if (r1.isNA(name) && r2.isNA(name)) { 60 | c = 0; 61 | continue; 62 | } 63 | if (r1.isNA(name)) { 64 | return 1; 65 | } 66 | if (r2.isNA(name)) { 67 | return -1; 68 | } 69 | Object a = r1.get(sortColumn.getName()); 70 | Object b = r2.get(sortColumn.getName()); 71 | c = r1.getType(sortColumn.getName()).compareRaw(a, b); 72 | c = sortColumn.getDirection() == SortColumn.Direction.Ascending ? c : -c; 73 | if (c != 0) { 74 | return c; 75 | } 76 | } 77 | return c; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/type/ValueType.java: -------------------------------------------------------------------------------- 1 | package de.unknownreality.dataframe.type; 2 | 3 | import java.io.DataInputStream; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.Writer; 7 | import java.nio.ByteBuffer; 8 | import java.text.ParseException; 9 | import java.util.Comparator; 10 | 11 | public abstract class ValueType { 12 | public abstract Class getType(); 13 | 14 | public abstract Comparator getComparator(); 15 | 16 | public abstract T read(DataInputStream dis) throws IOException; 17 | 18 | public abstract T read(ByteBuffer buf); 19 | 20 | public abstract T parse(String s) throws ParseException; 21 | 22 | public T parseOrNull(String s) { 23 | try { 24 | return parse(s); 25 | } catch (Exception e) { 26 | return null; 27 | } 28 | } 29 | 30 | public void writeRaw(Writer writer, Object value) throws IOException { 31 | write(writer, convertRaw(value)); 32 | } 33 | 34 | public abstract void write(Writer writer, T value) throws IOException; 35 | 36 | public String toStringRaw(Object value) { 37 | return toString(convertRaw(value)); 38 | } 39 | 40 | public abstract String toString(T value); 41 | 42 | 43 | public void writeRaw(DataOutputStream dos, Object value) throws IOException { 44 | write(dos, convertRaw(value)); 45 | } 46 | 47 | public abstract int write(DataOutputStream dos, T value) throws IOException; 48 | 49 | public int compareRaw(Object a, Object b) { 50 | return compare(convertRaw(a), convertRaw(b)); 51 | } 52 | 53 | public boolean equalsRaw(Object a, Object b) { 54 | return equals(convertRaw(a), convertRaw(b)); 55 | } 56 | 57 | public T convertRaw(Object o) { 58 | assertNotNull(o); 59 | if (getType().isInstance(o)) { 60 | return getType().cast(o); 61 | } 62 | throw new ValueTypeRuntimeException( 63 | String.format("error casting raw value of type %s to %s", 64 | o.getClass(), getType())); 65 | } 66 | 67 | public int compare(T a, T b) { 68 | return getComparator().compare(a, b); 69 | } 70 | 71 | public boolean equals(T a, T b) { 72 | return a.equals(b); 73 | } 74 | 75 | 76 | @Override 77 | public boolean equals(Object obj) { 78 | if (obj == null) { 79 | return false; 80 | } 81 | if (!(getClass().isAssignableFrom(obj.getClass()))) { 82 | return false; 83 | } 84 | ValueType other = (ValueType) obj; 85 | return getType().equals(other.getType()); 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return getType().hashCode(); 91 | } 92 | 93 | public static void assertNotNull(Object v) { 94 | if (v == null) { 95 | throw new IllegalArgumentException("null value is not allowed"); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/column/IntegerColumn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.column; 26 | 27 | import de.unknownreality.dataframe.common.Row; 28 | import de.unknownreality.dataframe.type.impl.IntegerType; 29 | 30 | /** 31 | * Created by Alex on 09.03.2016. 32 | */ 33 | public class IntegerColumn extends NumberColumn { 34 | 35 | private final IntegerType valueType = new IntegerType(); 36 | 37 | public IntegerColumn() { 38 | super(Integer.class); 39 | } 40 | 41 | public IntegerColumn(String name) { 42 | super(name, Integer.class); 43 | } 44 | 45 | public IntegerColumn(String name, Integer[] values) { 46 | super(name, values); 47 | } 48 | 49 | public IntegerColumn(String name, Integer[] values, int size) { 50 | super(name, values, size); 51 | } 52 | 53 | 54 | @Override 55 | public IntegerType getValueType() { 56 | return valueType; 57 | } 58 | 59 | @Override 60 | protected IntegerColumn getThis() { 61 | return this; 62 | } 63 | 64 | @Override 65 | public IntegerColumn copy() { 66 | Integer[] copyValues = new Integer[values.length]; 67 | toArray(copyValues); 68 | return new IntegerColumn(getName(), copyValues, size()); 69 | } 70 | 71 | @Override 72 | public Integer getValueFromRow(Row row, H headerName) { 73 | return row.getInteger(headerName); 74 | } 75 | 76 | @Override 77 | public Integer getValueFromRow(Row row, int headerIndex) { 78 | return row.getInteger(headerIndex); 79 | } 80 | 81 | @Override 82 | public IntegerColumn copyEmpty() { 83 | return new IntegerColumn(getName()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/index/interval/IntervalNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.index.interval; 26 | 27 | 28 | public class IntervalNode { 29 | private final Interval interval; 30 | private T value; 31 | private IntervalNode left; 32 | private IntervalNode right; 33 | private long subtreeSize; 34 | private Number max; 35 | 36 | IntervalNode(Interval interval, T value) { 37 | this.interval = interval; 38 | this.subtreeSize = 1; 39 | this.max = interval.high; 40 | this.value = value; 41 | } 42 | 43 | public IntervalNode getRight() { 44 | return right; 45 | } 46 | 47 | public IntervalNode getLeft() { 48 | return left; 49 | } 50 | 51 | public void setRight(IntervalNode right) { 52 | this.right = right; 53 | } 54 | 55 | public void setLeft(IntervalNode left) { 56 | this.left = left; 57 | } 58 | 59 | public T getValue() { 60 | return value; 61 | } 62 | 63 | public Interval getInterval() { 64 | return interval; 65 | } 66 | 67 | public Number getMax() { 68 | return max; 69 | } 70 | 71 | public long getSubtreeSize() { 72 | return subtreeSize; 73 | } 74 | 75 | public void setMax(Number max) { 76 | this.max = max; 77 | } 78 | 79 | public void setValue(T value) { 80 | this.value = value; 81 | } 82 | 83 | public void setSubtreeSize(long subtreeSize) { 84 | this.subtreeSize = subtreeSize; 85 | } 86 | 87 | public int getSubtreeHeight() { 88 | int l = Integer.MIN_VALUE; 89 | int r = Integer.MIN_VALUE; 90 | if (left != null) { 91 | l = left.getSubtreeHeight(); 92 | } 93 | if (right != null) { 94 | r = right.getSubtreeHeight(); 95 | } 96 | return Math.max(1,Math.max(l,r)); 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/filter/compile/ColumnPredicateFilterVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.filter.compile; 26 | 27 | import de.unknownreality.dataframe.filter.FilterPredicate; 28 | import de.unknownreality.dataframe.generated.PredicateBaseVisitor; 29 | import de.unknownreality.dataframe.generated.PredicateParser; 30 | 31 | /** 32 | * Created by Alex on 21.05.2017. 33 | */ 34 | public class ColumnPredicateFilterVisitor extends PredicateBaseVisitor { 35 | 36 | @Override 37 | public FilterPredicate visitColumn_predicate(PredicateParser.Column_predicateContext ctx) { 38 | String colNameA = FieldFilterVisitor.getColname(ctx.COLUMN(0).getText()); 39 | String colNameB = FieldFilterVisitor.getColname(ctx.COLUMN(1).getText()); 40 | return createColumnFieldFilter(colNameA,colNameB,ctx.FIELD_OPERATION().getText()); 41 | } 42 | 43 | private static FilterPredicate createColumnFieldFilter(String colNameA, String colNameB, String operation) { 44 | FieldFilterOperation fieldFilterOperation = FieldFilterOperation.find(operation); 45 | 46 | switch (fieldFilterOperation) { 47 | case EQ: 48 | return FilterPredicate.eqColumn(colNameA, colNameB); 49 | case NE: 50 | return FilterPredicate.neColumn(colNameA, colNameB); 51 | case LE: 52 | return FilterPredicate.leColumn(colNameA, colNameB); 53 | case LT: 54 | return FilterPredicate.ltColumn(colNameA, colNameB); 55 | case GE: 56 | return FilterPredicate.geColumn(colNameA, colNameB); 57 | case GT: 58 | return FilterPredicate.gtColumn(colNameA, colNameB); 59 | default: 60 | throw new PredicateCompilerException(String.format("unsupported filter operation '%s'", operation)); 61 | 62 | } 63 | } 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/ColumnInformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.DataFrameColumn; 28 | import de.unknownreality.dataframe.DataFrameRuntimeException; 29 | import de.unknownreality.dataframe.column.StringColumn; 30 | import de.unknownreality.dataframe.type.DataFrameTypeManager; 31 | 32 | /** 33 | * Created by Alex on 17.06.2017. 34 | */ 35 | public class ColumnInformation { 36 | private final boolean autodetect; 37 | private final String name; 38 | private final int index; 39 | private Class columnType; 40 | 41 | 42 | public ColumnInformation(int index, String name, Class type) { 43 | this.index = index; 44 | this.name = name; 45 | this.columnType = DataFrameTypeManager.get().getColumnType(type); 46 | if (columnType == null) { 47 | throw new DataFrameRuntimeException(String.format("no column type found for value type '%s'", type)); 48 | } 49 | this.autodetect = false; 50 | } 51 | 52 | public ColumnInformation(int index, String name){ 53 | this.index = index; 54 | this.name = name; 55 | this.autodetect = false; 56 | } 57 | 58 | public void setColumnType(Class columnType) { 59 | this.columnType = columnType; 60 | } 61 | 62 | public ColumnInformation(int index, String name, boolean autodetect){ 63 | this.index = index; 64 | this.name = name; 65 | this.columnType = StringColumn.class; 66 | this.autodetect = autodetect; 67 | } 68 | public boolean isAutodetect() { 69 | return autodetect; 70 | } 71 | 72 | public String getName() { 73 | return name; 74 | } 75 | 76 | public int getIndex() { 77 | return index; 78 | } 79 | 80 | public Class getColumnType() { 81 | return columnType; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/de/unknownreality/dataframe/DataFrameConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe; 26 | 27 | import org.junit.Assert; 28 | import org.junit.Test; 29 | 30 | import java.util.Locale; 31 | 32 | public class DataFrameConverterTest { 33 | @Test 34 | public void testAutoDetection(){ 35 | 36 | StringBuilder csvString = new StringBuilder(); 37 | csvString.append("x;y;v;b\n"); 38 | for (int i = 0; i < 1000; i++) { 39 | csvString.append(String.format(Locale.US, "%d;%f;%s;%b", i, i * 0.7, i + "s", true)); 40 | csvString.append("\n"); 41 | } 42 | 43 | DataFrame df = DataFrame.fromCSV(csvString.toString(), ';', true); 44 | Assert.assertEquals(Integer.class, df.getHeader().getValueType("x").getType()); 45 | Assert.assertEquals(Double.class, df.getHeader().getValueType("y").getType()); 46 | Assert.assertEquals(String.class, df.getHeader().getValueType("v").getType()); 47 | Assert.assertEquals(Boolean.class, df.getHeader().getValueType("b").getType()); 48 | 49 | 50 | csvString = new StringBuilder(); 51 | csvString.append("x;y;v;b\n"); 52 | for (int i = 0; i < 1000; i++) { 53 | if (i == 101) { 54 | csvString.append(String.format(Locale.US, "%s;%f;%s;%b", "x", i * 0.7, i + "s", true)); 55 | } else { 56 | csvString.append(String.format(Locale.US, "%d;%f;%s;%b", i, i * 0.7, i + "s", true)); 57 | } 58 | csvString.append("\n"); 59 | } 60 | 61 | df = DataFrame.fromCSV(csvString.toString(), ';', true); 62 | Assert.assertEquals(String.class, df.getHeader().getValueType("x").getType()); 63 | Assert.assertEquals(Double.class, df.getHeader().getValueType("y").getType()); 64 | Assert.assertEquals(String.class, df.getHeader().getValueType("v").getType()); 65 | Assert.assertEquals(Boolean.class, df.getHeader().getValueType("b").getType()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/print/ColumnPrintSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.print; 26 | 27 | public class ColumnPrintSettings { 28 | private Object columnHeader; 29 | private ValueFormatter valueFormatter; 30 | private ValueFormatter headerFormatter; 31 | private Integer width; 32 | private Integer maxContentWidth; 33 | private boolean autoWidth; 34 | 35 | public boolean isAutoWidth() { 36 | return autoWidth; 37 | } 38 | 39 | public void setAutoWidth(boolean autoWidth) { 40 | this.autoWidth = autoWidth; 41 | } 42 | 43 | public ColumnPrintSettings(Object columnHeader) { 44 | this.columnHeader = columnHeader; 45 | } 46 | 47 | public ColumnPrintSettings() { 48 | } 49 | 50 | public Integer getMaxContentWidth() { 51 | return maxContentWidth; 52 | } 53 | 54 | public void setMaxContentWidth(Integer maxContentWidth) { 55 | this.maxContentWidth = maxContentWidth; 56 | } 57 | 58 | public Integer getWidth() { 59 | return width; 60 | } 61 | 62 | public void setWidth(Integer width) { 63 | this.width = width; 64 | } 65 | 66 | public Object getColumnName() { 67 | return columnHeader; 68 | } 69 | 70 | public void setColumnName(Object columnName) { 71 | this.columnHeader = columnName; 72 | } 73 | 74 | public ValueFormatter getValueFormatter() { 75 | return valueFormatter; 76 | } 77 | 78 | public void setValueFormatter(ValueFormatter valueFormatter) { 79 | this.valueFormatter = valueFormatter; 80 | } 81 | 82 | public Object getColumnHeader() { 83 | return columnHeader; 84 | } 85 | 86 | public void setColumnHeader(Object columnHeader) { 87 | this.columnHeader = columnHeader; 88 | } 89 | 90 | public ValueFormatter getHeaderFormatter() { 91 | return headerFormatter; 92 | } 93 | 94 | public void setHeaderFormatter(ValueFormatter headerFormatter) { 95 | this.headerFormatter = headerFormatter; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/io/DataReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.io; 26 | 27 | import de.unknownreality.dataframe.DataFrameRuntimeException; 28 | import de.unknownreality.dataframe.common.Row; 29 | 30 | import java.io.*; 31 | import java.net.URL; 32 | import java.nio.charset.Charset; 33 | import java.util.zip.GZIPInputStream; 34 | 35 | /** 36 | * Created by Alex on 17.06.2017. 37 | */ 38 | public abstract class DataReader, C extends DataIterator> { 39 | 40 | public Charset getCharset() { 41 | return Charset.defaultCharset(); 42 | } 43 | 44 | public C load(File file) { 45 | try { 46 | if (GZipUtil.isGzipped(file)) { 47 | InputStream is = new GZIPInputStream(new FileInputStream(file)); 48 | return load(is); 49 | } 50 | return load(new InputStreamReader(new FileInputStream(file), getCharset())); 51 | } catch (IOException e) { 52 | throw new DataFrameRuntimeException(String.format("error loading file '%s'", file.getAbsolutePath()), e); 53 | } 54 | } 55 | 56 | public C load(String content) { 57 | StringReader reader = new StringReader(content); 58 | return load(reader); 59 | } 60 | 61 | public C load(String resource, ClassLoader classLoader) { 62 | InputStream is = classLoader.getResourceAsStream(resource); 63 | return load(is); 64 | } 65 | 66 | public C load(URL url) { 67 | InputStream is; 68 | try { 69 | is = url.openStream(); 70 | } catch (IOException e) { 71 | throw new DataFrameRuntimeException(String.format("error opening url stream '%s'", url), e); 72 | } 73 | return load(is); 74 | } 75 | 76 | public C load(byte[] bytes) { 77 | ByteArrayInputStream is = new ByteArrayInputStream(bytes); 78 | return load(is); 79 | } 80 | 81 | public C load(InputStream is) { 82 | InputStreamReader reader = new InputStreamReader(is); 83 | return load(reader); 84 | } 85 | 86 | public abstract C load(Reader reader); 87 | } 88 | -------------------------------------------------------------------------------- /src/main/antlr4/de/unknownreality/dataframe/generated/Predicate.g4: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Alexander Grün 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | grammar Predicate; 24 | 25 | /* 26 | * Parser Rules 27 | */ 28 | 29 | compilationUnit : predicate EOF ; 30 | 31 | field_filter : 32 | NEGATE? OPEN_BRACKET field_filter CLOSE_BRACKET| 33 | variable FIELD_OPERATION value| 34 | column_predicate| 35 | regex_filter| 36 | boolean_filter 37 | ; 38 | 39 | 40 | boolean_filter : 41 | variable | (NEGATE variable); 42 | 43 | regex_filter : 44 | variable MATCH REGEX; 45 | 46 | column_predicate : 47 | COLUMN FIELD_OPERATION COLUMN; 48 | 49 | predicate: 50 | NEGATE? OPEN_BRACKET predicate CLOSE_BRACKET | 51 | OPEN_BRACKET predicate PREDICATE_OPERATION predicate CLOSE_BRACKET| 52 | predicate PREDICATE_OPERATION predicate| 53 | field_filter; 54 | 55 | 56 | value: (NUMBER | BOOLEAN_VALUE | TEXT_VALUE | NULL); 57 | variable: VAR | COLUMN; 58 | /* 59 | * Lexer Rules 60 | */ 61 | fragment DIGIT : [0-9]; 62 | fragment COL_PREFIX : '.'; 63 | 64 | fragment CHAR : [a-zA-Z]; 65 | fragment STRING : '\'' (~('\'')|'\\\'') * '\''|'"' (~('"')|'\\"')* '"'; 66 | 67 | fragment UNESCAPED_STRING :~('.'| ' '|')' | '(' | '!') ~('\''|' '|')' | '(')*; 68 | 69 | fragment EQ : ('EQ' | 'eq' | '=' | '=='); 70 | fragment NE : ('NE' | 'ne' | '!='); 71 | fragment LE : ('LE' | 'le' | '<='); 72 | fragment LT : ('LT' | 'lt' | '<'); 73 | fragment GE : ('GE' | 'ge' | '>='); 74 | fragment GT : ('GT' | 'gt' | '>'); 75 | fragment LIKE : ('LIKE' | 'like'); 76 | REGEX : '/' (~('/') | '\\/')+ '/'; 77 | MATCH : ('~=' | '~' ); 78 | 79 | 80 | fragment AND : ('AND' | 'and' | '&' | '&&'); 81 | fragment OR : ('OR' | 'or' | '|' | '||'); 82 | fragment XOR : ('XOR' | 'xor') ; 83 | fragment NOR : ('NOR' | 'nor') ; 84 | fragment VAR_NAME : (UNESCAPED_STRING | STRING); 85 | 86 | OPEN_BRACKET: '('; 87 | CLOSE_BRACKET: ')'; 88 | 89 | NEGATE: '!'; 90 | 91 | PREDICATE_OPERATION : AND | OR | XOR | NOR; 92 | 93 | FIELD_OPERATION : EQ | NE |LE | LT | GT | GE | LIKE; 94 | 95 | NUMBER : '-'? DIGIT+([.,]DIGIT+)?; 96 | BOOLEAN_VALUE: 'true' | 'false'; 97 | TEXT_VALUE : STRING; 98 | NULL: 'null' | 'NULL' | 'NA' | 'na'; 99 | 100 | COLUMN : COL_PREFIX VAR_NAME; 101 | VAR: VAR_NAME; 102 | WHITESPACE : ' ' -> skip ; 103 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/transform/CountTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.transform; 26 | 27 | import de.unknownreality.dataframe.DataFrame; 28 | import de.unknownreality.dataframe.DataFrameColumn; 29 | import de.unknownreality.dataframe.DefaultDataFrame; 30 | import de.unknownreality.dataframe.column.IntegerColumn; 31 | 32 | import java.util.LinkedHashMap; 33 | import java.util.Map; 34 | 35 | /** 36 | * Created by algru on 06.09.2016. 37 | */ 38 | public class CountTransformer implements ColumnDataFrameTransform> { 39 | public static final String COUNTS_COLUMN = "counts"; 40 | private final boolean ignoreNA; 41 | 42 | public CountTransformer(boolean ignoreNA) { 43 | this.ignoreNA = ignoreNA; 44 | } 45 | 46 | public CountTransformer() { 47 | this(true); 48 | } 49 | 50 | /** 51 | * Creates a new dataframe containing the values of the input column and a column with the corresponding counts 52 | * 53 | * @param source input column 54 | * @return count dataframe 55 | */ 56 | @Override 57 | public DataFrame transform(DataFrameColumn source) { 58 | DataFrame countDataFrame = new DefaultDataFrame(); 59 | DataFrameColumn valueColumn = source.copyEmpty(); 60 | valueColumn.setName(source.getName()); 61 | IntegerColumn countColumn = new IntegerColumn(COUNTS_COLUMN); 62 | 63 | Map counts = new LinkedHashMap<>(); 64 | for (int i = 0; i < source.size(); i++) { 65 | if (ignoreNA && source.isNA(i)) { 66 | continue; 67 | } 68 | T v = source.get(i); 69 | Integer count = counts.get(v); 70 | count = count == null ? 0 : count; 71 | count++; 72 | counts.put(v, count); 73 | } 74 | for (Map.Entry entry : counts.entrySet()) { 75 | valueColumn.append(entry.getKey()); 76 | countColumn.append(entry.getValue()); 77 | } 78 | countDataFrame.addColumn(valueColumn); 79 | countDataFrame.addColumn(countColumn); 80 | return countDataFrame; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/csv/CSVWriterBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.csv; 26 | 27 | import de.unknownreality.dataframe.io.WriterBuilder; 28 | 29 | import java.nio.charset.Charset; 30 | 31 | /** 32 | * Created by Alex on 17.06.2017. 33 | */ 34 | public class CSVWriterBuilder implements WriterBuilder { 35 | private char separator = '\t'; 36 | private String headerPrefix = ""; 37 | private boolean containsHeader = true; 38 | private boolean gzip = false; 39 | private boolean quoteStrings = false; 40 | private Charset charset; 41 | 42 | private CSVWriterBuilder() { 43 | } 44 | 45 | public static CSVWriterBuilder create() { 46 | return new CSVWriterBuilder(); 47 | } 48 | 49 | 50 | public CSVWriterBuilder withSeparator(char separator) { 51 | this.separator = separator; 52 | return this; 53 | } 54 | 55 | public CSVWriterBuilder withHeaderPrefix(String headerPrefix){ 56 | this.headerPrefix = headerPrefix; 57 | return this; 58 | } 59 | 60 | public CSVWriterBuilder withHeader(boolean header){ 61 | this.containsHeader = header; 62 | return this; 63 | } 64 | 65 | @Deprecated 66 | public CSVWriterBuilder containsHeader(boolean header){ 67 | this.containsHeader = header; 68 | return this; 69 | } 70 | 71 | public CSVWriterBuilder quoteStrings(boolean quoteStrings) { 72 | this.quoteStrings = quoteStrings; 73 | return this; 74 | } 75 | 76 | public CSVWriterBuilder useGzip(boolean gzip) { 77 | this.gzip = gzip; 78 | return this; 79 | } 80 | 81 | public CSVWriterBuilder withCharset(Charset charset) { 82 | this.charset = charset; 83 | return this; 84 | } 85 | 86 | 87 | @Override 88 | public CSVWriter build() { 89 | CSVSettings settings = new CSVSettings(); 90 | settings.setSeparator(separator); 91 | settings.setHeaderPrefix(headerPrefix); 92 | settings.setContainsHeader(containsHeader); 93 | settings.setGzip(gzip); 94 | settings.setCharset(charset); 95 | settings.setQuoteStrings(quoteStrings); 96 | return new CSVWriter(settings); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/index/Index.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.index; 26 | 27 | import de.unknownreality.dataframe.DataFrameColumn; 28 | import de.unknownreality.dataframe.DataRow; 29 | 30 | import java.util.Collection; 31 | import java.util.List; 32 | 33 | /** 34 | * Created by Alex on 27.05.2016. 35 | */ 36 | public interface Index { 37 | /** 38 | * updates a {@link DataRow} in this index 39 | * 40 | * @param dataRow data row to update 41 | */ 42 | void update(DataRow dataRow); 43 | 44 | 45 | /** 46 | * removes a {@link DataRow} from this index 47 | * 48 | * @param dataRow data row to remove 49 | */ 50 | void remove(DataRow dataRow); 51 | 52 | /** 53 | * Returns the row number for values used in this index 54 | * 55 | * @param values indexed row values 56 | * @return index of row with the input value 57 | */ 58 | Collection find(Object... values); 59 | 60 | /** 61 | * Returns the name if this index 62 | * 63 | * @return name of index 64 | */ 65 | String getName(); 66 | 67 | /** 68 | * set true if only unique values are allowed for this index 69 | * @param unique allow only unique values 70 | */ 71 | void setUnique(boolean unique); 72 | 73 | 74 | /** 75 | * Returns true if this index contains the specified column 76 | * 77 | * @param column column to tes t 78 | * @return true if column is contained in this index 79 | */ 80 | boolean containsColumn(DataFrameColumn column); 81 | 82 | /** 83 | * Returns true if this index is unique 84 | * 85 | * @return true if this index is unique 86 | */ 87 | boolean isUnique(); 88 | 89 | /** 90 | * Returns the columns used in this index 91 | * 92 | * @return columns in this index 93 | */ 94 | List> getColumns(); 95 | 96 | /** 97 | * Clears this index 98 | */ 99 | void clear(); 100 | 101 | void replaceColumn(DataFrameColumn existing, DataFrameColumn replacement); 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/de/unknownreality/dataframe/transform/StringColumnConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * Copyright (c) 2019 Alexander Grün 4 | * * 5 | * * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * * of this software and associated documentation files (the "Software"), to deal 7 | * * in the Software without restriction, including without limitation the rights 8 | * * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * * copies of the Software, and to permit persons to whom the Software is 10 | * * furnished to do so, subject to the following conditions: 11 | * * 12 | * * The above copyright notice and this permission notice shall be included in all 13 | * * copies or substantial portions of the Software. 14 | * * 15 | * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * * SOFTWARE. 22 | * 23 | */ 24 | 25 | package de.unknownreality.dataframe.transform; 26 | 27 | import de.unknownreality.dataframe.DataFrameColumn; 28 | import de.unknownreality.dataframe.DataFrameException; 29 | import de.unknownreality.dataframe.column.StringColumn; 30 | import de.unknownreality.dataframe.type.DataFrameTypeManager; 31 | import de.unknownreality.dataframe.type.ValueType; 32 | 33 | /** 34 | * Created by Alex on 02.06.2017. 35 | */ 36 | public class StringColumnConverter { 37 | /** 38 | * Converts a StringColumn to a other column type by parsing all values 39 | * 40 | * @param value type of resulting column 41 | * @param type of resulting column 42 | * @param column original column 43 | * @param colType target column type 44 | * @return resulting converted column 45 | * 46 | * @throws DataFrameException thrown if conversion not possible 47 | */ 48 | public static > C convert(StringColumn column, Class colType) throws DataFrameException { 49 | if (colType == StringColumn.class) { 50 | return colType.cast(column.copy()); 51 | } 52 | C newColumn = colType.cast(DataFrameTypeManager.get().createColumn(colType)); 53 | newColumn.setName(column.getName()); 54 | ValueType valueType = newColumn.getValueType(); 55 | if (valueType == null) { 56 | throw new DataFrameException(String.format("no parser defined for column type '%s'", colType.getCanonicalName())); 57 | } 58 | for (int i = 0; i < column.size(); i++) { 59 | if (column.isNA(i)) { 60 | newColumn.appendNA(); 61 | continue; 62 | } 63 | V value = newColumn.getValueType().parseOrNull(column.get(i)); 64 | if (value == null) { 65 | throw new DataFrameException( 66 | String.format("error parsing value '%s' -> %s", 67 | column.get(i), 68 | newColumn.getValueType().getType())); 69 | } else { 70 | newColumn.append(value); 71 | } 72 | } 73 | return newColumn; 74 | } 75 | } 76 | --------------------------------------------------------------------------------