ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-5353 .NET: DDL example added
Date Wed, 17 Jan 2018 10:43:24 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 5407cf585 -> ab2736270


IGNITE-5353 .NET: DDL example added


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ab273627
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ab273627
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ab273627

Branch: refs/heads/master
Commit: ab27362703714be508e937e972dfdc8280f2251a
Parents: 5407cf5
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Wed Jan 17 13:43:15 2018 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Wed Jan 17 13:43:15 2018 +0300

----------------------------------------------------------------------
 .../Examples/ExamplesTest.cs                    |   3 +-
 .../Apache.Ignite.Examples.csproj               |   1 +
 .../Apache.Ignite.Examples/Sql/SqlDdlExample.cs | 111 +++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ab273627/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
index 90e8e0a..fcae595 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Examples/ExamplesTest.cs
@@ -58,7 +58,8 @@ namespace Apache.Ignite.Core.Tests.Examples
         private static readonly Type[] NoDllExamples =
         {
             typeof(BinaryModeExample), typeof(NearCacheExample), typeof(PeerAssemblyLoadingExample),
-            typeof(ThinClientPutGetExample), typeof(SqlExample), typeof(LinqExample), typeof(SqlDmlExample)
+            typeof(ThinClientPutGetExample), typeof(SqlExample), typeof(LinqExample), typeof(SqlDmlExample),
+            typeof(SqlDdlExample)
         };
 
         /** Config file path. */

http://git-wip-us.apache.org/repos/asf/ignite/blob/ab273627/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
index 6106ffd..51ac5ad 100644
--- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj
@@ -53,6 +53,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Sql\LinqExample.cs" />
+    <Compile Include="Sql\SqlDdlExample.cs" />
     <Compile Include="Sql\SqlDmlExample.cs" />
     <Compile Include="Sql\SqlExample.cs" />
     <Compile Include="ThinClient\ThinClientPutGetExample.cs" />

http://git-wip-us.apache.org/repos/asf/ignite/blob/ab273627/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Sql/SqlDdlExample.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Sql/SqlDdlExample.cs
b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Sql/SqlDdlExample.cs
new file mode 100644
index 0000000..3f72842
--- /dev/null
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Sql/SqlDdlExample.cs
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Examples.Sql
+{
+    using System;
+    using Apache.Ignite.Core;
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Query;
+
+    /// <summary>
+    /// This example showcases DDL capabilities of Ignite's SQL engine.
+    /// <para />
+    /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click ->
Build).
+    /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click
-> Properties ->
+    ///     Application -> Startup object);
+    /// 3) Start example (F5 or Ctrl+F5).
+    /// <para />
+    /// This example can be run with standalone Apache Ignite.NET node:
+    /// 1) Run %IGNITE_HOME%/platforms/dotnet/bin/Apache.Ignite.exe:
+    /// Apache.Ignite.exe -configFileName=platforms\dotnet\examples\apache.ignite.examples\app.config
+    /// 2) Start example.
+    /// </summary>
+    public class SqlDdlExample
+    {
+        /// <summary>Dummy cache name.</summary>
+        private const string DummyCacheName = "dummy_cache";
+
+        [STAThread]
+        public static void Main()
+        {
+            using (var ignite = Ignition.StartFromApplicationConfiguration())
+            {
+                Console.WriteLine();
+                Console.WriteLine(">>> Cache query DDL example started.");
+                
+                // Create dummy cache to act as an entry point for SQL queries (new SQL API
which do not require this
+                // will appear in future versions, JDBC and ODBC drivers do not require it
already).
+                var cacheCfg = new CacheConfiguration(DummyCacheName)
+                {
+                    SqlSchema = "PUBLIC"
+                };
+
+                ICache<object, object> cache = ignite.GetOrCreateCache<object, object>(cacheCfg);
+                
+                // Create reference City table based on REPLICATED template.
+                cache.Query(new SqlFieldsQuery(
+                    "CREATE TABLE city (id LONG PRIMARY KEY, name VARCHAR) WITH \"template=replicated\"")).GetAll();
+
+                // Create table based on PARTITIONED template with one backup.
+                cache.Query(new SqlFieldsQuery(
+                    "CREATE TABLE person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY
(id, city_id)) " +
+                    "WITH \"backups=1, affinity_key=city_id\"")).GetAll();
+
+                // Create an index.
+                cache.Query(new SqlFieldsQuery("CREATE INDEX on Person (city_id)")).GetAll();
+                
+                Console.WriteLine("\n>>> Created database objects.");
+
+                const string addCity = "INSERT INTO city (id, name) VALUES (?, ?)";
+                
+                cache.Query(new SqlFieldsQuery(addCity, 1L, "Forest Hill"));
+                cache.Query(new SqlFieldsQuery(addCity, 2L, "Denver"));
+                cache.Query(new SqlFieldsQuery(addCity, 3L, "St. Petersburg"));
+
+                const string addPerson = "INSERT INTO person (id, name, city_id) values (?,
?, ?)";
+                
+                cache.Query(new SqlFieldsQuery(addPerson, 1L, "John Doe", 3L));
+                cache.Query(new SqlFieldsQuery(addPerson, 2L, "Jane Roe", 2L));
+                cache.Query(new SqlFieldsQuery(addPerson, 3L, "Mary Major", 1L));
+                cache.Query(new SqlFieldsQuery(addPerson, 4L, "Richard Miles", 2L));
+                
+                Console.WriteLine("\n>>> Populated data.");
+                
+                IFieldsQueryCursor res = cache.Query(new SqlFieldsQuery(
+                    "SELECT p.name, c.name FROM Person p INNER JOIN City c on c.id = p.city_id"));
+
+                Console.WriteLine("\n>>> Query results:");
+
+                foreach (var row in res)
+                {
+                    Console.WriteLine("{0}, {1}", row[0], row[1]);
+                }
+                
+                cache.Query(new SqlFieldsQuery("drop table Person")).GetAll();
+                cache.Query(new SqlFieldsQuery("drop table City")).GetAll();
+
+                Console.WriteLine("\n>>> Dropped database objects.");
+            }
+
+            Console.WriteLine();
+            Console.WriteLine(">>> Example finished, press any key to exit ...");
+            Console.ReadKey();
+        }
+    }
+}
\ No newline at end of file


Mime
View raw message