protected final void set(int index, Tuple tuple, int field) { if (tuple.isBlankOrNull(field)) { nulls.set(index); return; } nulls.clear(index); switch (type) { case 0: booleans[index] = tuple.getBool(field); break; case 1: bits[index] = tuple.getByte(field); break; case 2: shorts[index] = tuple.getInt2(field); break; case 3: ints[index] = tuple.getInt4(field); break; case 4: longs[index] = tuple.getInt8(field); break; case 5: floats[index] = tuple.getFloat4(field); break; case 6: doubles[index] = tuple.getFloat8(field); break; case 7: bytes[index] = tuple.getBytes(field); break; case 8: ints[index] = tuple.getInt4(field); break; default: throw new IllegalArgumentException(); } }
private Object getPrimitive(Tuple tuple, int i, Schema.Type avroType) { if (tuple.isBlankOrNull(i)) { return null; } switch (avroType) { case NULL: return null; case BOOLEAN: return tuple.getBool(i); case INT: return tuple.getInt4(i); case LONG: return tuple.getInt8(i); case FLOAT: return tuple.getFloat4(i); case DOUBLE: return tuple.getFloat8(i); case BYTES: case FIXED: return ByteBuffer.wrap(tuple.getBytes(i)); case STRING: return tuple.getText(i); default: throw new RuntimeException("Unknown primitive type."); } }
@Override public void eval(FunctionContext ctx, Tuple params) { if (!params.isBlankOrNull(0)) { SumContext sumCtx = (SumContext)ctx; sumCtx.hasNonNull = true; sumCtx.sum += params.getFloat4(0); } } }
public static byte[] serialize(Column col, Tuple tuple, int index) throws IOException { if (tuple.isBlankOrNull(index)) { return null; } return tuple.getBytes(index); } }
private Object getObject(Tuple tuple, int index) { if (handleNull(tuple, index)) { return null; } TajoDataTypes.Type dataType = schema.getColumn(index).getDataType().getType(); switch(dataType) { case BOOLEAN: return tuple.getBool(index); case INT1: case INT2: return tuple.getInt2(index); case INT4: return tuple.getInt4(index); case INT8: return tuple.getInt8(index); case TEXT: case CHAR: case VARCHAR: return tuple.getText(index); case FLOAT4: return tuple.getFloat4(index); case FLOAT8: return tuple.getFloat8(index); case NUMERIC: return tuple.getFloat8(index); case DATE: { return toDate(tuple.getTimeDate(index), null); } case TIME: { return toTime(tuple.getTimeDate(index), null); } case TIMESTAMP: { return toTimestamp(tuple.getTimeDate(index), timezone); } default: return tuple.asDatum(index).asChars(); } }
Schema schema = createAllTypesSchema(); Tuple tuple = new VTuple(schema.size()); tuple.put(0, DatumFactory.createBool(true)); tuple.put(1, DatumFactory.createChar('t')); tuple.put(2, DatumFactory.createInt2((short)2048)); tuple.put(3, DatumFactory.createInt4(4096)); tuple.put(4, DatumFactory.createInt8(8192L)); tuple.put(5, DatumFactory.createFloat4(0.2f)); tuple.put(6, DatumFactory.createFloat8(4.1)); tuple.put(7, DatumFactory.createText(HELLO)); tuple.put(8, DatumFactory.createBlob(HELLO.getBytes(Charsets.UTF_8))); tuple.put(9, NullDatum.get()); assertEquals(true, tuple.getBool(0)); assertTrue(String.valueOf('t').equals(String.valueOf(tuple.getChar(1)))); assertEquals((short)2048, tuple.getInt2(2)); assertEquals(4096, tuple.getInt4(3)); assertEquals(8192L, tuple.getInt8(4)); assertEquals(new Float(0.2f), new Float(tuple.getFloat4(5))); assertEquals(new Double(4.1), new Double(tuple.getFloat8(6))); assertTrue(HELLO.equals(tuple.getText(7))); assertArrayEquals(HELLO.getBytes(Charsets.UTF_8), tuple.getBytes(8)); assertTrue(tuple.isBlankOrNull(9));
private Object getPrimitive(Tuple tuple, int i, Schema.Type avroType) { if (tuple.get(i) instanceof NullDatum) { return null; } switch (avroType) { case NULL: return null; case BOOLEAN: return tuple.getBool(i); case INT: return tuple.getInt4(i); case LONG: return tuple.getInt8(i); case FLOAT: return tuple.getFloat4(i); case DOUBLE: return tuple.getFloat8(i); case BYTES: case FIXED: return ByteBuffer.wrap(tuple.getBytes(i)); case STRING: return tuple.getText(i); default: throw new RuntimeException("Unknown primitive type."); } }
public static void validateTupleResult(int j, Tuple t) { assertTrue((j % 1 == 0) == t.getBool(0)); assertTrue(1 == t.getInt2(1)); assertEquals(j, t.getInt4(2)); assertEquals(j, t.getInt8(3)); assertTrue(j == t.getFloat4(4)); assertTrue(j == t.getFloat8(5)); assertEquals(new String(UNICODE_FIELD_PREFIX + j), t.getText(6)); assertEquals(DatumFactory.createTimestamp("2014-04-16 08:48:00").asInt8() + (long) j, t.getInt8(7)); assertEquals(DatumFactory.createDate("2014-04-16").asInt4() + j, t.getInt4(8)); assertEquals(DatumFactory.createTime("08:48:00").asInt8() + j, t.getInt8(9)); assertEquals(DatumFactory.createInterval((j + 1) + " hours"), t.getInterval(10)); assertEquals(new ProtobufDatum(ProtoUtil.convertString(j + "")), t.getProtobufDatum(11)); }
@Override public void eval(FunctionContext ctx, Tuple params) { AvgContext avgCtx = (AvgContext) ctx; if (!params.isBlankOrNull(0)) { avgCtx.sum += params.getFloat8(0); avgCtx.count++; } }
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) { return NullDatum.get(); } String addr = params.getText(0); String otherCode = params.getText(1); String thisCode = GeoIPUtil.getCountryCode(addr); return DatumFactory.createBool(thisCode.equals(otherCode)); } }
@Override public void eval(FunctionContext ctx, Tuple params) { if (!params.isBlankOrNull(0)) { SumContext sumCtx = (SumContext) ctx; sumCtx.hasNonNull = true; sumCtx.sum += params.getInt8(0); } }
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) { return NullDatum.get(); } byte [] addr = params.getBytes(0); String otherCode = params.getText(1); String thisCode = GeoIPUtil.getCountryCode(addr); return DatumFactory.createBool(thisCode.equals(otherCode)); } }
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0)) { return NullDatum.get(); } return DatumFactory.createInt4(Math.abs(params.getInt4(0))); } }
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0) || params.isBlankOrNull(1)) { return NullDatum.get(); } return DatumFactory.createText(repeat(params.getText(0), params.getInt4(1))); } }
@Override public void eval(FunctionContext ctx, Tuple params) { LastValueContext lastValueCtx = (LastValueContext) ctx; if (!params.isBlankOrNull(0)) { lastValueCtx.last = params.asDatum(0); } }
private String getString(Tuple tuple, int index) throws SQLException { if (handleNull(tuple, index)) { return null; } switch(tuple.type(index)) { case BOOLEAN: return String.valueOf(tuple.getBool(index)); case TIMESTAMP: return TimestampDatum.asChars(tuple.getTimeDate(index), timezone, false); default : return tuple.asDatum(index).asChars(); } }
private void verifyProjectedFields(boolean projectable, Tuple tuple, int tupleCnt) { if (projectable) { assertTrue(tupleCnt + 2 == tuple.getInt8(0)); assertTrue(tupleCnt + 3 == tuple.getFloat4(1)); } else { // Internal storage always project all fields. if (!internalType) { assertTrue(tuple.isBlankOrNull(0)); } assertTrue(tupleCnt + 2 == tuple.getInt8(1)); assertTrue(tupleCnt + 3 == tuple.getFloat4(2)); } }
/** * Test for readMessage. * * @throws Exception */ @Test public void testScanner() throws Exception { KafkaFragment fragment = new KafkaFragment(KAFKA_SERVER_URI, TOPIC_NAME, TOPIC_NAME, 0, 1, 0, "localhost"); TajoConf conf = new TajoConf(); TableMeta meta = CatalogUtil.newTableMeta(BuiltinStorages.KAFKA, new TajoConf()); KafkaScanner scanner = new KafkaScanner(conf, TABLE_SCHEMA, meta, fragment); scanner.init(); Tuple tuple = scanner.next(); assertTrue(tuple.getInt4(0) == 1); assertTrue(tuple.getText(1).equals("abc")); assertTrue(tuple.getFloat4(2) == 0.2f); scanner.close(); } }
protected final Tuple evalParams(Tuple tuple) { for (int i = 0; i < argEvals.length; i++) { params.put(i, argEvals[i].eval(tuple)); } return params; }