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); } }
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); } }
private boolean ensureColumnExistance(String tableName, String columnName) throws UndefinedTableException { final TableDesc tableDesc = catalog.getTableDesc(tableName); return tableDesc.getSchema().containsByName(columnName); } }
private boolean ensureColumnExistance(String tableName, String columnName) throws UndefinedTableException { final TableDesc tableDesc = catalog.getTableDesc(tableName); return tableDesc.getSchema().containsByName(columnName); }
private boolean ensureColumnPartitionKeys(String tableName, String columnName) throws UndefinedTableException { final TableDesc tableDesc = catalog.getTableDesc(tableName); if (tableDesc.getPartitionMethod().getExpressionSchema().contains(columnName)) { return true; } else { return false; } }
private boolean ensureColumnPartitionKeys(String tableName, String columnName) throws UndefinedTableException { final TableDesc tableDesc = catalog.getTableDesc(tableName); if (tableDesc.getPartitionMethod().getExpressionSchema().contains(columnName)) { return true; } else { return false; } }
@Override public boolean isEligible(PlanContext context, Expr expr) throws TajoException { Set<Relation> relations = ExprFinderIncludeSubquery.finds(expr, OpType.Relation); for (Relation eachRelation : relations) { TableDesc tableDesc = catalog.getTableDesc(getQualifiedName(context, eachRelation.getName())); if (tableDesc.hasEmptySchema()) { return true; } } return false; }
@Override public boolean isEligible(PlanContext context, Expr expr) throws TajoException { Set<Relation> relations = ExprFinderIncludeSubquery.finds(expr, OpType.Relation); for (Relation eachRelation : relations) { TableDesc tableDesc = catalog.getTableDesc(getQualifiedName(context, eachRelation.getName())); if (tableDesc.hasEmptySchema()) { return true; } } return false; }
public List<Path> listTableFiles(String tableName) throws Exception { TableDesc tableDesc = testingCluster.getMaster().getCatalog().getTableDesc(getCurrentDatabase(), tableName); if (tableDesc == null) { return null; } Path path = new Path(tableDesc.getUri()); FileSystem fs = path.getFileSystem(conf); return listFiles(fs, path); }
/** * Reads data file from Test Cluster's HDFS * @param tableName * @return data file's contents * @throws Exception */ public String getTableFileContents(String tableName) throws Exception { TableDesc tableDesc = testingCluster.getMaster().getCatalog().getTableDesc(getCurrentDatabase(), tableName); if (tableDesc == null) { return null; } Path path = new Path(tableDesc.getUri()); return getTableFileContents(path); }
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(); }
private void verifyDescTable(String sql, String tableName, String resultFileName) throws Exception { setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); tajoCli.executeScript(sql); tajoCli.executeMetaCommand("\\d " + tableName); tajoCli.executeMetaCommand("\\d \"" + tableName + "\""); String consoleResult = new String(out.toByteArray()); if (!cluster.isHiveCatalogStoreRunning()) { TableMeta meta = cluster.getCatalogService().getTableDesc("default", tableName).getMeta(); assertOutputResult(resultFileName, consoleResult, new String[]{"${table.timezone}", "${table.path}"}, new String[]{cluster.getConfiguration().getSystemTimezone().getID(), TablespaceManager.getDefault().getTableUri(meta, "default", tableName).toString()}); } }
@Test(timeout = 3000) public void testNonForwardQueryPause() throws Exception { final String sql = "select * from default.lineitem"; TableDesc tableDesc = cluster.getMaster().getCatalog().getTableDesc("default", "lineitem"); assertNotNull(tableDesc); assertEquals(0L, tableDesc.getStats().getNumRows().longValue()); try (InputStream testInput = new ByteArrayInputStream(new byte[]{(byte) DefaultTajoCliOutputFormatter.QUIT_COMMAND}); TajoCli cli = new TajoCli(cluster.getConfiguration(), new String[]{}, null, testInput, out, err)) { setVar(cli, SessionVars.CLI_PAGE_ROWS, "2"); setVar(cli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName()); cli.executeScript(sql); String consoleResult; consoleResult = new String(out.toByteArray()); assertOutputResult(consoleResult); } }
@Test public final void testCreateAfterSelect() throws Exception { ResultSet res = testBase.execute( "create table orderkeys as select l_orderkey from lineitem"); res.close(); TajoTestingCluster cluster = testBase.getTestingCluster(); CatalogService catalog = cluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, "orderkeys")); TableDesc orderKeys = catalog.getTableDesc(DEFAULT_DATABASE_NAME, "orderkeys"); if (!cluster.isHiveCatalogStoreRunning()) { assertEquals(8, orderKeys.getStats().getNumRows().intValue()); } }
@Test public final void testInsertOverwriteSmallerColumns() throws Exception { ResultSet res = executeFile("table1_ddl.sql"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), "table1")); TableDesc originalDesc = catalog.getTableDesc(getCurrentDatabase(), "table1"); res = executeFile("testInsertOverwriteSmallerColumns.sql"); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "table1"); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(8, desc.getStats().getNumRows().intValue()); } assertEquals(originalDesc.getSchema(), desc.getSchema()); executeString("DROP TABLE table1 PURGE"); }
@Test public final void testInsertOverwrite() throws Exception { ResultSet res = executeFile("table1_ddl.sql"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), "table1")); res = executeFile("testInsertOverwrite.sql"); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "table1"); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(8, desc.getStats().getNumRows().intValue()); } executeString("DROP TABLE table1 PURGE"); }
@Test public final void testInsertOverwriteWithDatabase() throws Exception { ResultSet res = executeFile("table1_ddl.sql"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), "table1")); res = executeQuery(); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "table1"); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(8, desc.getStats().getNumRows().intValue()); } executeString("DROP TABLE table1 PURGE"); }
@Test public final void testInsertOverwriteWithAsterisk() throws Exception { ResultSet res = executeFile("full_table_csv_ddl.sql"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), "full_table_csv")); res = executeString("insert overwrite into full_table_csv select * from default.lineitem where l_orderkey = 3"); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "full_table_csv"); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(2, desc.getStats().getNumRows().intValue()); } executeString("DROP TABLE full_table_csv PURGE"); }
@Test public final void testInsertOverwriteWithAsteriskAndMore() throws Exception { ResultSet res = executeFile("lineitem_year_month_ddl.sql"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), "lineitem_year_month")); res = executeFile("load_to_lineitem_year_month.sql"); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), "lineitem_year_month"); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(8, desc.getStats().getNumRows().intValue()); } res = executeQuery(); assertResultSet(res); res.close(); executeString("DROP TABLE lineitem_year_month PURGE"); }
@Test public final void testInsertOverwriteCapitalTableName() throws Exception { String tableName = IdentifierUtil.normalizeIdentifier("testInsertOverwriteCapitalTableName"); ResultSet res = executeString("create table " + tableName + " as select * from default.lineitem"); res.close(); CatalogService catalog = testingCluster.getMaster().getCatalog(); assertTrue(catalog.existsTable(getCurrentDatabase(), tableName)); res = executeString("insert overwrite into " + tableName + " select * from default.lineitem where l_orderkey = 3"); res.close(); TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), tableName); if (!testingCluster.isHiveCatalogStoreRunning()) { assertEquals(2, desc.getStats().getNumRows().intValue()); } executeString("DROP TABLE " + tableName + " PURGE"); }