boolean exists = catalog.existsTable(qualifiedName); if (!exists) { if (ifExists) { // DROP TABLE IF EXISTS TableDesc tableDesc = catalog.getTableDesc(qualifiedName); catalog.dropTable(qualifiedName);
@Override public DataType visitCountRowsFunction(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, CountRowsFunctionExpr expr) throws TajoException { FunctionDesc countRows = catalog.getFunction("count", CatalogProtos.FunctionType.AGGREGATION, new DataType[] {}); return countRows.getReturnType(); }
partitions = catalog.getPartitionsOfTable(splits[0], splits[1]); if (partitions.isEmpty()) { filteredPaths = findFilteredPathsFromFileSystem(partitionColumns, conjunctiveForms, fs, tablePath); if (catalog.existPartitions(splits[0], splits[1])) { PartitionsByAlgebraProto request = getPartitionsAlgebraProto(splits[0], splits[1], conjunctiveForms); partitions = catalog.getPartitionsByAlgebra(request); filteredPaths = findFilteredPathsByPartitionDesc(partitions); } else { partitions = catalog.getPartitionsOfTable(splits[0], splits[1]); if (partitions.isEmpty()) { filteredPaths = findFilteredPathsFromFileSystem(partitionColumns, conjunctiveForms, fs, tablePath);
public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) throws UndefinedDatabaseException, InsufficientPrivilegeException, CannotDropCurrentDatabaseException { boolean exists = catalog.existDatabase(databaseName); if (!exists) { if (ifExists) { // DROP DATABASE IF EXISTS LOG.info("database \"" + databaseName + "\" does not exists."); return; } else { // Otherwise, it causes an exception. throw new UndefinedDatabaseException(databaseName); } } if (queryContext.getCurrentDatabase().equals(databaseName)) { throw new CannotDropCurrentDatabaseException(); } catalog.dropDatabase(databaseName); }
@Override public Response run(JerseyResourceDelegateContext context) { JerseyResourceDelegateContextKey<MasterContext> masterContextKey = JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class); MasterContext masterContext = context.get(masterContextKey); JerseyResourceDelegateContextKey<String> databaseNameKey = JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class); String databaseName = context.get(databaseNameKey); CatalogService catalogService = masterContext.getCatalog(); if (!catalogService.existDatabase(databaseName)) { return Response.status(Status.NOT_FOUND).build(); } Collection<String> tableNames = catalogService.getAllTableNames(databaseName); Map<String, Collection<String>> tableNamesMap = new HashMap<String, Collection<String>>(); tableNamesMap.put(tablesKeyName, tableNames); return Response.ok(tableNamesMap).build(); }
public void dropIndex(final QueryContext queryContext, final DropIndexNode dropIndexNode) throws UndefinedIndexException, UndefinedDatabaseException { String databaseName, simpleIndexName; if (IdentifierUtil.isFQTableName(dropIndexNode.getIndexName())) { String[] splits = IdentifierUtil.splitFQTableName(dropIndexNode.getIndexName()); databaseName = splits[0]; simpleIndexName = splits[1]; } else { databaseName = queryContext.getCurrentDatabase(); simpleIndexName = dropIndexNode.getIndexName(); } if (!catalog.existIndexByName(databaseName, simpleIndexName)) { throw new UndefinedIndexException(simpleIndexName); } IndexDesc desc = catalog.getIndexByName(databaseName, simpleIndexName); catalog.dropIndex(databaseName, simpleIndexName); Path indexPath = new Path(desc.getIndexPath()); try { FileSystem fs = indexPath.getFileSystem(context.getConf()); fs.delete(indexPath, true); } catch (IOException e) { throw new InternalError(e.getMessage()); } LOG.info("Index " + simpleIndexName + " is dropped."); }
private void createColumnPartitionedTable() throws Exception { String tableName = IdentifierUtil.normalizeIdentifier("ColumnPartitionedTable"); ResultSet res = executeString( "create table " + tableName + " (col1 int4, col2 int4) partition by column(key float8) "); res.close(); assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, tableName)); assertEquals(2, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getSchema().size()); assertEquals(3, catalog.getTableDesc(DEFAULT_DATABASE_NAME, tableName).getLogicalSchema().size()); res = testBase.execute( "insert overwrite into " + tableName + " select l_orderkey, l_partkey, l_quantity from lineitem"); res.close(); }
@BeforeClass public static void setUp() throws Exception { util = new TajoTestingCluster(); util.startCatalogCluster(); catalog = util.getCatalogService(); catalog.createTablespace(DEFAULT_TABLESPACE_NAME, "hdfs://localhost:1234"); catalog.createDatabase(DEFAULT_DATABASE_NAME, DEFAULT_TABLESPACE_NAME); for (FunctionDesc funcDesc : FunctionLoader.findLegacyFunctions()) { catalog.createFunction(funcDesc); } // TPC-H Schema for Complex Queries String [] tpchTables = { "part", "supplier", "partsupp", "nation", "region", "lineitem" }; tpch = new TPCH(); tpch.loadSchemas(); tpch.loadOutSchema(); for (String table : tpchTables) { TableMeta m = CatalogUtil.newTableMeta(BuiltinStorages.TEXT, util.getConfiguration()); TableDesc d = CatalogUtil.newTableDesc( IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, table), tpch.getSchema(table), m, CommonTestingUtil.getTestDir()); catalog.createTable(d); } sqlAnalyzer = new SQLAnalyzer(); planner = new LogicalPlanner(catalog, TablespaceManager.getInstance()); }
catalog = util.getCatalogService(); testDir = CommonTestingUtil.getTestDir(TEST_PATH); catalog.createTablespace(DEFAULT_TABLESPACE_NAME, testDir.toUri().toString()); catalog.createDatabase(DEFAULT_DATABASE_NAME, DEFAULT_TABLESPACE_NAME); conf.setVar(TajoConf.ConfVars.WORKER_TEMPORAL_DIR, testDir.toString()); IdentifierUtil.buildFQName(TajoConstants.DEFAULT_DATABASE_NAME, "employee"), schema, employeeMeta, employeePath.toUri()); catalog.createTable(employee); analyzer = new SQLAnalyzer(); planner = new LogicalPlanner(catalog, TablespaceManager.getInstance());
CatalogUtil.newTableMeta(BuiltinStorages.TEXT, util.getConfiguration()), CommonTestingUtil.getTestDir().toUri(), true); catalog.createTable(tableDesc); assertTrue(catalog.existsTable("default.self_desc_table1")); tableDesc = catalog.getTableDesc("default.self_desc_table1"); assertTrue(tableDesc.hasEmptySchema()); assertEquals("default.self_desc_table1.name", targets.get(2).getCanonicalName()); catalog.dropTable("default.self_desc_table1");
if (!catalog.existsTable(databaseName, simpleTableName)) { throw new UndefinedTableException(alterTable.getTableName()); TableDesc tableDesc = catalog.getTableDesc(databaseName, simpleTableName); List<PartitionDescProto> existingPartitions = catalog.getPartitionsOfTable(databaseName, simpleTableName); List<String> existingPartitionNames = new ArrayList<>(); Path existingPartitionPath = null; catalog.addPartitions(databaseName, simpleTableName, targetPartitions, true);
assertTrue(catalog.existsTable(tableName)); TableDesc retrieved = catalog.getTableDesc(tableName); assertEquals(retrieved.getName(), tableName); assertEquals(retrieved.getPartitionMethod().getPartitionType(), CatalogProtos.PartitionType.COLUMN); executeDDL("alter_table_add_partition2.sql", null); List<CatalogProtos.PartitionDescProto> partitions = catalog.getPartitionsOfTable("TestAlterTable", "partitioned_table"); assertNotNull(partitions); assertEquals(partitions.size(), 1); executeDDL("alter_table_drop_partition2.sql", null); partitions = catalog.getPartitionsOfTable("TestAlterTable", "partitioned_table"); assertNotNull(partitions); assertEquals(partitions.size(), 0); assertFalse(fs.exists(partitionPath)); catalog.dropTable(tableName);
private void checkBaseTBSpaceAndDatabase() throws IOException, DuplicateDatabaseException, DuplicateTablespaceException { if (catalog.existTablespace(DEFAULT_TABLESPACE_NAME)) { // if default tablespace already exists tablespace = catalog.getTablespace(DEFAULT_TABLESPACE_NAME); } catch (UndefinedTablespaceException e) { throw new TajoInternalError(e); catalog.alterTablespace(alterTablespace); } catch (TajoException e) { throw new TajoInternalError(e); } else if (!catalog.existTablespace(DEFAULT_TABLESPACE_NAME)) { // if the default tablespace does not exists catalog.createTablespace(DEFAULT_TABLESPACE_NAME, context.getConf().getVar(ConfVars.WAREHOUSE_DIR)); } else { LOG.info(String.format("Default tablespace (%s) is already prepared.", DEFAULT_TABLESPACE_NAME)); if (!catalog.existDatabase(DEFAULT_DATABASE_NAME)) { globalEngine.getDDLExecutor().createDatabase(null, DEFAULT_DATABASE_NAME, DEFAULT_TABLESPACE_NAME, false); } else {
private TableDesc handlExistence(boolean ifNotExists, String qualifiedName) throws DuplicateTableException, UndefinedTableException { if (ifNotExists) { LOG.info("relation \"" + qualifiedName + "\" is already exists."); return catalog.getTableDesc(qualifiedName); } else { throw new DuplicateTableException(qualifiedName); } }
if (!catalogService.existDatabase(databaseName) || !catalogService.existsTable(databaseName, tableName)) { return Response.status(Status.NOT_FOUND).build(); catalogService.dropTable(canonicalTableName); return Response.ok().build(); } catch (TajoException e) {
@Test public final void testAlterLocation() throws Exception { if (!testingCluster.isHiveCatalogStoreRunning()) { ////////////////////////////////////////////////////////////////////////////// // Create two table spaces ////////////////////////////////////////////////////////////////////////////// assertFalse(catalog.existTablespace("space1")); catalog.createTablespace("space1", "hdfs://xxx.com/warehouse"); assertTrue(catalog.existTablespace("space1")); // pre verification CatalogProtos.TablespaceProto space1 = catalog.getTablespace("space1"); assertEquals("space1", space1.getSpaceName()); assertEquals("hdfs://xxx.com/warehouse", space1.getUri()); executeString("ALTER TABLESPACE space1 LOCATION 'hdfs://yyy.com/warehouse';"); // Verify ALTER TABLESPACE space1 space1 = catalog.getTablespace("space1"); assertEquals("space1", space1.getSpaceName()); assertEquals("hdfs://yyy.com/warehouse", space1.getUri()); catalog.dropTablespace("space1"); assertFalse(catalog.existTablespace("space1")); } } }
private boolean assertRelationNoExistence(Context context, String tableName) { String qualifiedName = guessTableName(context, tableName); if (catalog.existsTable(qualifiedName)) { context.state.addVerification(new DuplicateTableException(qualifiedName)); return false; } return true; }
"l_quantity from default.lineitem"); TableDesc tableDesc = catalog.getTableDesc(databaseName, tableName); assertNotNull(tableDesc); List<CatalogProtos.PartitionDescProto> partitions = catalog.getPartitionsOfTable(databaseName, tableName); for (CatalogProtos.PartitionDescProto eachPartition : partitions) { assertTrue(eachPartition.getNumBytes() > 0L);
@Test public final void testCreateIndexOnLocation() throws Exception { executeQuery(); assertTrue(catalog.existIndexByName(getCurrentDatabase(), "l_orderkey_idx")); assertTrue(catalog.existIndexByColumnNames(getCurrentDatabase(), "lineitem", new String[]{"l_orderkey"})); catalog.dropIndex(getCurrentDatabase(), "l_orderkey_idx"); assertFalse(catalog.existIndexByName(getCurrentDatabase(), "l_orderkey_idx")); executeString("create index l_orderkey_idx on lineitem (l_orderkey asc nulls first) location '/tajo/warehouse/default/l_orderkey_idx';"); assertTrue(catalog.existIndexByName(getCurrentDatabase(), "l_orderkey_idx")); assertTrue(catalog.existIndexByColumnNames(getCurrentDatabase(), "lineitem", new String[]{"l_orderkey"})); executeString("drop index l_orderkey_idx"); assertFalse(catalog.existIndexByName(getCurrentDatabase(), "l_orderkey_idx")); assertIndexNotExist(getCurrentDatabase(), "l_orderkey_idx"); } }
tablePath.toUri()); tableDesc.setStats(stats); util.getMaster().getCatalog().createTable(tableDesc);