Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void put(Datum[] values) {

@Override
public TajoDataTypes.Type type(int fieldId) {
return values.get(fieldId).type();
return values.get(fieldId).kind();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,18 @@ public static boolean isSigned(Type type) {
}
}

public static boolean isNumeric(Type type) {
return isNumber(type) || isReal(type);
public static boolean isNumeric(org.apache.tajo.type.Type type) {
return isNumber(type) || isReal(type.kind());
}

public static boolean isNumber(Type type) {
public static boolean isNumber(org.apache.tajo.type.Type type) {
return
type == Type.INT2 ||
type == Type.INT4 ||
type == Type.INT8;
type.kind() == Type.INT2 ||
type.kind() == Type.INT4 ||
type.kind() == Type.INT8;
}

public static boolean isReal(Type type) {
return
type == Type.FLOAT4||
type == Type.FLOAT8;
return type == Type.FLOAT4|| type == Type.FLOAT8;
}
}
9 changes: 4 additions & 5 deletions tajo-common/src/main/java/org/apache/tajo/datum/AnyDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
package org.apache.tajo.datum;

import com.google.gson.annotations.Expose;

import static org.apache.tajo.common.TajoDataTypes.Type.ANY;
import org.apache.tajo.type.Type;

/**
* <code>AnyDatum</code> can contain any types of datum.
Expand All @@ -29,7 +28,7 @@ public class AnyDatum extends Datum {
@Expose Datum val;

public AnyDatum(Datum val) {
super(ANY);
super(Type.Any);
this.val = val;
}

Expand Down Expand Up @@ -58,7 +57,7 @@ public boolean equals(Object obj) {

@Override
public Datum equalsTo(Datum datum) {
if (datum.type() == ANY) {
if (datum.type.isAny()) {
AnyDatum other = (AnyDatum) datum;
return val.equalsTo(other.val);
}
Expand All @@ -67,7 +66,7 @@ public Datum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
if (datum.type() == ANY) {
if (datum.type.isAny()) {
AnyDatum other = (AnyDatum) datum;
return val.compareTo(other.val);
}
Expand Down
8 changes: 4 additions & 4 deletions tajo-common/src/main/java/org/apache/tajo/datum/BitDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
package org.apache.tajo.datum;

import com.google.gson.annotations.Expose;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.exception.InvalidOperationException;
import org.apache.tajo.type.Type;
import org.apache.tajo.util.NumberUtil;

public class BitDatum extends Datum {
private static final int size = 1;
@Expose final byte val;

public BitDatum(byte val) {
super(TajoDataTypes.Type.BIT);
super(Type.Bit);
this.val = val;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public boolean equals(Object obj) {

@Override
public Datum equalsTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case BIT:
return DatumFactory.createBool(this.val == (((BitDatum) datum).val));
case NULL_TYPE:
Expand All @@ -117,7 +117,7 @@ public Datum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case BIT:
if (val < datum.asByte() ) {
return -1;
Expand Down
12 changes: 6 additions & 6 deletions tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
import java.nio.charset.Charset;
import java.util.Arrays;

import static org.apache.tajo.common.TajoDataTypes.Type.BLOB;
import static org.apache.tajo.type.Type.Blob;

public class BlobDatum extends Datum {
@Expose private final byte [] val;
private ByteBuffer bb = null;

public BlobDatum(byte[] val) {
super(BLOB);
super(Blob);
this.val = val;
this.bb = ByteBuffer.wrap(val);
bb.flip();
}

public BlobDatum(byte[] val, int offset, int length) {
super(BLOB);
super(Blob);
byte[] b = new byte[length];
System.arraycopy(val, offset, b, 0 , length);
this.val = b;
Expand All @@ -51,7 +51,7 @@ public BlobDatum(byte[] val, int offset, int length) {
}

public BlobDatum(ByteBuffer val) {
super(BLOB);
super(Blob);
this.val = val.array();
this.bb = val.duplicate();
bb.flip();
Expand Down Expand Up @@ -138,7 +138,7 @@ public boolean equals(Object obj) {

@Override
public Datum equalsTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case BLOB:
return DatumFactory.createBool(Arrays.equals(this.val, ((BlobDatum)datum).val));
case NULL_TYPE:
Expand All @@ -150,7 +150,7 @@ public Datum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case BLOB:
initFromBytes();
((BlobDatum)datum).initFromBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

import com.google.common.primitives.Booleans;
import com.google.gson.annotations.Expose;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.exception.InvalidOperationException;

import static org.apache.tajo.type.Type.Bool;

public class BooleanDatum extends Datum {
@Expose private final boolean val;
public static final String TRUE_STRING ="t";
Expand Down Expand Up @@ -57,17 +58,17 @@ public class BooleanDatum extends Datum {
};

private BooleanDatum(boolean val) {
super(TajoDataTypes.Type.BOOLEAN);
super(Bool);
this.val = val;
}

protected BooleanDatum(byte byteVal) {
super(TajoDataTypes.Type.BOOLEAN);
super(Bool);
this.val = byteVal == TRUE_INT;
}

protected BooleanDatum(int byteVal) {
super(TajoDataTypes.Type.BOOLEAN);
super(Bool);
this.val = byteVal == TRUE_INT;
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public boolean equals(Object obj) {

// Datum Comparator
public BooleanDatum equalsTo(Datum datum) {
switch(datum.type()) {
switch(datum.kind()) {
case BOOLEAN: return DatumFactory.createBool(this.val == ((BooleanDatum)datum).val);
default:
throw new InvalidOperationException(datum.type());
Expand All @@ -166,7 +167,7 @@ public BooleanDatum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case BOOLEAN:
return Booleans.compare(val, datum.asBool());
default:
Expand Down
10 changes: 5 additions & 5 deletions tajo-common/src/main/java/org/apache/tajo/datum/CharDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

import java.util.Arrays;

import static org.apache.tajo.common.TajoDataTypes.Type;
import static org.apache.tajo.type.Type.Char;

public class CharDatum extends Datum {
@Expose private final int size;
@Expose private final byte[] bytes;
private String chars = null;

public CharDatum(byte val) {
super(Type.CHAR);
super(Char(1));
this.size = 1;
bytes = new byte[size];
bytes[0] = val;
Expand All @@ -43,7 +43,7 @@ public CharDatum(char val) {
}

public CharDatum(byte [] bytes) {
super(Type.CHAR);
super(Char(1));
this.bytes = bytes;
this.size = bytes.length;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public boolean equals(Object obj) {

@Override
public Datum equalsTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case CHAR:
case VARCHAR:
case TEXT:
Expand All @@ -147,7 +147,7 @@ public Datum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case CHAR:
case TEXT:
return UnsignedBytes.lexicographicalComparator().compare(bytes, datum.asByteArray());
Expand Down
16 changes: 9 additions & 7 deletions tajo-common/src/main/java/org/apache/tajo/datum/DateDatum.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,31 @@
import com.google.common.primitives.Ints;
import org.apache.tajo.common.TajoDataTypes;
import org.apache.tajo.common.TajoDataTypes.Type;
import org.apache.tajo.exception.InvalidValueForCastException;
import org.apache.tajo.exception.InvalidOperationException;
import org.apache.tajo.exception.InvalidValueForCastException;
import org.apache.tajo.exception.TajoRuntimeException;
import org.apache.tajo.util.Bytes;
import org.apache.tajo.util.datetime.DateTimeConstants.DateStyle;
import org.apache.tajo.util.datetime.DateTimeFormat;
import org.apache.tajo.util.datetime.DateTimeUtil;
import org.apache.tajo.util.datetime.TimeMeta;

import static org.apache.tajo.type.Type.Date;

public class DateDatum extends Datum {
public static final int SIZE = 4;

// Dates are stored by local time.
private int jdate;

public DateDatum(int value) {
super(TajoDataTypes.Type.DATE);
super(Date);

jdate = value;
}

public DateDatum(TimeMeta tm) {
super(TajoDataTypes.Type.DATE);
super(Date);
jdate = DateTimeUtil.date2j(tm.years, tm.monthOfYear, tm.dayOfMonth);
}

Expand Down Expand Up @@ -102,7 +104,7 @@ public String toString() {

@Override
public Datum plus(Datum datum) {
switch (datum.type()) {
switch (datum.kind()) {
case INT2:
case INT4:
case INT8: {
Expand All @@ -128,7 +130,7 @@ public Datum plus(Datum datum) {

@Override
public Datum minus(Datum datum) {
switch(datum.type()) {
switch(datum.kind()) {
case INT2:
case INT4:
case INT8: {
Expand Down Expand Up @@ -198,7 +200,7 @@ public int size() {

@Override
public Datum equalsTo(Datum datum) {
if (datum.type() == Type.DATE) {
if (datum.kind() == Type.DATE) {
return DatumFactory.createBool(equals(datum));
} else if (datum.isNull()) {
return datum;
Expand All @@ -209,7 +211,7 @@ public Datum equalsTo(Datum datum) {

@Override
public int compareTo(Datum datum) {
if (datum.type() == TajoDataTypes.Type.DATE) {
if (datum.kind() == TajoDataTypes.Type.DATE) {
DateDatum another = (DateDatum) datum;
return Ints.compare(jdate, another.jdate);
} else if (datum.isNull()) {
Expand Down
Loading