This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some docs; refactoring and some optimization
- Loading branch information
Jerry Liang
committed
Aug 18, 2019
1 parent
82fcead
commit b39032e
Showing
36 changed files
with
2,527 additions
and
1,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"cSpell.words": [ | ||
"transpiler", | ||
"transpiled", | ||
"transpiling" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using openCypherTranspiler.Common.GraphSchema; | ||
using openCypherTranspiler.LogicalPlanner; | ||
using openCypherTranspiler.openCypherParser; | ||
using openCypherTranspiler.SQLRenderer; | ||
|
||
namespace Simple | ||
{ | ||
class Program | ||
{ | ||
class SimpleProvider : ISQLDBSchemaProvider | ||
{ | ||
private static readonly IDictionary<string, NodeSchema> Nodes = new List<NodeSchema>() | ||
{ | ||
new NodeSchema() | ||
{ | ||
Name = "device", | ||
NodeIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "id", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.NodeJoinKey | ||
}, | ||
Properties = Enumerable.Empty<EntityProperty>().ToList() | ||
}, | ||
new NodeSchema() | ||
{ | ||
Name = "tenant", | ||
NodeIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "id", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.NodeJoinKey | ||
}, | ||
Properties = Enumerable.Empty<EntityProperty>().ToList() | ||
}, | ||
new NodeSchema() | ||
{ | ||
Name = "app", | ||
NodeIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "id", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.NodeJoinKey | ||
}, | ||
Properties = new List<EntityProperty>() | ||
{ | ||
new EntityProperty() | ||
{ | ||
PropertyName = "AppName", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.RegularProperty | ||
}, | ||
} | ||
} | ||
}.ToDictionary(kv => kv.Name, kv => kv); | ||
|
||
private static readonly IDictionary<string, EdgeSchema> Edges = new List<EdgeSchema>() | ||
{ | ||
new EdgeSchema() | ||
{ | ||
Name = "belongsTo", | ||
SourceNodeId = "device", | ||
SourceIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "srcid", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.SourceNodeJoinKey | ||
}, | ||
SinkNodeId = "tenant", | ||
SinkIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "destid", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.SinkNodeJoinKey | ||
}, | ||
Properties = Enumerable.Empty<EntityProperty>().ToList() | ||
}, | ||
new EdgeSchema() | ||
{ | ||
Name = "runs", | ||
SourceNodeId = "device", | ||
SourceIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "srcid", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.SourceNodeJoinKey | ||
}, | ||
SinkNodeId = "app", | ||
SinkIdProperty = new EntityProperty() | ||
{ | ||
PropertyName = "destid", | ||
DataType = typeof(string), | ||
PropertyType = EntityProperty.PropertyDefinitionType.SinkNodeJoinKey | ||
}, | ||
Properties = Enumerable.Empty<EntityProperty>().ToList() | ||
} | ||
}.ToDictionary(kv => $"{kv.SourceNodeId}@{kv.Name}@{kv.SinkNodeId}", kv => kv); | ||
|
||
private static readonly IDictionary<string, SQLTableDescriptor> Tables = new List<SQLTableDescriptor>() | ||
{ | ||
new SQLTableDescriptor() | ||
{ | ||
EntityId = "device", | ||
TableOrViewName = "tblDevice" | ||
}, | ||
new SQLTableDescriptor() | ||
{ | ||
EntityId = "tenant", | ||
TableOrViewName = "tblTenant" | ||
}, | ||
new SQLTableDescriptor() | ||
{ | ||
EntityId = "app", | ||
TableOrViewName = "tblApp" | ||
}, | ||
new SQLTableDescriptor() | ||
{ | ||
EntityId = "device@belongsTo@tenant", | ||
TableOrViewName = "tblBelongsTo" | ||
}, | ||
new SQLTableDescriptor() | ||
{ | ||
EntityId = "device@runs@app", | ||
TableOrViewName = "tblRuns" | ||
}, | ||
}.ToDictionary(kv => kv.EntityId, kv => kv); | ||
|
||
public EdgeSchema GetEdgeDefinition(string edgeVerb, string fromNodeName, string toNodeName) | ||
{ | ||
return Edges[$"{fromNodeName}@{edgeVerb}@{toNodeName}"]; | ||
} | ||
|
||
public NodeSchema GetNodeDefinition(string nodeName) | ||
{ | ||
return Nodes[nodeName]; | ||
} | ||
|
||
public SQLTableDescriptor GetSQLTableDescriptors(string entityId) | ||
{ | ||
// In this function, you will need to map SQL table or view to | ||
// the graph entities (nodes and edges). The table or the view | ||
// should already be normalized against the node key or | ||
// the edge source/sink key | ||
return Tables[entityId]; | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
var cypherQueryText = @" | ||
MATCH (d:device)-[:belongsTo]->(t:tenant) | ||
MATCH (d)-[:runs]->(a:app) | ||
RETURN t.id as TenantId, a.AppName as AppName, COUNT(d) as DeviceCount | ||
"; | ||
|
||
Console.WriteLine("Input openCypher Query:"); | ||
Console.WriteLine(cypherQueryText); | ||
|
||
var graphDef = new SimpleProvider(); | ||
|
||
var plan = LogicalPlan.ProcessQueryTree(OpenCypherParser.Parse(cypherQueryText, null), graphDef, null); | ||
var sqlRender = new SQLRenderer(graphDef, null); | ||
var tSqlQuery = sqlRender.RenderPlan(plan); | ||
|
||
Console.WriteLine("Output T-SQL Query:"); | ||
Console.WriteLine(tSqlQuery); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<RestoreSources>$(RestoreSources);../../src/Common/bin/Debug;../../src/openCypherParser/bin/Debug;../../src/LogicalPlanner/bin/Debug;../../src/SQLRenderer/bin/Debug;https://api.nuget.org/v3/index.json</RestoreSources> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="openCypherTranspiler.Common" Version="0.1.0" /> | ||
<PackageReference Include="openCypherTranspiler.openCypherParser" Version="0.1.0" /> | ||
<PackageReference Include="openCypherTranspiler.LogicalPlanner" Version="0.1.0" /> | ||
<PackageReference Include="openCypherTranspiler.SQLRenderer" Version="0.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace openCypherTranspiler.Common.Interfaces | ||
{ | ||
public interface IParser | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.