@Override public String toString() { return "CREATE DATABASE " + (ifNotExists ? " IF NOT EXISTS " : "") + IdentifierUtil.denormalizeIdentifier(databaseName); }
public static void buildSchema(StringBuilder sb, Schema schema) { boolean first = true; sb.append(" ("); for (Column column : schema.toArray()) { if (first) { first = false; } else { sb.append(", "); } sb.append(IdentifierUtil.denormalizeIdentifier(column.getSimpleName())).append(" "); TypeDesc typeDesc = column.getTypeDesc(); sb.append(typeDesc); } sb.append(")"); }
public static String buildDDLForIndex(IndexDesc desc) { StringBuilder sb = new StringBuilder(); sb.append("--\n") .append("-- Name: ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())).append("; Type: INDEX;") .append(" Index Method: ").append(desc.getIndexMethod()); sb.append("\n--\n"); sb.append("CREATE INDEX ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())); sb.append(" on ").append(IdentifierUtil.denormalizeIdentifier(desc.getTableName())).append(" ( "); for (SortSpec sortSpec : desc.getKeySortSpecs()) { sb.append(sortSpec.getSortKey().getQualifiedName()).append(" "); sb.append(sortSpec.isAscending() ? "asc" : "desc").append(" "); sb.append(sortSpec.isNullsFirst() ? "null first" : "null last").append(", "); } sb.replace(sb.length() - 2, sb.length() - 1, " )"); sb.append(" location '").append(desc.getIndexPath()).append("';"); return sb.toString(); }
public static String columnToDDLString(Column column) { StringBuilder sb = new StringBuilder(IdentifierUtil.denormalizeIdentifier(column.getSimpleName())); sb.append(" ").append(column.getDataType().getType()); if (column.getDataType().hasLength()) { sb.append(" (").append(column.getDataType().getLength()).append(")"); } return sb.toString(); }
public static String buildDDLForBaseTable(TableDesc desc) { StringBuilder sb = new StringBuilder(); sb.append("--\n") .append("-- Name: ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())).append("; Type: TABLE;") .append(" Storage: ").append(desc.getMeta().getDataFormat()); sb.append("\n--\n"); sb.append("CREATE TABLE ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())); buildSchema(sb, desc.getSchema()); buildUsingClause(sb, desc.getMeta()); buildWithClause(sb, desc.getMeta()); if (desc.hasPartition()) { buildPartitionClause(sb, desc); } sb.append(";"); return sb.toString(); }
public static String buildDDLForExternalTable(TableDesc desc) { StringBuilder sb = new StringBuilder(); sb.append("--\n") .append("-- Name: ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())).append("; Type: TABLE;") .append(" Storage: ").append(desc.getMeta().getDataFormat()); sb.append("\n-- Path: ").append(desc.getUri()); sb.append("\n--\n"); sb.append("CREATE EXTERNAL TABLE ").append(IdentifierUtil.denormalizeIdentifier(desc.getName())); buildSchema(sb, desc.getSchema()); buildUsingClause(sb, desc.getMeta()); buildWithClause(sb, desc.getMeta()); if (desc.hasPartition()) { buildPartitionClause(sb, desc); } buildLocationClause(sb, desc); sb.append(";"); return sb.toString(); }
sb.append("ALTER TABLE ").append(IdentifierUtil.denormalizeIdentifier(table.getName())) .append(" ADD IF NOT EXISTS PARTITION (");
writer.write("\n"); writer.write("--\n"); writer.write(String.format("-- Database name: %s%n", IdentifierUtil.denormalizeIdentifier(databaseName))); writer.write("--\n"); writer.write("\n"); writer.write(String.format("CREATE DATABASE IF NOT EXISTS %s;", IdentifierUtil.denormalizeIdentifier(databaseName))); writer.write("\n\n"); IdentifierUtil.denormalizeIdentifier(databaseName) + "." + IdentifierUtil.denormalizeIdentifier(tableName)));
private void init() { String className = getClass().getSimpleName(); currentQueryPath = new Path(queryBasePath, className); currentResultPath = new Path(resultBasePath, className); currentDatasetPath = new Path(datasetBasePath, className); NamedTest namedTest = getClass().getAnnotation(NamedTest.class); if (namedTest != null) { namedQueryPath = new Path(queryBasePath, namedTest.value()); namedDatasetPath = new Path(datasetBasePath, namedTest.value()); } try { // if the current database is "default", we don't need create it because it is already prepated at startup time. if (!currentDatabase.equals(TajoConstants.DEFAULT_DATABASE_NAME)) { client.updateQuery("CREATE DATABASE IF NOT EXISTS " + IdentifierUtil.denormalizeIdentifier(currentDatabase)); } client.selectDatabase(currentDatabase); currentResultFS = currentResultPath.getFileSystem(testBase.getTestingCluster().getConfiguration()); } catch (Exception e) { throw new RuntimeException(e); } testingCluster.setAllTajoDaemonConfValue(TajoConf.ConfVars.$TEST_BROADCAST_JOIN_ENABLED.varname, "false"); }
@AfterClass public static void tearDownClass() throws Exception { for (String tableName : createdTableGlobalSet) { client.updateQuery("DROP TABLE IF EXISTS " + IdentifierUtil.denormalizeIdentifier(tableName)); } createdTableGlobalSet.clear(); // if the current database is "default", shouldn't drop it. if (!currentDatabase.equals(TajoConstants.DEFAULT_DATABASE_NAME)) { for (String tableName : catalog.getAllTableNames(currentDatabase)) { try { client.updateQuery("DROP TABLE IF EXISTS " + tableName); } catch (InsufficientPrivilegeException i) { LOG.warn("relation '" + tableName + "' is read only."); } } client.selectDatabase(TajoConstants.DEFAULT_DATABASE_NAME); try { client.dropDatabase(currentDatabase); } catch (InsufficientPrivilegeException e) { LOG.warn("database '" + currentDatabase + "' is read only."); } } client.close(); }
private final void assertPathOfCreatedTable(final String databaseName, final String originalTableName, final String newTableName, String createTableStmt) throws Exception { // create one table executeString("CREATE DATABASE " + IdentifierUtil.denormalizeIdentifier(databaseName)).close(); getClient().existDatabase(IdentifierUtil.denormalizeIdentifier(databaseName)); final String oldFQTableName = IdentifierUtil.buildFQName(databaseName, originalTableName); ResultSet res = executeString(createTableStmt); res.close(); assertTableExists(oldFQTableName); TableDesc oldTableDesc = client.getTableDesc(oldFQTableName); // checking the existence of the table directory and validating the path Path warehouseDir = TajoConf.getWarehouseDir(testingCluster.getConfiguration()); FileSystem fs = warehouseDir.getFileSystem(testingCluster.getConfiguration()); assertTrue(fs.exists(new Path(oldTableDesc.getUri()))); assertEquals(StorageUtil.concatPath(warehouseDir, databaseName, originalTableName), new Path(oldTableDesc.getUri())); // Rename client.executeQuery("ALTER TABLE " + IdentifierUtil.denormalizeIdentifier(oldFQTableName) + " RENAME to " + IdentifierUtil.denormalizeIdentifier(newTableName)); // checking the existence of the new table directory and validating the path final String newFQTableName = IdentifierUtil.buildFQName(databaseName, newTableName); TableDesc newTableDesc = client.getTableDesc(newFQTableName); assertTrue(fs.exists(new Path(newTableDesc.getUri()))); assertEquals(StorageUtil.concatPath(warehouseDir, databaseName, newTableName), new Path(newTableDesc.getUri())); }
res = executeString("select * from " + IdentifierUtil.denormalizeIdentifier(getCurrentDatabase()) + ".table1");