Skip to content

Commit

Permalink
IGNITE-16848 InternalTuple interface extracted from Row. (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibessonov committed May 17, 2022
1 parent 32afeaa commit 7bcd7ca
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 180 deletions.
Expand Up @@ -58,7 +58,7 @@ public static TestObjectWithAllTypes randomObject(Random rnd) {
obj.uuidCol = new UUID(rnd.nextLong(), rnd.nextLong());
obj.bitmaskCol = IgniteTestUtils.randomBitSet(rnd, 42);

obj.dateCol = LocalDate.ofYearDay(1990 + rnd.nextInt(50), rnd.nextInt(360));
obj.dateCol = LocalDate.ofYearDay(1990 + rnd.nextInt(50), 1 + rnd.nextInt(360));
obj.timeCol = LocalTime.of(rnd.nextInt(24), rnd.nextInt(60));
obj.dateTimeCol = LocalDateTime.of(obj.dateCol, obj.timeCol);
obj.timestampCol = Instant.now().plusSeconds(rnd.nextInt(1000));
Expand Down
Expand Up @@ -24,7 +24,7 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.BitSet;
import org.apache.ignite.internal.schema.row.Row;
import org.apache.ignite.internal.schema.row.InternalTuple;
import org.apache.ignite.internal.tostring.S;

/**
Expand All @@ -42,7 +42,7 @@ public enum NativeTypeSpec {
INT8("int8", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.byteValueBoxed(colIdx);
}
},
Expand All @@ -53,7 +53,7 @@ public Object objectValue(Row tup, int colIdx) {
INT16("int16", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.shortValueBoxed(colIdx);
}
},
Expand All @@ -64,7 +64,7 @@ public Object objectValue(Row tup, int colIdx) {
INT32("int32", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.intValueBoxed(colIdx);
}
},
Expand All @@ -75,7 +75,7 @@ public Object objectValue(Row tup, int colIdx) {
INT64("int64", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.longValueBoxed(colIdx);
}
},
Expand All @@ -86,7 +86,7 @@ public Object objectValue(Row tup, int colIdx) {
FLOAT("float", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.floatValueBoxed(colIdx);
}
},
Expand All @@ -97,7 +97,7 @@ public Object objectValue(Row tup, int colIdx) {
DOUBLE("double", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.doubleValueBoxed(colIdx);
}
},
Expand All @@ -108,7 +108,7 @@ public Object objectValue(Row tup, int colIdx) {
DECIMAL("decimal", false) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.decimalValue(colIdx);
}
},
Expand All @@ -119,7 +119,7 @@ public Object objectValue(Row tup, int colIdx) {
UUID("uuid", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.uuidValue(colIdx);
}
},
Expand All @@ -130,7 +130,7 @@ public Object objectValue(Row tup, int colIdx) {
STRING("string") {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.stringValue(colIdx);
}
},
Expand All @@ -141,7 +141,7 @@ public Object objectValue(Row tup, int colIdx) {
BYTES("blob") {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.bytesValue(colIdx);
}
},
Expand All @@ -152,7 +152,7 @@ public Object objectValue(Row tup, int colIdx) {
BITMASK("bitmask", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.bitmaskValue(colIdx);
}
},
Expand All @@ -163,7 +163,7 @@ public Object objectValue(Row tup, int colIdx) {
NUMBER("number", false) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.numberValue(colIdx);
}
},
Expand All @@ -174,7 +174,7 @@ public Object objectValue(Row tup, int colIdx) {
DATE("date", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.dateValue(colIdx);
}
},
Expand All @@ -185,7 +185,7 @@ public Object objectValue(Row tup, int colIdx) {
TIME("time", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.timeValue(colIdx);
}
},
Expand All @@ -196,7 +196,7 @@ public Object objectValue(Row tup, int colIdx) {
DATETIME("datetime", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.dateTimeValue(colIdx);
}
},
Expand All @@ -207,7 +207,7 @@ public Object objectValue(Row tup, int colIdx) {
TIMESTAMP("timestamp", true) {
/** {@inheritDoc} */
@Override
public Object objectValue(Row tup, int colIdx) {
public Object objectValue(InternalTuple tup, int colIdx) {
return tup.timestampValue(colIdx);
}
};
Expand Down Expand Up @@ -254,7 +254,7 @@ public boolean fixedLength() {
* @return An Object representation of the value.
* @throws InvalidTypeException If this native type differs from the actual type of {@code colIdx}.
*/
public abstract Object objectValue(Row row, int colIdx) throws InvalidTypeException;
public abstract Object objectValue(InternalTuple row, int colIdx) throws InvalidTypeException;

/**
* Maps class to native type.
Expand Down
@@ -0,0 +1,223 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.schema.row;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.BitSet;
import java.util.UUID;
import org.apache.ignite.internal.schema.InvalidTypeException;

/**
* General interface to describe tuples outside of their data layout and column schemas.
* Accessor methods may or may not throw {@link InvalidTypeException} depending on the implementation.
*/
public interface InternalTuple {
/**
* Returns a number of values in the tuple.
*/
int count();

/**
* Checks whether the given column contains a null value.
*
* @param col Column index.
* @return {@code true} if this column contains a null value, {@code false} otherwise.
*/
boolean hasNullValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
byte byteValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Byte byteValueBoxed(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
short shortValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Short shortValueBoxed(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
int intValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Integer intValueBoxed(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
long longValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Long longValueBoxed(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
float floatValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Float floatValueBoxed(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
double doubleValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Double doubleValueBoxed(int col);

/**
* Reads value from specified column.
*
* @param col Column index.
* @return Column value.
*/
BigDecimal decimalValue(int col);

/**
* Reads value from specified column.
*
* @param col Column index.
* @return Column value.
*/
BigInteger numberValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
String stringValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
byte[] bytesValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
UUID uuidValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
BitSet bitmaskValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
LocalDate dateValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
LocalTime timeValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
LocalDateTime dateTimeValue(int col);

/**
* Reads value for specified column.
*
* @param col Column index.
* @return Column value.
*/
Instant timestampValue(int col);
}

0 comments on commit 7bcd7ca

Please sign in to comment.