This repository was archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathBulkLoadTutorial.cs
More file actions
101 lines (96 loc) · 3.77 KB
/
Copy pathBulkLoadTutorial.cs
File metadata and controls
101 lines (96 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GraphView;
namespace GraphViewTutorial
{
class BulkLoadTutorial
{
static string ReaderFileName = "Reader.txt";
static string BookFileName = "Book.txt";
static string readRelationFileName = "Read.txt";
static void generateFiles()
{
using (System.IO.StreamWriter file =new System.IO.StreamWriter(ReaderFileName))
{
file.WriteLine("Alice,Female");
file.WriteLine("Bob,Male");
file.WriteLine("Clever,");
file.Close();
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter(BookFileName))
{
file.WriteLine("\"The Three-Body Problem\"");
file.WriteLine("\"Harry Potter\"");
file.Close();
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter(readRelationFileName))
{
file.WriteLine("Alice,\"The Three-Body Problem\"");
file.WriteLine("Bob,\"The Three-Body Problem\"");
file.WriteLine("Clever,\"Harry Potter\"");
file.Close();
}
}
static void deleteFiles()
{
System.IO.File.Delete(ReaderFileName);
System.IO.File.Delete(BookFileName);
System.IO.File.Delete(readRelationFileName);
}
public static void run()
{
GraphViewConnection con = new GraphViewConnection(TutorialConfiguration.getConnectionString());
con.Open();
con.ClearData();
try
{
generateFiles();
Console.WriteLine("Creating tables...");
#region Create a schema for reader and book
con.CreateNodeTable(@"CREATE TABLE [Book] (
[ColumnRole:""NodeId""] name VARCHAR(40) )");
con.CreateNodeTable(@"CREATE TABLE [Reader] (
[ColumnRole:""NodeId""] name VARCHAR(30),
[ColumnRole:""Property""] gender VARCHAR(10),
[ColumnRole:""Edge"",Reference:""Book""] Reads VARBINARY(max) )");
#endregion
Console.WriteLine("BulkLoading...");
#region Bulk Load Nodes
con.BulkInsertNode(ReaderFileName, "Reader", "dbo", null, ",", "\n");
con.BulkInsertNode(BookFileName, "Book", "dbo", null, ",", "\n");
con.BulkInsertEdge(readRelationFileName, "dbo", "Reader", "name", "Book", "name", "Reads", null, ",", "\n");
#endregion
Console.WriteLine("Querying...");
#region Query
var res = con.ExecuteReader(@"SELECT x.name as name1, y.name as name2 FROM Reader x, Book y
MATCH x-[Reads]->y ");
try
{
while (res.Read())
{
System.Console.WriteLine(res["name1"].ToString() + " Reads " + res["name2"].ToString());
}
}
finally
{
if (res != null)
res.Close();
}
#endregion
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally // close the connection and drop table
{
con.ClearGraphDatabase();
con.Close();
deleteFiles();
}
}
}
}