public static String getStoreTableName(LogicalPlan plan) { LogicalRootNode rootNode = plan.getRootBlock().getRoot(); NodeType nodeType = rootNode.getChild().getType(); if (nodeType == NodeType.CREATE_TABLE) { return ((CreateTableNode)rootNode.getChild()).getTableName(); } else if (nodeType == NodeType.INSERT) { return ((InsertNode)rootNode.getChild()).getTableName(); } else { return null; } }
public static String getStoreTableName(LogicalPlan plan) { LogicalRootNode rootNode = plan.getRootBlock().getRoot(); NodeType nodeType = rootNode.getChild().getType(); if (nodeType == NodeType.CREATE_TABLE) { return ((CreateTableNode)rootNode.getChild()).getTableName(); } else if (nodeType == NodeType.INSERT) { return ((InsertNode)rootNode.getChild()).getTableName(); } else { return null; } }
public static TableDesc getTableDesc(CatalogService catalog, LogicalNode node) throws UndefinedTableException { if (node.getType() == NodeType.ROOT) { node = ((LogicalRootNode)node).getChild(); } if (node.getType() == NodeType.CREATE_TABLE) { return createTableDesc((CreateTableNode)node); } String tableName = null; InsertNode insertNode = null; if (node.getType() == NodeType.INSERT) { insertNode = (InsertNode)node; tableName = insertNode.getTableName(); } else { return null; } if (tableName != null) { String[] tableTokens = tableName.split("\\."); if (tableTokens.length >= 2) { if (catalog.existsTable(tableTokens[0], tableTokens[1])) { return catalog.getTableDesc(tableTokens[0], tableTokens[1]); } } } else { if (insertNode.getUri() != null) { //insert ... location return createTableDesc(insertNode); } } return null; }
public static TableDesc getTableDesc(CatalogService catalog, LogicalNode node) throws UndefinedTableException { if (node.getType() == NodeType.ROOT) { node = ((LogicalRootNode)node).getChild(); } if (node.getType() == NodeType.CREATE_TABLE) { return createTableDesc((CreateTableNode)node); } String tableName = null; InsertNode insertNode = null; if (node.getType() == NodeType.INSERT) { insertNode = (InsertNode)node; tableName = insertNode.getTableName(); } else { return null; } if (tableName != null) { String[] tableTokens = tableName.split("\\."); if (tableTokens.length >= 2) { if (catalog.existsTable(tableTokens[0], tableTokens[1])) { return catalog.getTableDesc(tableTokens[0], tableTokens[1]); } } } else { if (insertNode.getUri() != null) { //insert ... location return createTableDesc(insertNode); } } return null; }
@Override public PlanString getPlanString() { PlanString planString = new PlanString(this); planString.appendTitle(" INTO "); if (hasTargetTable()) { planString.appendTitle(getTableName()); if (hasTargetSchema()) { planString.addExplan(getTargetSchema().toString()); } } else { planString.addExplan("LOCATION " + uri); } return planString; } }
@Override public PlanString getPlanString() { PlanString planString = new PlanString(this); planString.appendTitle(" INTO "); if (hasTargetTable()) { planString.appendTitle(getTableName()); if (hasTargetSchema()) { planString.addExplan(getTargetSchema().toString()); } } else { planString.addExplan("LOCATION " + uri); } return planString; } }
private static TableDesc createTableDesc(InsertNode insertNode) { TableMeta meta = new TableMeta(insertNode.getStorageType(), insertNode.getOptions()); TableDesc tableDescTobeCreated = new TableDesc( insertNode.getTableName(), insertNode.getTableSchema(), meta, insertNode.getUri() != null ? insertNode.getUri() : null); if (insertNode.hasPartition()) { tableDescTobeCreated.setPartitionMethod(insertNode.getPartitionMethod()); } return tableDescTobeCreated; }
private static TableDesc createTableDesc(InsertNode insertNode) { TableMeta meta = new TableMeta(insertNode.getStorageType(), insertNode.getOptions()); TableDesc tableDescTobeCreated = new TableDesc( insertNode.getTableName(), insertNode.getTableSchema(), meta, insertNode.getUri() != null ? insertNode.getUri() : null); if (insertNode.hasPartition()) { tableDescTobeCreated.setPartitionMethod(insertNode.getPartitionMethod()); } return tableDescTobeCreated; }
InsertNode insertNode, SubmitQueryResponse.Builder responseBuilder) { try { String nodeUniqName = insertNode.getTableName() == null ? new Path(insertNode.getUri()).getName() : insertNode.getTableName(); String queryId = nodeUniqName + "_" + System.currentTimeMillis(); builder.setTableName(insertNode.getTableName()); builder.setStats(stats.getProto()); insertNode.getTableName(), insertNode.getTargetSchema(), tableMeta,
InsertNode insertNode, SubmitQueryResponse.Builder responseBuilder) { try { String nodeUniqName = insertNode.getTableName() == null ? new Path(insertNode.getUri()).getName() : insertNode.getTableName(); String queryId = nodeUniqName + "_" + System.currentTimeMillis(); builder.setTableName(insertNode.getTableName()); builder.setStats(stats.getProto()); insertNode.getTableName(), insertNode.getTargetSchema(), tableMeta,
@Test public final void testInsertInto1() throws TajoException { QueryContext qc = createQueryContext(); Expr expr = sqlAnalyzer.parse(insertStatements[1]); LogicalPlan plan = planner.createPlan(qc, expr); assertEquals(1, plan.getQueryBlocks().size()); InsertNode insertNode = getInsertNode(plan); assertFalse(insertNode.isOverwrite()); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "score"), insertNode.getTableName()); }
@Override public void hook(QueryContext queryContext, LogicalPlan plan) throws Exception { queryContext.setInsert(); InsertNode insertNode = plan.getRootBlock().getNode(NodeType.INSERT); // Set QueryContext settings, such as output table name and output path. // It also remove data files if overwrite is true. if (insertNode.hasTargetTable()) { // INSERT INTO [TB_NAME] queryContext.setOutputTable(insertNode.getTableName()); if (insertNode.hasPartition()) { queryContext.setPartitionMethod(insertNode.getPartitionMethod()); } } else { // INSERT INTO LOCATION ... // When INSERT INTO LOCATION, must not set output table. queryContext.setFileOutput(); } // Set the final output table uri queryContext.setOutputPath(insertNode.getUri()); if (insertNode.isOverwrite()) { queryContext.setOutputOverwrite(); } } }
@Override public void hook(QueryContext queryContext, LogicalPlan plan) throws Exception { queryContext.setInsert(); InsertNode insertNode = plan.getRootBlock().getNode(NodeType.INSERT); // Set QueryContext settings, such as output table name and output path. // It also remove data files if overwrite is true. if (insertNode.hasTargetTable()) { // INSERT INTO [TB_NAME] queryContext.setOutputTable(insertNode.getTableName()); if (insertNode.hasPartition()) { queryContext.setPartitionMethod(insertNode.getPartitionMethod()); } } else { // INSERT INTO LOCATION ... // When INSERT INTO LOCATION, must not set output table. queryContext.setFileOutput(); } // Set the final output table uri queryContext.setOutputPath(insertNode.getUri()); if (insertNode.isOverwrite()) { queryContext.setOutputOverwrite(); } } }
@Test public final void testInsertInto0() throws TajoException { QueryContext qc = createQueryContext(); Expr expr = sqlAnalyzer.parse(insertStatements[0]); LogicalPlan plan = planner.createPlan(qc, expr); assertEquals(1, plan.getQueryBlocks().size()); InsertNode insertNode = getInsertNode(plan); assertFalse(insertNode.isOverwrite()); assertTrue(insertNode.hasTargetTable()); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "score"), insertNode.getTableName()); }
String tableName = insertNode.getTableName(); finalTable = catalog.getTableDesc(tableName); } else {
String tableName = insertNode.getTableName(); finalTable = catalog.getTableDesc(tableName); } else {
@Test public final void testInsertInto2() throws TajoException { QueryContext qc = createQueryContext(); Expr expr = sqlAnalyzer.parse(insertStatements[2]); LogicalPlan plan = planner.createPlan(qc, expr); assertEquals(1, plan.getQueryBlocks().size()); InsertNode insertNode = getInsertNode(plan); assertFalse(insertNode.isOverwrite()); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "employee"), insertNode.getTableName()); assertTrue(insertNode.hasTargetSchema()); assertEquals(insertNode.getTargetSchema().getColumn(0).getSimpleName(), "name"); assertEquals(insertNode.getTargetSchema().getColumn(1).getSimpleName(), "deptname"); }
@Test public final void testInsertInto4() throws TajoException { QueryContext qc = createQueryContext(); Expr expr = sqlAnalyzer.parse(insertStatements[4]); LogicalPlan plan = planner.createPlan(qc, expr); assertEquals(1, plan.getQueryBlocks().size()); InsertNode insertNode = getInsertNode(plan); assertTrue(insertNode.isOverwrite()); assertTrue(insertNode.hasTargetTable()); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "employee"), insertNode.getTableName()); assertTrue(insertNode.hasTargetSchema()); assertEquals(insertNode.getTargetSchema().getColumn(0).getSimpleName(), "name"); assertEquals(insertNode.getTargetSchema().getColumn(1).getSimpleName(), "deptname"); }