Java Code Examples for org.apache.flink.api.common.typeinfo.Types#BOOLEAN

The following examples show how to use org.apache.flink.api.common.typeinfo.Types#BOOLEAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImputerTest.java    From Alink with Apache License 2.0 6 votes vote down vote up
AlgoOperator getData(boolean isBatch) {


        Row[] testArray =
            new Row[]{
                Row.of("0", "a", 1L, 1, 2.0, true),
                Row.of("1", null, 2L, 2, -3.0, true),
                Row.of("2", "c", null, null, 2.0, false),
                Row.of("3", "a", 0L, 0, null, null),
            };

        String[] colNames = new String[]{"id", "f_string", "f_long", "f_int", "f_double", "f_boolean"};
        TableSchema schema = new TableSchema(
            colNames,
            new TypeInformation<?>[] {Types.STRING, Types.STRING, Types.LONG, Types.INT, Types.DOUBLE, Types.BOOLEAN}
        );
        if (isBatch) {
            return new MemSourceBatchOp(Arrays.asList(testArray), schema);
        } else {
            return new MemSourceStreamOp(Arrays.asList(testArray), schema);
        }

    }
 
Example 2
Source File: StandardScalerMapperTest.java    From Alink with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    Row[] rows = new Row[]{
        Row.of(0L, "{\"withMean\":\"true\",\"withStd\":\"true\"}", null, null, null),
        Row.of(1048576L, "[1.0,1.0,0.2]", null, null, null),
        Row.of(2097152L, "[1.0,1.0,1.0]", null, null, null)
    };

    List<Row> model = Arrays.asList(rows);

    TableSchema dataSchema = new TableSchema(
        new String[]{"f_string", "f_long", "f_int", "f_double", "f_boolean"},
        new TypeInformation<?>[]{Types.STRING, Types.LONG, Types.INT, Types.DOUBLE, Types.BOOLEAN}
    );
    Params params = new Params();

    StandardScalerModelMapper mapper = new StandardScalerModelMapper(modelSchema, dataSchema, params);
    mapper.loadModel(model);

    assertEquals((double) mapper.map(Row.of("a", 1L, 1, 2.0, true)).getField(1), 0.0, 10e-4);
    assertEquals((double) mapper.map(Row.of("a", 1L, 1, 2.0, true)).getField(2), 0.8, 10e-4);
    assertEquals((double) mapper.map(Row.of("a", 1L, 1, 2.0, true)).getField(3), 1.0, 10e-4);

}
 
Example 3
Source File: TableUtilTest.java    From Alink with Apache License 2.0 6 votes vote down vote up
@Test
public void getCategoricalColsTest() {
    TableSchema tableSchema = new TableSchema(new String[]{"f0", "f1", "f2", "f3"},
        new TypeInformation[]{Types.INT, Types.LONG, Types.STRING, Types.BOOLEAN});

    Assert.assertArrayEquals(TableUtil.getCategoricalCols(tableSchema, tableSchema.getFieldNames(), null),
        new String[]{"f2", "f3"});
    Assert.assertArrayEquals(
        TableUtil.getCategoricalCols(tableSchema, new String[]{"f2", "f1", "f0", "f3"}, new String[]{"f0"}),
        new String[]{"f2", "f0", "f3"});

    thrown.expect(IllegalArgumentException.class);
    Assert.assertArrayEquals(
        TableUtil.getCategoricalCols(tableSchema, new String[]{"f3", "f0"}, new String[]{"f2"}),
        new String[]{"f3", "f2"});
}
 
Example 4
Source File: CsvFormatterTest.java    From Alink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormatter() throws Exception {
    TypeInformation[] types = new TypeInformation[]{Types.STRING, Types.DOUBLE, Types.LONG,
        Types.BOOLEAN, Types.SQL_TIMESTAMP};

    Row row = Row.of("string", 1.0, 1L, true, new java.sql.Timestamp(System.currentTimeMillis()));
    CsvFormatter formatter = new CsvFormatter(types, ",", '"');
    CsvParser parser = new CsvParser(types, ",", '"');
    String text = formatter.format(row);
    Row parsed = parser.parse(text).f1;

    Assert.assertEquals(parsed.getArity(), row.getArity());
    for (int i = 0; i < parsed.getArity(); i++) {
        Assert.assertEquals(parsed.getField(i), row.getField(i));
    }
}
 
Example 5
Source File: StandardScalerTest.java    From Alink with Apache License 2.0 6 votes vote down vote up
public static AlgoOperator getMultiTypeData(boolean isBatch) {
    Row[] testArray =
        new Row[]{
            Row.of(new Object[]{"0", "a", 1L, 1, 0.2, true}),
            Row.of(new Object[]{"1", null, 2L, 2, null, true}),
            Row.of(new Object[]{"2", "c", null, null, null, false}),
            Row.of(new Object[]{"3", "a", 0L, 0, null, null}),
        };

    String[] colNames = new String[]{"id", "f_string", "f_long", "f_int", "f_double", "f_boolean"};
    TypeInformation[] colTypes = new TypeInformation[]{Types.STRING, Types.STRING, Types.LONG, Types.INT, Types.DOUBLE,
        Types.BOOLEAN};
    TableSchema schema = new TableSchema(
        colNames,
        colTypes
    );

    if (isBatch) {
        return new MemSourceBatchOp(Arrays.asList(testArray), schema);
    } else {
        return new MemSourceStreamOp(Arrays.asList(testArray), schema);
    }
}
 
Example 6
Source File: DeduplicateKeepFirstRowFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration configure) throws Exception {
	super.open(configure);
	initCleanupTimeState("DeduplicateFunctionKeepFirstRow");
	ValueStateDescriptor<Boolean> stateDesc = new ValueStateDescriptor<>("existsState", Types.BOOLEAN);
	state = getRuntimeContext().getState(stateDesc);
}
 
Example 7
Source File: TaxiRideTableSource.java    From flink-training-exercises with Apache License 2.0 5 votes vote down vote up
@Override
public TableSchema getTableSchema() {
	TypeInformation<?>[] types = new TypeInformation[] {
			Types.LONG,
			Types.LONG,
			Types.LONG,
			Types.BOOLEAN,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.FLOAT,
			Types.SHORT,
			Types.SQL_TIMESTAMP
	};

	String[] names = new String[]{
			"rideId",
			"taxiId",
			"driverId",
			"isStart",
			"startLon",
			"startLat",
			"endLon",
			"endLat",
			"passengerCnt",
			"eventTime"
	};

	return new TableSchema(names, types);
}
 
Example 8
Source File: DeduplicateKeepFirstRowFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration configure) throws Exception {
	super.open(configure);
	ValueStateDescriptor<Boolean> stateDesc = new ValueStateDescriptor<>("existsState", Types.BOOLEAN);
	StateTtlConfig ttlConfig = createTtlConfig(minRetentionTime);
	if (ttlConfig.isEnabled()) {
		stateDesc.enableTimeToLive(ttlConfig);
	}
	state = getRuntimeContext().getState(stateDesc);
}
 
Example 9
Source File: TableUtilTest.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Test
public void getNumericColsTest() {
    TableSchema tableSchema = new TableSchema(new String[]{"f0", "f1", "F2", "f3"},
        new TypeInformation[]{Types.INT, Types.LONG, Types.STRING, Types.BOOLEAN});

    Assert.assertArrayEquals(TableUtil.getNumericCols(tableSchema), new String[]{"f0", "f1"});
    Assert.assertArrayEquals(TableUtil.getNumericCols(tableSchema, new String[]{"f0"}), new String[]{"f1"});
    Assert.assertArrayEquals(TableUtil.getNumericCols(tableSchema, new String[]{"f2"}), new String[]{"f0", "f1"});
}
 
Example 10
Source File: EventTimeTriggers.java    From flink with Apache License 2.0 4 votes vote down vote up
AfterEndOfWindowEarlyAndLate(Trigger<W> earlyTrigger, Trigger<W> lateTrigger) {
	this.earlyTrigger = earlyTrigger;
	this.lateTrigger = lateTrigger;
	this.hasFiredOnTimeStateDesc = new ValueStateDescriptor<>("eventTime-afterEOW", Types.BOOLEAN);
}
 
Example 11
Source File: MiniBatchDeduplicateKeepFirstRowFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(ExecutionContext ctx) throws Exception {
	super.open(ctx);
	ValueStateDescriptor<Boolean> stateDesc = new ValueStateDescriptor<>("existsState", Types.BOOLEAN);
	state = ctx.getRuntimeContext().getState(stateDesc);
}
 
Example 12
Source File: CollectStreamTableSink.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TupleTypeInfo<Tuple2<Boolean, Row>> getOutputType() {
	return new TupleTypeInfo<>(Types.BOOLEAN, getRecordType());
}
 
Example 13
Source File: JDBCUpsertTableSink.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Tuple2<Boolean, Row>> getOutputType() {
	return new TupleTypeInfo<>(Types.BOOLEAN, getRecordType());
}
 
Example 14
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Boolean> getResultType() {
	return Types.BOOLEAN;
}
 
Example 15
Source File: RetractStreamTableSink.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
default TypeInformation<Tuple2<Boolean, T>> getOutputType() {
	return new TupleTypeInfo<>(Types.BOOLEAN, getRecordType());
}
 
Example 16
Source File: FirstValueWithRetractAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Boolean> getResultType() {
	return Types.BOOLEAN;
}
 
Example 17
Source File: JsonRowDeserializationSchema.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private Object convert(JsonNode node, TypeInformation<?> info) {
	if (info == Types.VOID || node.isNull()) {
		return null;
	} else if (info == Types.BOOLEAN) {
		return node.asBoolean();
	} else if (info == Types.STRING) {
		return node.asText();
	} else if (info == Types.BIG_DEC) {
		return node.decimalValue();
	} else if (info == Types.BIG_INT) {
		return node.bigIntegerValue();
	} else if (info == Types.SQL_DATE) {
		return Date.valueOf(node.asText());
	} else if (info == Types.SQL_TIME) {
		// according to RFC 3339 every full-time must have a timezone;
		// until we have full timezone support, we only support UTC;
		// users can parse their time as string as a workaround
		final String time = node.asText();
		if (time.indexOf('Z') < 0 || time.indexOf('.') >= 0) {
			throw new IllegalStateException(
				"Invalid time format. Only a time in UTC timezone without milliseconds is supported yet. " +
					"Format: HH:mm:ss'Z'");
		}
		return Time.valueOf(time.substring(0, time.length() - 1));
	} else if (info == Types.SQL_TIMESTAMP) {
		// according to RFC 3339 every date-time must have a timezone;
		// until we have full timezone support, we only support UTC;
		// users can parse their time as string as a workaround
		final String timestamp = node.asText();
		if (timestamp.indexOf('Z') < 0) {
			throw new IllegalStateException(
				"Invalid timestamp format. Only a timestamp in UTC timezone is supported yet. " +
					"Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		}
		return Timestamp.valueOf(timestamp.substring(0, timestamp.length() - 1).replace('T', ' '));
	} else if (info instanceof RowTypeInfo) {
		return convertRow(node, (RowTypeInfo) info);
	} else if (info instanceof ObjectArrayTypeInfo) {
		return convertObjectArray(node, ((ObjectArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof BasicArrayTypeInfo) {
		return convertObjectArray(node, ((BasicArrayTypeInfo) info).getComponentInfo());
	} else if (info instanceof PrimitiveArrayTypeInfo &&
			((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) {
		return convertByteArray(node);
	} else {
		// for types that were specified without JSON schema
		// e.g. POJOs
		try {
			return objectMapper.treeToValue(node, info.getTypeClass());
		} catch (JsonProcessingException e) {
			throw new IllegalStateException("Unsupported type information '" + info + "' for node: " + node);
		}
	}
}
 
Example 18
Source File: CollectStreamTableSink.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public TupleTypeInfo<Tuple2<Boolean, Row>> getOutputType() {
  return new TupleTypeInfo<>(Types.BOOLEAN, getRecordType());
}
 
Example 19
Source File: FirstValueAggFunction.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public TypeInformation<Boolean> getResultType() {
	return Types.BOOLEAN;
}
 
Example 20
Source File: CollectStreamTableSink.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public TupleTypeInfo<Tuple2<Boolean, Row>> getOutputType() {
	return new TupleTypeInfo<>(Types.BOOLEAN, getRecordType());
}