@Test public void testBasics() { String dataType = "varchar"; String precision = "60"; String scale = null; dataType = BeelineHiveClient.considerDataTypePrecision(dataType, precision, scale); Assert.assertEquals("varchar(60)", dataType); dataType = "char"; precision = "50"; scale = null; dataType = BeelineHiveClient.considerDataTypePrecision(dataType, precision, scale); Assert.assertEquals("char(50)", dataType); dataType = "decimal"; precision = "8"; scale = "4"; dataType = BeelineHiveClient.considerDataTypePrecision(dataType, precision, scale); Assert.assertEquals("decimal(8,4)", dataType); dataType = "numeric"; precision = "7"; scale = "3"; dataType = BeelineHiveClient.considerDataTypePrecision(dataType, precision, scale); Assert.assertEquals("numeric(7,3)", dataType); }
public static String considerDataTypePrecision(String dataType, String precision, String scale) { if ("VARCHAR".equalsIgnoreCase(dataType) || "CHAR".equalsIgnoreCase(dataType)) { if (null != precision) dataType = new StringBuilder(dataType).append("(").append(precision).append(")").toString(); } if ("DECIMAL".equalsIgnoreCase(dataType) || "NUMERIC".equalsIgnoreCase(dataType)) { if (precision != null && scale != null) dataType = new StringBuilder(dataType).append("(").append(precision).append(",").append(scale) .append(")").toString(); } return dataType; }
BeelineHiveClient implements IHiveClient { public static String considerDataTypePrecision(String dataType, String precision, String scale) { if ("VARCHAR".equalsIgnoreCase(dataType) || "CHAR".equalsIgnoreCase(dataType)) { if (null != precision) dataType = new StringBuilder(dataType).append("(").append(precision).append(")").toString(); } if ("DECIMAL".equalsIgnoreCase(dataType) || "NUMERIC".equalsIgnoreCase(dataType)) { if (precision != null && scale != null) dataType = new StringBuilder(dataType).append("(").append(precision).append(",").append(scale) .append(")").toString(); } return dataType; } }
BeelineHiveClient implements IHiveClient { public static String considerDataTypePrecision(String dataType, String precision, String scale) { if ("VARCHAR".equalsIgnoreCase(dataType) || "CHAR".equalsIgnoreCase(dataType)) { if (null != precision) dataType = new StringBuilder(dataType).append("(").append(precision).append(")").toString(); } if ("DECIMAL".equalsIgnoreCase(dataType) || "NUMERIC".equalsIgnoreCase(dataType)) { if (precision != null && scale != null) dataType = new StringBuilder(dataType).append("(").append(precision).append(",").append(scale) .append(")").toString(); } return dataType; } BeelineHiveClient(String beelineParams); }
BeelineHiveClient implements IHiveClient { public static String considerDataTypePrecision(String dataType, String precision, String scale) { if ("VARCHAR".equalsIgnoreCase(dataType) || "CHAR".equalsIgnoreCase(dataType)) { if (null != precision) dataType = new StringBuilder(dataType).append("(").append(precision).append(")").toString(); } if ("DECIMAL".equalsIgnoreCase(dataType) || "NUMERIC".equalsIgnoreCase(dataType)) { if (precision != null && scale != null) dataType = new StringBuilder(dataType).append("(").append(precision).append(",").append(scale) .append(")").toString(); } return dataType; } BeelineHiveClient(String beelineParams); List<String> getHiveDbNames(); List<String> getHiveTableNames(String database); @Override long getHiveTableRows(String database, String tableName); @Override List<Object[]> getHiveResult(String hql); @Override void executeHQL(String hql); @Override void executeHQL(String[] hqls); HiveTableMeta getHiveTableMeta(String database, String tableName); static String considerDataTypePrecision(String dataType, String precision, String scale); void close(); static void main(String[] args); }
BeelineHiveClient implements IHiveClient { public static String considerDataTypePrecision(String dataType, String precision, String scale) { if ("VARCHAR".equalsIgnoreCase(dataType) || "CHAR".equalsIgnoreCase(dataType)) { if (null != precision) dataType = new StringBuilder(dataType).append("(").append(precision).append(")").toString(); } if ("DECIMAL".equalsIgnoreCase(dataType) || "NUMERIC".equalsIgnoreCase(dataType)) { if (precision != null && scale != null) dataType = new StringBuilder(dataType).append("(").append(precision).append(",").append(scale) .append(")").toString(); } return dataType; } BeelineHiveClient(String beelineParams); List<String> getHiveDbNames(); List<String> getHiveTableNames(String database); @Override long getHiveTableRows(String database, String tableName); @Override List<Object[]> getHiveResult(String hql); @Override void executeHQL(String hql); @Override void executeHQL(String[] hqls); HiveTableMeta getHiveTableMeta(String database, String tableName); static String considerDataTypePrecision(String dataType, String precision, String scale); void close(); static void main(String[] args);  }