@Test public void testTransform() throws Exception { StructuredRecordToCubeFact transform = new StructuredRecordToCubeFact(createValidConfig()); Schema schema = Schema.recordOf( "record", Schema.Field.of("tsField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("dimField1", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("dimField3", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("boolField", Schema.nullableOf(Schema.of(Schema.Type.BOOLEAN))), Schema.Field.of("intField", Schema.nullableOf(Schema.of(Schema.Type.INT))), Schema.Field.of("longField", Schema.nullableOf(Schema.of(Schema.Type.LONG))), Schema.Field.of("floatField", Schema.nullableOf(Schema.of(Schema.Type.FLOAT))), Schema.Field.of("bytesField", Schema.nullableOf(Schema.of(Schema.Type.BYTES))), Schema.Field.of("metricField1", Schema.nullableOf(Schema.of(Schema.Type.STRING)))); long ts = System.currentTimeMillis(); StructuredRecord record = StructuredRecord.builder(schema) .set("tsField", new SimpleDateFormat(DATE_FORMAT).format(new Date(ts))) .set("dimField1", "dimVal1") .set("dimField3", "dimVal3") .set("boolField", true) .set("intField", 5) .set("longField", 10L) .set("floatField", 3.14f) .set("bytesField", Bytes.toBytes("foo")) .set("metricField1", "15") .build(); CubeFact transformed = transform.transform(record); Assert.assertEquals(ts / 1000, transformed.getTimestamp()); Map<String, String> dims = transformed.getDimensionValues(); Assert.assertEquals(9, dims.size()); Assert.assertEquals(new SimpleDateFormat(DATE_FORMAT).format(new Date(ts)), dims.get("tsField")); Assert.assertEquals("dimVal1", dims.get("dimField1")); Assert.assertEquals("dimVal3", dims.get("dimField3")); Assert.assertEquals("true", dims.get("boolField")); Assert.assertEquals("5", dims.get("intField")); Assert.assertEquals("10", dims.get("longField")); Assert.assertEquals("3.14", dims.get("floatField")); Assert.assertEquals(Bytes.toStringBinary(Bytes.toBytes("foo")), dims.get("bytesField")); Assert.assertEquals("15", dims.get("metricField1")); Collection<Measurement> expectedMeasurements = ImmutableList.of( new Measurement("metricField1", MeasureType.COUNTER, 15), new Measurement("intField", MeasureType.GAUGE, 5), new Measurement("longField", MeasureType.COUNTER, 10), new Measurement("floatField", MeasureType.GAUGE, 3) ); verifyMeasurements(expectedMeasurements, transformed.getMeasurements()); Map<String, String> config = createValidConfig(); config.put(Properties.Cube.FACT_TS_FIELD, null); transform = new StructuredRecordToCubeFact(config); long tsStart = System.currentTimeMillis(); record = StructuredRecord.builder(schema) .set("metricField1", "15") .build(); transformed = transform.transform(record); long tsEnd = System.currentTimeMillis(); Assert.assertTrue(tsStart / 1000 <= transformed.getTimestamp()); Assert.assertTrue(1000 + tsEnd / 1000 >= transformed.getTimestamp()); }
public CubeFact transform(StructuredRecord record) throws Exception { Schema recordSchema = record.getSchema(); Preconditions.checkArgument(recordSchema.getType() == Schema.Type.RECORD, "input must be a record."); return factBuilder.build(record); }
StructuredRecordToCubeFact { public CubeFact transform(StructuredRecord record) throws Exception { Schema recordSchema = record.getSchema(); Preconditions.checkArgument(recordSchema.getType() == Schema.Type.RECORD, "input must be a record."); return factBuilder.build(record); } }
StructuredRecordToCubeFact { public CubeFact transform(StructuredRecord record) throws Exception { Schema recordSchema = record.getSchema(); Preconditions.checkArgument(recordSchema.getType() == Schema.Type.RECORD, "input must be a record."); return factBuilder.build(record); } StructuredRecordToCubeFact(Map<String, String> properties); }
StructuredRecordToCubeFact { public CubeFact transform(StructuredRecord record) throws Exception { Schema recordSchema = record.getSchema(); Preconditions.checkArgument(recordSchema.getType() == Schema.Type.RECORD, "input must be a record."); return factBuilder.build(record); } StructuredRecordToCubeFact(Map<String, String> properties); CubeFact transform(StructuredRecord record); }
StructuredRecordToCubeFact { public CubeFact transform(StructuredRecord record) throws Exception { Schema recordSchema = record.getSchema(); Preconditions.checkArgument(recordSchema.getType() == Schema.Type.RECORD, "input must be a record."); return factBuilder.build(record); } StructuredRecordToCubeFact(Map<String, String> properties); CubeFact transform(StructuredRecord record);  }