ConfigurationDataTypes { public static String getConfigurationDataType(DataType type) { Set<String> supportedTypes = Sets.newHashSet( STRING, FLOAT, DOUBLE, BYTE, SHORT, INT, LONG, BOOLEAN, BINARY, DATE, TIMESTAMP); if (supportedTypes.contains(type.typeName()) || (type instanceof DecimalType)) { return type.typeName(); } else if (type.typeName().equals("integer")) { return INT; } else { throw new RuntimeException("Unsupported field type: " + type); } }  static String getConfigurationDataType(DataType type); static DataType getSparkDataType(String typeString); static final String DECIMAL; static final String STRING; static final String FLOAT; static final String DOUBLE; static final String BYTE; static final String SHORT; static final String INT; static final String LONG; static final String BOOLEAN; static final String BINARY; static final String DATE; static final String TIMESTAMP; }
@Test public void testGetConfigurationDataTypeValid() { assertEquals(ConfigurationDataTypes.getConfigurationDataType(new DecimalType()), "decimal(10,0)"); assertEquals(ConfigurationDataTypes.getConfigurationDataType(new DecimalType(38,38)), "decimal(38,38)"); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.StringType), ConfigurationDataTypes.STRING); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.FloatType), ConfigurationDataTypes.FLOAT); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.DoubleType), ConfigurationDataTypes.DOUBLE); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.ByteType), ConfigurationDataTypes.BYTE); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.ShortType), ConfigurationDataTypes.SHORT); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.IntegerType), ConfigurationDataTypes.INT); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.LongType), ConfigurationDataTypes.LONG); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.BooleanType), ConfigurationDataTypes.BOOLEAN); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.BinaryType), ConfigurationDataTypes.BINARY); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.DateType), ConfigurationDataTypes.DATE); assertEquals(ConfigurationDataTypes.getConfigurationDataType(DataTypes.TimestampType), ConfigurationDataTypes.TIMESTAMP); }
@Test (expected = RuntimeException.class) public void testGetConfigurationDataTypeInvalid() { ConfigurationDataTypes.getConfigurationDataType(new ArrayType()); }