@Override
  public ColumnMetadataImpl buildMetadata(VirtualColumnContext context) {
    ColumnMetadataImpl.Builder builder = getColumnMetadataBuilder(context).setCardinality(1).setHasDictionary(true);
    if (context.getFieldSpec().isSingleValueField()) {
      builder.setSorted(true);
    } else {
      // When there is no value for a multi-value column, the maxNumberOfMultiValues and cardinality should be
      // set as 1 because the MV column bitmap uses 1 to delimit the rows for a MV column. Each MV column will have a
      // default null value based on column's data type
      builder.setMaxNumberOfMultiValues(1);
    }

    FieldSpec fieldSpec = context.getFieldSpec();
    Object defaultNullValue = fieldSpec.getDefaultNullValue();
    switch (fieldSpec.getDataType().getStoredType()) {
      case INT:
        builder.setMinValue((int) defaultNullValue).setMaxValue((int) defaultNullValue);
        break;
      case LONG:
        builder.setMinValue((long) defaultNullValue).setMaxValue((long) defaultNullValue);
        break;
      case FLOAT:
        builder.setMinValue((float) defaultNullValue).setMaxValue((float) defaultNullValue);
        break;
      case DOUBLE:
        builder.setMinValue((double) defaultNullValue).setMaxValue((double) defaultNullValue);
        break;
      case BIG_DECIMAL:
        builder.setMinValue((BigDecimal) defaultNullValue).setMaxValue((BigDecimal) defaultNullValue);
        break;
      case STRING:
        builder.setMinValue((String) defaultNullValue).setMaxValue((String) defaultNullValue);
        break;
      case BYTES:
        builder.setMinValue(new ByteArray((byte[]) defaultNullValue))
            .setMaxValue(new ByteArray((byte[]) defaultNullValue));
        break;
      default:
        throw new IllegalStateException();
    }

    return builder.build();
  }
@Test
  public void testBuildMetadata() {
    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_INT, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_INT).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue((int) SV_INT.getDefaultNullValue())
            .setMaxValue((int) SV_INT.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_LONG, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_LONG).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue((long) SV_LONG.getDefaultNullValue())
            .setMaxValue((long) SV_LONG.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_FLOAT, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_FLOAT).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue((float) SV_FLOAT.getDefaultNullValue())
            .setMaxValue((float) SV_FLOAT.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_DOUBLE, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_DOUBLE).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue((double) SV_DOUBLE.getDefaultNullValue())
            .setMaxValue((double) SV_DOUBLE.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_STRING, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_STRING).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue((String) SV_STRING.getDefaultNullValue())
            .setMaxValue((String) SV_STRING.getDefaultNullValue()).build());

    assertEquals(
        new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_STRING_WITH_DEFAULT, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_STRING_WITH_DEFAULT).setTotalDocs(1).setCardinality(1)
            .setSorted(true).setHasDictionary(true).setMinValue("default").setMaxValue("default").build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(SV_BYTES, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(SV_BYTES).setTotalDocs(1).setCardinality(1).setSorted(true)
            .setHasDictionary(true).setMinValue(new ByteArray((byte[]) SV_BYTES.getDefaultNullValue()))
            .setMaxValue(new ByteArray((byte[]) SV_BYTES.getDefaultNullValue())).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(MV_INT, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(MV_INT).setTotalDocs(1).setCardinality(1).setSorted(false)
            .setHasDictionary(true).setMaxNumberOfMultiValues(1).setMinValue((int) MV_INT.getDefaultNullValue())
            .setMaxValue((int) MV_INT.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(MV_LONG, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(MV_LONG).setTotalDocs(1).setCardinality(1).setSorted(false)
            .setHasDictionary(true).setMaxNumberOfMultiValues(1).setMinValue((long) MV_LONG.getDefaultNullValue())
            .setMaxValue((long) MV_LONG.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(MV_FLOAT, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(MV_FLOAT).setTotalDocs(1).setCardinality(1).setSorted(false)
            .setHasDictionary(true).setMaxNumberOfMultiValues(1).setMinValue((float) MV_FLOAT.getDefaultNullValue())
        .setMaxValue((float) MV_FLOAT.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(MV_DOUBLE, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(MV_DOUBLE).setTotalDocs(1).setCardinality(1).setSorted(false)
            .setHasDictionary(true).setMaxNumberOfMultiValues(1).setMinValue((double) MV_DOUBLE.getDefaultNullValue())
            .setMaxValue((double) MV_DOUBLE.getDefaultNullValue()).build());

    assertEquals(new DefaultNullValueVirtualColumnProvider().buildMetadata(new VirtualColumnContext(MV_STRING, 1)),
        new ColumnMetadataImpl.Builder().setFieldSpec(MV_STRING).setTotalDocs(1).setCardinality(1).setSorted(false)
            .setHasDictionary(true).setMaxNumberOfMultiValues(1).setMinValue((String) MV_STRING.getDefaultNullValue())
            .setMaxValue((String) MV_STRING.getDefaultNullValue()).build());
  }