Updated on 2026-06-27 GMT+08:00

Flink Decimal Calculation Precision Enhancement

Scenarios

This feature is used when the Decimal calculation result needs to be more accurate and more precise.

Notes and Constraints

To use this feature, you need to add the -Ddecimal.nonstandard=true parameter to the Flink process.

This section applies only to MRS 3.6.0-LTS and later.

How to Use

When configuring a Flink job, you can add the custom parameter env.java.default-opts.all on the FlinkServer web UI and set it to -Ddecimal.nonstandard=true. For details, see Creating a FlinkServer Job.

Example:
public class DataStreamJob {
 public static void main(String[] args) throws Exception {
  // create environments of both APIs
  StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

  // create a DataStream
  DataStream<BigDecimal> dataStream = env.fromElements(new BigDecimal("1.1234"));

  // interpret the insert-only DataStream as a Table
  Table inputTable = tableEnv.fromDataStream(dataStream,Schema.newBuilder().column("f0", DataTypes.DECIMAL(18,10)).build());

  //Table inputTable = tableEnv.fromDataStream(dataStream);

  System.out.println(inputTable.getResolvedSchema());

  // register the Table object as a view and query it
  tableEnv.createTemporaryView("InputTable", inputTable);
		Table resultTable = tableEnv.sqlQuery("SELECT f0*f0 FROM InputTable");

		// interpret the insert-only Table as a DataStream again
		DataStream<Row> resultStream = tableEnv.toDataStream(resultTable);

		// add a printing sink and execute in DataStream API
		resultStream.print();
		env.execute();
	}
}
Execution result:
  • Calculation result when this feature is enabled:
    1.2620275600000
  • Calculation result when this feature is disabled:
    1.262028