public static byte[] fromLogical(Schema schema, BigDecimal value) {
        int schemaScale = scale(schema);
        if (value.scale() != schemaScale)
            throw new DataException(String.format(
                "Decimal value has mismatching scale for given Decimal schema. "
                    + "Schema has scale %d, value has scale %d.",
                schemaScale,
                value.scale()
            ));
        return value.unscaledValue().toByteArray();
    }
@Test
    public void testFromLogical() {
        Schema schema = Decimal.schema(TEST_SCALE);
        byte[] encoded = Decimal.fromLogical(schema, TEST_DECIMAL);
        assertArrayEquals(TEST_BYTES, encoded);

        encoded = Decimal.fromLogical(schema, TEST_DECIMAL_NEGATIVE);
        assertArrayEquals(TEST_BYTES_NEGATIVE, encoded);
    }