Add support for query params in load csv (#1653)
This commit is contained in:
parent
786cdea260
commit
0133673f1d
@ -467,8 +467,10 @@ antlrcpp::Any CypherMainVisitor::visitLoadCsv(MemgraphCypher::LoadCsvContext *ct
|
||||
|
||||
auto *load_csv = storage_->Create<LoadCsv>();
|
||||
// handle file name
|
||||
if (ctx->csvFile()->literal()->StringLiteral()) {
|
||||
if (ctx->csvFile()->literal() && ctx->csvFile()->literal()->StringLiteral()) {
|
||||
load_csv->file_ = std::any_cast<Expression *>(ctx->csvFile()->accept(this));
|
||||
} else if (ctx->csvFile()->parameter()) {
|
||||
load_csv->file_ = std::any_cast<ParameterLookup *>(ctx->csvFile()->accept(this));
|
||||
} else {
|
||||
throw SemanticException("CSV file path should be a string literal");
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ loadCsv : LOAD CSV FROM csvFile ( WITH | NO ) HEADER
|
||||
( NULLIF nullif ) ?
|
||||
AS rowVar ;
|
||||
|
||||
csvFile : literal ;
|
||||
csvFile : literal | parameter ;
|
||||
|
||||
delimiter : literal ;
|
||||
|
||||
|
@ -232,7 +232,6 @@ class RuleBasedPlanner {
|
||||
} else if (auto *load_csv = utils::Downcast<query::LoadCsv>(clause)) {
|
||||
const auto &row_sym = context.symbol_table->at(*load_csv->row_var_);
|
||||
context.bound_symbols.insert(row_sym);
|
||||
|
||||
input_op = std::make_unique<plan::LoadCsv>(std::move(input_op), load_csv->file_, load_csv->with_header_,
|
||||
load_csv->ignore_bad_, load_csv->delimiter_, load_csv->quote_,
|
||||
load_csv->nullif_, row_sym);
|
||||
|
@ -16,6 +16,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
from gqlalchemy import Memgraph
|
||||
from mgclient import DatabaseError
|
||||
from neo4j import GraphDatabase
|
||||
|
||||
SIMPLE_CSV_FILE = "simple.csv"
|
||||
|
||||
@ -52,5 +53,22 @@ def test_given_one_row_in_db_when_load_csv_after_match_then_pass():
|
||||
assert len(list(results)) == 4
|
||||
|
||||
|
||||
def test_load_csv_with_parameters():
|
||||
memgraph = Memgraph("localhost", 7687)
|
||||
URI = "bolt://localhost:7687"
|
||||
AUTH = ("", "")
|
||||
|
||||
with GraphDatabase.driver(URI, auth=AUTH) as client:
|
||||
with client.session(database="memgraph") as session:
|
||||
results = session.run(
|
||||
f"""MATCH (n {{prop: 1}}) LOAD CSV
|
||||
FROM $file WITH HEADER AS row
|
||||
CREATE (:Person {{name: row.name}})
|
||||
RETURN n""",
|
||||
file=get_file_path(SIMPLE_CSV_FILE),
|
||||
)
|
||||
assert len(list(results)) == 4
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main([__file__, "-rA"]))
|
||||
|
@ -64,7 +64,7 @@ Feature: Functions
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop: ToBoolean("t")});
|
||||
CREATE (:Node {prop: TOBOOLEAN("t")});
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
@ -74,11 +74,11 @@ Feature: Functions
|
||||
| n.prop |
|
||||
| true |
|
||||
|
||||
Scenario: ToBoolean test 03:
|
||||
Scenario: ToBoolean test 04:
|
||||
Given an empty graph
|
||||
And having executed
|
||||
"""
|
||||
CREATE (:Node {prop: ToBoolean("f")});
|
||||
CREATE (:Node {prop: TOBOOLEAN("f")});
|
||||
"""
|
||||
When executing query:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user