Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,14 @@ public final void testInsertOverwriteWithDatabase() throws Exception {
executeString("DROP TABLE table1 PURGE");
}

@Test
public final void testInsertOverwriteTableWithNonFromQuery() throws Exception {
String tableName = CatalogUtil.normalizeIdentifier("InsertOverwriteWithEvalQuery");
public final void testInsertOverwriteAllValues(String rawTableName, String query) throws Exception {
String tableName = CatalogUtil.normalizeIdentifier(rawTableName);
ResultSet res = executeString("create table " + tableName +" (col1 int4, col2 float4, col3 text)");
res.close();
CatalogService catalog = testingCluster.getMaster().getCatalog();
assertTrue(catalog.existsTable(getCurrentDatabase(), tableName));

res = executeString("insert overwrite into " + tableName
+ " select 1::INT4, 2.1::FLOAT4, 'test'; ");
res = executeString(query);

res.close();

Expand All @@ -658,13 +656,24 @@ public final void testInsertOverwriteTableWithNonFromQuery() throws Exception {
}

@Test
public final void testInsertOverwriteTableWithNonFromQuery2() throws Exception {
String tableName = CatalogUtil.normalizeIdentifier("InsertOverwriteWithEvalQuery2");
public final void testInsertOverwriteAllValues1() throws Exception {
String tbName = getMethodName();
testInsertOverwriteAllValues(tbName, "insert overwrite into " + tbName + " select 1::INT4, 2.1::FLOAT4, 'test'; ");
}

@Test
public final void testInsertOverwriteAllValues2() throws Exception {
String tbName = getMethodName();
testInsertOverwriteAllValues(tbName, "insert overwrite into " + tbName + " VALUES(1::INT4, 2.1::FLOAT4, 'test');");
}

public final void testInsertOverwriteSomeValues(String rawTableName, String sql) throws Exception {
String tableName = CatalogUtil.normalizeIdentifier(rawTableName);
ResultSet res = executeString("create table " + tableName +" (col1 int4, col2 float4, col3 text)");
res.close();
CatalogService catalog = testingCluster.getMaster().getCatalog();
assertTrue(catalog.existsTable(getCurrentDatabase(), tableName));
res = executeString("insert overwrite into " + tableName + " (col1, col3) select 1::INT4, 'test';");
res = executeString(sql);
res.close();

TableDesc desc = catalog.getTableDesc(getCurrentDatabase(), tableName);
Expand All @@ -685,6 +694,20 @@ public final void testInsertOverwriteTableWithNonFromQuery2() throws Exception {
executeString("DROP TABLE " + tableName + " PURGE");
}

@Test
public final void testInsertOverwriteTableSomeValues1() throws Exception {
String tbName = getMethodName();
testInsertOverwriteSomeValues(tbName,
"insert overwrite into " + tbName + " (col1, col3) select 1::INT4, 'test'");
}

@Test
public final void testInsertOverwriteTableSomeValues2() throws Exception {
String tbName = getMethodName();
testInsertOverwriteSomeValues(tbName,
"insert overwrite into " + tbName + " (col1, col3) VALUES(1::INT4, 'test')");
}

@Test
public final void testInsertOverwritePathWithNonFromQuery() throws Exception {
ResultSet res = executeString("insert overwrite into location " +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO table1 VALUES (1, 2.3, "str", date '1980-04-01', time '01:50:00', timestamp '1980-04-1 01:50:00');
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"IsOverwrite": false,
"TableName": "table1",
"SubPlan": {
"IsDistinct": false,
"Projections": [
{
"Expr": {
"Value": "1",
"ValueType": "Unsigned_Integer",
"OpType": "Literal"
},
"OpType": "Target"
},
{
"Expr": {
"Value": "2.3",
"ValueType": "Unsigned_Float",
"OpType": "Literal"
},
"OpType": "Target"
},
{
"Expr": {
"ColumnName": "str",
"OpType": "Column"
},
"OpType": "Target"
},
{
"Expr": {
"Date": {
"Year": "1980",
"Month": "04",
"Day": "01"
},
"OpType": "DateLiteral"
},
"OpType": "Target"
},
{
"Expr": {
"Time": {
"Hour": "01",
"Minute": "50",
"Second": "00"
},
"OpType": "TimeLiteral"
},
"OpType": "Target"
},
{
"Expr": {
"Date": {
"Year": "1980",
"Month": "04",
"Day": "1"
},
"Time": {
"Hour": "01",
"Minute": "50",
"Second": "00"
},
"OpType": "TimestampLiteral"
},
"OpType": "Target"
}
],
"OpType": "Projection"
},
"OpType": "Insert"
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void insertRowValues(QueryContext queryContext,
taskAttemptContext = new TaskAttemptContext(queryContext, null, null, null, null);
taskAttemptContext.setOutputPath(new Path(finalOutputUri));

EvalExprExec evalExprExec = new EvalExprExec(taskAttemptContext, (EvalExprNode) insertNode.getChild());
EvalExprExec evalExprExec = new EvalExprExec(taskAttemptContext, insertNode.getChild());
InsertRowsExec exec = new InsertRowsExec(taskAttemptContext, insertNode, evalExprExec);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.tajo.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

import static org.apache.tajo.algebra.Aggregation.GroupElement;
import static org.apache.tajo.algebra.CreateTable.*;
Expand Down Expand Up @@ -1670,7 +1671,16 @@ public Expr visitInsert_statement(Insert_statementContext ctx) {
}
}

insertExpr.setSubQuery(visitQuery_expression(ctx.query_expression()));
if (checkIfExist(ctx.VALUES())) {
List<NamedExpr> values = ctx.row_value_predicand().stream()
.map(value -> new NamedExpr(visitRow_value_predicand(value)))
.collect(Collectors.toList());
Projection projection = new Projection();
projection.setNamedExprs(values.toArray(new NamedExpr[values.size()]));
insertExpr.setSubQuery(projection);
} else {
insertExpr.setSubQuery(visitQuery_expression(ctx.query_expression()));
}

Preconditions.checkState(insertExpr.hasTableName() || insertExpr.hasLocation(),
"Either a table name or a location should be given.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,18 +951,14 @@ parenthesized_boolean_value_expression

/*
===============================================================================
7.2 <row value expression>
7.2 <row value expression> (p293)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you explain what p293 means?

===============================================================================
*/
row_value_expression
: row_value_special_case
| explicit_row_value_constructor
;

row_value_special_case
: nonparenthesized_value_expression_primary
;

explicit_row_value_constructor
: NULL
;
Expand All @@ -978,6 +974,10 @@ row_value_constructor_predicand
// | explicit_row_value_constructor
;

row_value_special_case
: nonparenthesized_value_expression_primary
;

/*
===============================================================================
7.4 <table expression>
Expand Down Expand Up @@ -1605,6 +1605,8 @@ null_ordering

insert_statement
: INSERT (OVERWRITE)? INTO table_name (LEFT_PAREN column_reference_list RIGHT_PAREN)? query_expression
| INSERT (OVERWRITE)? INTO table_name (LEFT_PAREN column_reference_list RIGHT_PAREN)? VALUES
LEFT_PAREN row_value_predicand (COMMA row_value_predicand)* RIGHT_PAREN
| INSERT (OVERWRITE)? INTO LOCATION path=Character_String_Literal (USING storage_type=identifier (param_clause)?)? query_expression
;

Expand Down