Mac High Sierra环境下Neo4j的Load CSV导入命令语法咨询
Using Neo4j's
LOAD CSV for Your Sales Data on Mac OS High Sierra Hey there! Let's walk through exactly how to structure the LOAD CSV command for your specific sales data CSV on Neo4j (running on Mac OS High Sierra). I'll break this down from the basic syntax to a fully customized example that matches your CSV fields.
Core LOAD CSV Structure
The foundational syntax for LOAD CSV (perfect for your header-row CSV) looks like this:
LOAD CSV WITH HEADERS FROM 'file:///path/to/your/csv/file.csv' AS row // Your logic here (create nodes, set properties, link relationships, etc.)
Key Notes for Mac OS:
- Neo4j has a default
importdirectory where it's safest to place your CSV file (avoids permission headaches). For Neo4j Desktop users, find it by right-clicking your database > "Open Folder" > "import". - Once your CSV is in the
importfolder, you can reference it simply asfile:///your_filename.csv—no need for the full system path.
Customized Command for Your CSV Schema
Your CSV mixes numeric, string, and timestamp fields, so we'll cast values to Neo4j's native data types (since CSV reads all values as strings by default). Here's a ready-to-use example that creates a SalesRecord node for each row:
// Use PERIODIC COMMIT for large datasets to avoid memory overload USING PERIODIC COMMIT 1000 LOAD CSV WITH HEADERS FROM 'file:///sales_data.csv' AS row CREATE (s:SalesRecord { // Numeric fields: convert from string to integer salesVolumes: toInteger(row.SALES_VOLUMES), netSales: toInteger(row.NET_SALES), cm1: toInteger(row.CM1), // String fields: use directly productMainGroup: row.PRODUCT_MAIN_GROUP, region: row.REGION, sbu: row.SBU, salesType: row.SALES_TYPE, dataSource: row.DATA_SOURCE, period: row.PERIOD, // Period-related numeric fields periodYear: toInteger(row.PERIOD_YEAR), periodHalfYear: toInteger(row.PERIOD_HALF_YEAR), periodQuarter: toInteger(row.PERIOD_QUARTER), periodMonth: toInteger(row.PERIOD_MONTH), // Additional string fields currency: row.CURRENCY, userId: row.USERID, // Timestamp field: convert to Neo4j's datetime type entryTs: datetime(row.ENTRY_TS) })
Optional Adjustments
- Handling Null Values: If some fields might be empty, use
coalesce()to set a default. For example:salesVolumes: coalesce(toInteger(row.SALES_VOLUMES), 0) - Creating Relationships: If you want to link
SalesRecordnodes to existing nodes (e.g., aRegionnode withname: row.REGION), modify the query to useMATCH+CREATE:USING PERIODIC COMMIT 1000 LOAD CSV WITH HEADERS FROM 'file:///sales_data.csv' AS row MATCH (r:Region {name: row.REGION}) CREATE (s:SalesRecord { /* ... properties ... */ }) CREATE (s)-[:RECORDED_IN]->(r) - Performance Tweaks: For very large CSVs, bump the
PERIODIC COMMITvalue (e.g., 5000) to speed up imports—just keep it aligned with your system's memory capacity.
内容的提问来源于stack exchange,提问作者David
相关产品推荐
相关产品推荐

