Data standard
This topic addresses common questions about data standards.
Development specifications for quality check UDFs for data elements, metrics, and dimension properties
General specifications:
The field value to be checked.
The meta definition of the data element, metric, or dimension property in JSON string format.
The function returns an integer. A return value of 0 indicates that the value meets the check rule, and 1 indicates that it does not.
Meta definition for data elements, metrics, and dimension properties:
{
"type": "STRING", // The type of the data element, metric, or dimension property. Valid values: INTEGER, DECIMAL, STRING, DATETIME, DATE, TIME, and BINARY.
"size": 32, // The length.
"scale": 16, // The precision.
"ruleDesc": "" // The business rule.
}For more information about UDFs, see UDFs.
For example, you can define a data element for an ID card number. If the data type of the data element is STRING and the required length is 18, you can define a UDF to check the validity of the ID card number.
UDF:
package org.alidata.odps.udf.examples;
import com.aliyun.odps.udf.UDF;
public final class IdCardChecker extends UDF {
public Integer evaluate(String idCard, String eleMetaStr) {
// TODO: check
// If the check passes, return 0. If the check fails, return 1.
return 0;
}
}The first parameter, idCard, is the value of the field to which the data element is attached.
The second parameter, eleMetaStr, is the meta definition of the data element, such as "{\"type\":\"STRING\",\"size\":18}".
The return value is 0 if the check passes and 1 if the check fails.
Then, you can create the id_card_check UDF in MaxCompute UDF management and associate it with the ID card number data element.
Based on the quality check UDF attached to the data element, the data modeling module automatically adds a UDF rule for the corresponding compute resource platform. For example, it automatically adds a custom SQL rule for MaxCompute. The default expected value is 0. The rule is executed using the following SQL statement:
select sum(id_card_check(idCard, "{\"type\":\"STRING\",\"size\":18}")) from table where partition