private static void buildWithClause(final StringBuilder sb, TableMeta meta) { KeyValueSet options = meta.getOptions(); if (options != null && options.size() > 0) { sb.append(" WITH ("); // sort table properties in an lexicographic order of the property keys. Map.Entry<String, String>[] entries = meta.getOptions().getAllKeyValus().entrySet().toArray( new Map.Entry[meta.getOptions().size()]); Arrays.sort(entries, new Comparator<Map.Entry<String, String>>() { @Override public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) { return o1.getKey().compareTo(o2.getKey()); } }); // Join all properties by comma (',') sb.append(StringUtils.join(entries, ", ", new Function<Map.Entry<String, String>, String>() { @Override public String apply(Map.Entry<String, String> e) { return "'" + e.getKey() + "'='" + e.getValue() + "'"; } })); sb.append(")"); } }
private static void buildWithClause(final StringBuilder sb, TableMeta meta) { KeyValueSet options = meta.getPropertySet(); if (options != null && options.size() > 0) { sb.append(" WITH ("); // sort table properties in an lexicographic order of the property keys. Entry<String, String> [] entries = meta.getPropertySet().getAllKeyValus().entrySet().toArray( new Entry[meta.getPropertySet().size()]); Arrays.sort(entries, new Comparator<Entry<String, String>>() { @Override public int compare(Entry<String, String> o1, Entry<String, String> o2) { return o1.getKey().compareTo(o2.getKey()); } }); // Join all properties by comma (',') sb.append(StringUtils.join(entries, ", ", new Function<Entry<String, String>, String>() { @Override public String apply(Entry<String, String> e) { return "'" + e.getKey() + "'='" + e.getValue() + "'"; } })); sb.append(")"); } }
@Test public final void testAlterTableUnsetProperty() throws Exception { executeDDL("table2_ddl.sql", "table2.tbl", "ALTY"); String tableName = IdentifierUtil.buildFQName(getCurrentDatabase(), "alty"); assertTrue(catalog.existsTable(tableName)); TableDesc tableDesc = catalog.getTableDesc(tableName); TableMeta tableMeta = tableDesc.getMeta(); assertEquals(tableMeta.getPropertySet().size(), 3); assertNotNull(tableMeta.getProperty("timezone")); assertNotNull(tableMeta.getProperty("text.null")); assertEquals(tableMeta.getProperty("text.delimiter"), "\\u002b"); executeDDL("alter_table_unset_property_delimiter.sql", null); tableDesc = catalog.getTableDesc(tableName); tableMeta = tableDesc.getMeta(); assertEquals(tableMeta.getPropertySet().size(), 2); assertNotNull(tableMeta.getProperty("timezone")); assertNotNull(tableMeta.getProperty("text.null")); assertFalse(tableMeta.getPropertySet().containsKey("text.delimiter")); executeDDL("alter_table_unset_not_exists_property.sql", null); tableDesc = catalog.getTableDesc(tableName); tableMeta = tableDesc.getMeta(); assertEquals(tableMeta.getPropertySet().size(), 2); assertNotNull(tableMeta.getProperty("timezone")); assertNotNull(tableMeta.getProperty("text.null")); assertFalse(tableMeta.getPropertySet().containsKey("text.delimiter")); }