column-table

A simple column-oriented table library

License

License

GroupId

GroupId

com.github.ykiselev
ArtifactId

ArtifactId

column-table
Last Version

Last Version

0.6
Release Date

Release Date

Type

Type

jar
Description

Description

column-table
A simple column-oriented table library
Project URL

Project URL

https://github.com/YKiselev/column-table
Source Code Management

Source Code Management

http://github.com/YKiselev/column-table/tree/master

Download column-table

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ykiselev/column-table/ -->
<dependency>
    <groupId>com.github.ykiselev</groupId>
    <artifactId>column-table</artifactId>
    <version>0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ykiselev/column-table/
implementation 'com.github.ykiselev:column-table:0.6'
// https://jarcasting.com/artifacts/com.github.ykiselev/column-table/
implementation ("com.github.ykiselev:column-table:0.6")
'com.github.ykiselev:column-table:jar:0.6'
<dependency org="com.github.ykiselev" name="column-table" rev="0.6">
  <artifact name="column-table" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ykiselev', module='column-table', version='0.6')
)
libraryDependencies += "com.github.ykiselev" % "column-table" % "0.6"
[com.github.ykiselev/column-table "0.6"]

Dependencies

test (6)

Group / Artifact Type Version
junit : junit jar 4.12
org.thymeleaf : thymeleaf jar 3.0.6.RELEASE
org.apache.velocity : velocity jar 1.7
log4j : log4j jar 1.2.17
org.slf4j : slf4j-log4j12 jar 1.7.25
org.apache.commons : commons-lang3 jar 3.5

Project Modules

There are no modules declared in this project.

Synopsis

This is a library with classes defining in-memory column-oriented growing-only table to be used instead of long-living collections of POJOs (to reduce memory consumption). Has columns for all the primitive types and generic one (to store strings for example). Row access is only by index (like in array index not DBMS index). No fancy stuff like string de-duplication because such functionality is not related to table internals and can be easily added when needed. No queries, no filters.

Code Example

Define table

    class MyTable extends AbstractMutableTable {
    
        private final MutableLongArray id = new MutableLongArray();
    
        private final MutableObjectArray<String> name = new MutableObjectArray<>(String.class);
    
        @Override
        protected Iterable<? extends MutableArray> columns() {
            return Arrays.asList(id, name);
        }
    
    }

Here we define table with 2 columns of different types.

And fill it...

    int row = table.add();
    table.id.set(row, 123L);
    table.name.set(row, "Zeus");

Here we adding new row to the table and then setting id cell value to 123L and name cell value to "Zeus". Our class is derived from com.github.ykiselev.column.table.AbstractMutableTable which implements useful methods like add(). Derived class should implement only one abstract method - com.github.ykiselev.column.table.AbstractMutableTable.columns so that base class will know all it's columns and be able to resize them when needed.

Next thing we can do with our table - serialize it. Each mutable array can be converted to 'normal' Java array by calling method toArray(int length)

    private Object writeReplace() throws ObjectStreamException {
        return new MyTableReplacement(
                rows(),
                id,
                name
        );
    }

where

final class MyTableReplacement implements Serializable {

    private static final long serialVersionUID = 4282998382380376807L;

    private long[] id;

    private String[] name;

    MyTableReplacement(int rows, MutableLongArray id, MutableObjectArray<String> name) {
        this.id = id.toArray(rows);
        this.name = name.toArray(rows);
    }

    Object readResolve() throws ObjectStreamException {
        return new MyImmutableTable(
                id,
                name
        );
    }
}

and this will deserialize into immutable table

final class MyImmutableTable {

    private final long[] id;

    private final String[] name;

    long id(int index) {
        return id[index];
    }

    String name(int index) {
        return name[index];
    }

    MyImmutableTable(long[] id, String[] name) {
        this.id = id;
        this.name = name;
    }
}

Motivation

To decrease memory footprint in (rare) cases when one need big long-living collection of POJOs.

Installation

For maven projects add dependency to pom.xml

<dependency>
    <groupId>com.github.ykiselev</groupId>
    <artifactId>column-table</artifactId>
    <version>0.6</version>
</dependency>

API Reference

Javadoc is in repo along with library.

Tests

mvn clean test or run specific test:

  • com.github.ykiselev.column.table.AbstractMutableTableTest

Contributors

Please e-mail me if you need more info or want to improve something: [email protected]

Downloads

Download the latest jar or

License

This library is licensed under the Apache License, Version 2.0.

Versions

Version
0.6
0.5
0.4
0.3
0.2
0.1