diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7f6de4d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,345 @@ +# 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. + +# editorconfig.org + +# top-most EditorConfig file +root = true + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +spelling_exclusion_path = ./exclusion.dic + +[*.json] +indent_size = 2 + +# Generated code +[*{_AssemblyInfo.cs,.notsupported.cs,*/obj/*/External/**/*,*/obj/dotnet-new.IntegrationTests/*/TemplatePackagesPaths.cs}] +generated_code = true + +# C# files +[*.cs] +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_switch_labels = true +csharp_indent_labels = one_less_than_current + +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + +# avoid this. unless absolutely necessary +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_event = false:suggestion + +# Types: use keywords instead of BCL types, and permit var only when the type is clear +csharp_style_var_for_built_in_types = false:none +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# name all constant fields using PascalCase +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.pascal_case_style.capitalization = pascal_case + +# static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style +dotnet_naming_symbols.static_fields.applicable_kinds = field +dotnet_naming_symbols.static_fields.required_modifiers = static +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case + +# internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# Code style defaults +csharp_using_directive_placement = outside_namespace:suggestion +dotnet_sort_system_directives_first = true +csharp_prefer_braces = true:silent +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none +csharp_style_prefer_switch_expression = true:suggestion + +# Code quality +dotnet_style_readonly_field = true:suggestion +dotnet_code_quality_unused_parameters = non_public:suggestion + +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +csharp_prefer_simple_default_expression = true:suggestion + +# Expression-bodied members +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_constructors = true:silent +csharp_style_expression_bodied_operators = true:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = true:silent + +# Pattern matching +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# Null checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = do_not_ignore +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Default analyzed API surface = 'all' (public APIs + non-public APIs) +dotnet_code_quality.api_surface = all + +# License header +file_header_template = /*\n * Licensed to the Apache Software Foundation (ASF) under one\n * or more contributor license agreements. See the NOTICE file\n * distributed with this work for additional information\n * regarding copyright ownership. The ASF licenses this file\n * to you under the Apache License, Version 2.0 (the\n * "License"); you may not use this file except in compliance\n * with the License. You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */ + +# Code files +[*.{cs,vb}] +# Analyzers +dotnet_code_quality.ca1802.api_surface = private, internal +dotnet_code_quality.ca1822.api_surface = private, internal +dotnet_code_quality.ca2208.api_surface = public +# Mark attributes with AttributeUsageAttribute +dotnet_diagnostic.CA1018.severity = warning +# Properties should not be write only +dotnet_diagnostic.CA1044.severity = warning +# Do not declare protected member in sealed type +dotnet_diagnostic.CA1047.severity = warning +# Avoid using cref tags with a prefix +dotnet_diagnostic.CA1200.severity = suggestion +# P/Invokes should not be visible +dotnet_diagnostic.CA1401.severity = warning +# Parameter names should match base declaration +dotnet_diagnostic.CA1725.severity = suggestion +# Remove empty Finalizers +dotnet_diagnostic.CA1821.severity = warning +# Mark assemblies with NeutralResourcesLanguageAttribute +dotnet_diagnostic.CA1824.severity = warning +# Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used +dotnet_diagnostic.CA1828.severity = warning +# Prefer strongly-typed Append and Insert method overloads on StringBuilder. +dotnet_diagnostic.CA1830.severity = warning +# Use AsSpan or AsMemory instead of Range-based indexers when appropriate +dotnet_diagnostic.CA1832.severity = warning +# Use AsSpan or AsMemory instead of Range-based indexers when appropriate +dotnet_diagnostic.CA1833.severity = warning +# Prefer IsEmpty over Count +dotnet_diagnostic.CA1836.severity = warning +# Use 'Environment.ProcessPath' +dotnet_diagnostic.CA1839.severity = warning +# Do not call ToImmutableCollection on an ImmutableCollection value +# Temporarily disable to avoid regression in preview 1, revert back to warning when start using preview 2 +dotnet_diagnostic.CA2009.severity = none +# Avoid infinite recursion +dotnet_diagnostic.CA2011.severity = warning +# Initialize value type static fields inline +dotnet_diagnostic.CA2207.severity = warning +# Implement serialization constructors +dotnet_diagnostic.CA2229.severity = warning +# Provide correct arguments to formatting methods +dotnet_diagnostic.CA2241.severity = warning +# Test for NaN correctly +dotnet_diagnostic.CA2242.severity = warning +# Do not assign a property to itself. +dotnet_diagnostic.CA2245.severity = warning +# Provide correct 'enum' argument to 'Enum.HasFlag' +dotnet_diagnostic.CA2248.severity = warning +# Do Not Add Schema By URL +dotnet_diagnostic.CA3061.severity = warning +# Insecure DTD processing in XML +dotnet_diagnostic.CA3075.severity = warning +# Insecure XSLT script processing. +dotnet_diagnostic.CA3076.severity = warning +# Insecure Processing in API Design, XmlDocument and XmlTextReader +dotnet_diagnostic.CA3077.severity = warning +# Mark Verb Handlers With Validate Antiforgery Token +dotnet_diagnostic.CA3147.severity = warning +# Do Not Use Broken Cryptographic Algorithms +dotnet_diagnostic.CA5351.severity = warning +# Do Not Disable Certificate Validation +dotnet_diagnostic.CA5359.severity = warning +# Do Not Call Dangerous Methods In Deserialization +dotnet_diagnostic.CA5360.severity = warning +# Do Not Disable SChannel Use of Strong Crypto +dotnet_diagnostic.CA5361.severity = warning +# Do Not Disable Request Validation +dotnet_diagnostic.CA5363.severity = warning +# Do Not Use Deprecated Security Protocols +dotnet_diagnostic.CA5364.severity = warning +# Do Not Disable HTTP Header Checking +dotnet_diagnostic.CA5365.severity = warning +# Set ViewStateUserKey For Classes Derived From Page +dotnet_diagnostic.CA5368.severity = warning +# Use XmlReader For Validating Reader +dotnet_diagnostic.CA5370.severity = warning +# Do not use obsolete key derivation function +dotnet_diagnostic.CA5373.severity = warning +# Do Not Use XslTransform +dotnet_diagnostic.CA5374.severity = warning +# Use SharedAccessProtocol HttpsOnly +dotnet_diagnostic.CA5376.severity = warning +# Use Container Level Access Policy +dotnet_diagnostic.CA5377.severity = warning +# Do not disable ServicePointManagerSecurityProtocols +dotnet_diagnostic.CA5378.severity = warning +# Do Not Use Weak Key Derivation Function Algorithm +dotnet_diagnostic.CA5379.severity = warning +# Do Not Add Certificates To Root Store +dotnet_diagnostic.CA5380.severity = warning +# Ensure Certificates Are Not Added To Root Store +dotnet_diagnostic.CA5381.severity = warning +# Do Not Use Digital Signature Algorithm (DSA) +dotnet_diagnostic.CA5384.severity = warning +# Use Rivest–Shamir–Adleman (RSA) Algorithm With Sufficient Key Size +dotnet_diagnostic.CA5385.severity = warning +dotnet_diagnostic.CS1591.severity = suggestion +# UseIsNullCheck +dotnet_diagnostic.IDE0041.severity = warning +# ValidateFormatString +dotnet_diagnostic.IDE0043.severity = warning +# MakeLocalFunctionStatic +dotnet_diagnostic.IDE0062.severity = warning +# ConvertTypeOfToNameOf +dotnet_diagnostic.IDE0082.severity = warning +# Remove unnecessary lambda expression +dotnet_diagnostic.IDE0200.severity = none +# Remove redundant nullable directive +dotnet_diagnostic.IDE0240.severity = warning + +# C++ Files +[*.{cpp,h,in}] +curly_bracket_next_line = true +indent_brace_style = Allman + +# Xml project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +[*.{csproj,vbproj,proj,nativeproj,locproj}] +charset = utf-8-bom + +# Xml build files +[*.builds] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# YAML config files +[*.{yml,yaml}] +indent_size = 2 + +# Shell scripts +[*.sh] +end_of_line = lf +[*.{cmd, bat}] +end_of_line = crlf + +# IDE0040: Add accessibility modifiers +dotnet_diagnostic.IDE0040.severity = warning + +[*.txt] +insert_final_newline = false + +# Verify settings +[*.{received,verified}.{txt,xml,json}] +charset = "utf-8-bom" +end_of_line = lf +indent_size = unset +indent_style = unset +insert_final_newline = false +tab_width = unset +trim_trailing_whitespace = false diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 3f0367f..dc602ef 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -2,31 +2,30 @@ name: .NET on: push: - branches: [ main, dev/* ] + branches: [main, dev/*] pull_request: - branches: [ main ] + branches: [main, dev/*] jobs: build: - runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] + os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '9.0.x' - - name: Restore dependencies - run: dotnet restore "src/Apache.IoTDB/Apache.IoTDB.csproj" - - name: Check License Header - # skywalking-eyes doesn't support windows - if: runner.os == 'Linux' - uses: apache/skywalking-eyes@v0.6.0 - - name: Build - run: dotnet build --no-restore "src/Apache.IoTDB/Apache.IoTDB.csproj" - - name: Test - run: dotnet test --no-build --verbosity normal "tests/Apache.IoTDB.Tests/Apache.IoTDB.Tests.csproj" + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "9.0.x" + - name: Restore dependencies + run: dotnet restore "src/Apache.IoTDB/Apache.IoTDB.csproj" + - name: Check License Header + # skywalking-eyes doesn't support windows + if: runner.os == 'Linux' + uses: apache/skywalking-eyes@v0.6.0 + - name: Build + run: dotnet build --no-restore "src/Apache.IoTDB/Apache.IoTDB.csproj" + - name: Test + run: dotnet test --no-build --verbosity normal "tests/Apache.IoTDB.Tests/Apache.IoTDB.Tests.csproj" diff --git a/.github/workflows/e2e-multinode.yml b/.github/workflows/e2e-multinode.yml index 60d0a03..dafbd9c 100644 --- a/.github/workflows/e2e-multinode.yml +++ b/.github/workflows/e2e-multinode.yml @@ -2,24 +2,22 @@ name: E2E Tests in MultiNode IoTDB on: push: - branches: [ main, dev/* ] + branches: [main, dev/*] pull_request: - branches: [ main ] + branches: [main, dev/*] jobs: - build: name: e2e test in MultiNode IoTDB runs-on: ubuntu-latest steps: + - name: Check out code into the CSharp module directory + uses: actions/checkout@v4 - - name: Check out code into the CSharp module directory - uses: actions/checkout@v4 - - - name: Set Docker & Run Test - run: | - docker compose -f docker-compose-2c2d.yml up --build --abort-on-container-exit --remove-orphans + - name: Set Docker & Run Test + run: | + docker compose -f docker-compose-2c2d.yml up --build --abort-on-container-exit --remove-orphans - - name: Clean IoTDB & Shut Down Docker - run: | - docker compose -f docker-compose-2c2d.yml down + - name: Clean IoTDB & Shut Down Docker + run: | + docker compose -f docker-compose-2c2d.yml down diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index b8bf1e4..de78f1b 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -2,24 +2,22 @@ name: E2E Tests on: push: - branches: [ main, dev/* ] + branches: [main, dev/*] pull_request: - branches: [ main ] + branches: [main, dev/*] jobs: - build: name: e2e test runs-on: ubuntu-latest steps: + - name: Check out code into the CSharp module directory + uses: actions/checkout@v4 - - name: Check out code into the CSharp module directory - uses: actions/checkout@v4 - - - name: Set Docker & Run Test - run: | - docker network create --subnet 172.18.0.0/24 iotdb-network && docker compose -f docker-compose.yml up --build --abort-on-container-exit --remove-orphans + - name: Set Docker & Run Test + run: | + docker network create --subnet 172.18.0.0/24 iotdb-network && docker compose -f docker-compose.yml up --build --abort-on-container-exit --remove-orphans - - name: Clean IoTDB & Shut Down Docker - run: | - docker compose -f docker-compose.yml down + - name: Clean IoTDB & Shut Down Docker + run: | + docker compose -f docker-compose.yml down diff --git a/Apache.IoTDB.sln b/Apache.IoTDB.sln index 7ddbed2..b6b5aaf 100644 --- a/Apache.IoTDB.sln +++ b/Apache.IoTDB.sln @@ -26,8 +26,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{DEAC57D3-4 docs\time_profile_zh.pdf = docs\time_profile_zh.pdf EndProjectSection EndProject -Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{4D457769-80CB-401F-9155-C3125C04FACD}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apache.IoTDB.Data", "src\Apache.IoTDB.Data\Apache.IoTDB.Data.csproj", "{4308656F-D174-49A6-ACE4-15894B017D55}" EndProject Global diff --git a/samples/Apache.IoTDB.Samples/Program.cs b/samples/Apache.IoTDB.Samples/Program.cs index aee4081..8f57405 100644 --- a/samples/Apache.IoTDB.Samples/Program.cs +++ b/samples/Apache.IoTDB.Samples/Program.cs @@ -17,12 +17,12 @@ * under the License. */ +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System.Threading.Tasks; -using System.CommandLine; -using System.Collections.Generic; -using System; namespace Apache.IoTDB.Samples { @@ -35,46 +35,46 @@ public static async Task Main(string[] args) () => "localhost", description: "Use single endpoint (e.g. --single localhost)"); - var multiOption = new Option>( - "--multi", - description: "Use multiple endpoints (e.g. --multi localhost:6667 localhost:6668)") - { - AllowMultipleArgumentsPerToken = true - }; + var multiOption = new Option>( + "--multi", + description: "Use multiple endpoints (e.g. --multi localhost:6667 localhost:6668)") + { + AllowMultipleArgumentsPerToken = true + }; - var rootCommand = new RootCommand + var rootCommand = new RootCommand { singleOption, multiOption }; - rootCommand.SetHandler(async (string single, List multi) => - { - var utilsTest = new UtilsTest(); - utilsTest.TestParseEndPoint(); + rootCommand.SetHandler(async (string single, List multi) => + { + var utilsTest = new UtilsTest(); + utilsTest.TestParseEndPoint(); - SessionPoolTest sessionPoolTest; + SessionPoolTest sessionPoolTest; - if (!string.IsNullOrEmpty(single) && (multi == null || multi.Count == 0)) - { - sessionPoolTest = new SessionPoolTest(single); - } - else if (multi != null && multi.Count != 0) - { - sessionPoolTest = new SessionPoolTest(multi); - } - else - { - Console.WriteLine("Please specify either --single or --multi endpoints."); - return; - } + if (!string.IsNullOrEmpty(single) && (multi == null || multi.Count == 0)) + { + sessionPoolTest = new SessionPoolTest(single); + } + else if (multi != null && multi.Count != 0) + { + sessionPoolTest = new SessionPoolTest(multi); + } + else + { + Console.WriteLine("Please specify either --single or --multi endpoints."); + return; + } - await sessionPoolTest.Test(); + await sessionPoolTest.Test(); - }, singleOption, multiOption); + }, singleOption, multiOption); - await rootCommand.InvokeAsync(args); + await rootCommand.InvokeAsync(args); } public static void OpenDebugMode(this SessionPool session) diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedRecord.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedRecord.cs index 241a229..ef65bb9 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedRecord.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedRecord.cs @@ -24,476 +24,476 @@ using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestInsertAlignedRecord() { - public async Task TestInsertAlignedRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - int status; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - - string prefixPath = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List { test_measurements[1], test_measurements[2], test_measurements[3] }; - var types = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var encodings = new List { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressors = new List { Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED }; - //status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurements, types, encodings, compressors); - //System.Diagnostics.Debug.Assert(status == 0); - - var measures = new List - { test_measurements[1], test_measurements[2], test_measurements[3] }; - var values = new List { "test_text", true, (int)123 }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 1; timestamp <= fetch_size * processed_size; timestamp++) - { - var rowRecord = new RowRecord(timestamp, values, measures); - var task = session_pool.InsertAlignedRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), rowRecord); - tasks.Add(task); - } - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total insert record time is {0}", end_ms - start_ms)); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedRecordAsync Passed"); - } - public async Task TestInsertAlignedStringRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - - status = await session_pool.CreateAlignedTimeseriesAsync( - string.Format("{0}.{1}", test_database_name, test_device), - new List() { test_measurements[0], test_measurements[1], test_measurements[2] }, - new List() { TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT }, - new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }, - new List() { Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED }); - - System.Diagnostics.Debug.Assert(status == 0); - var measurements = new List - {test_measurements[0], test_measurements[1], test_measurements[2]}; - var values = new List { "test_text1", "test_text2", "test_text3" }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 1; timestamp <= fetch_size * processed_size; timestamp++) - { - var task = session_pool.InsertAlignedStringRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), measurements, values, timestamp); - tasks.Add(task); - } - - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total insert aligned string record time is {0}", end_ms - start_ms)); - var res = await session_pool.ExecuteQueryStatementAsync("select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_cnt = 0; - while (res.HasNext()) - { - res.Next(); - res_cnt++; - } - Console.WriteLine(res_cnt + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_cnt == fetch_size * processed_size); - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedStringRecordAsync Passed"); - } - public async Task TestInsertAlignedRecords() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + var session_pool = new SessionPool(host, port, poolSize); + int status; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + + string prefixPath = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List { testMeasurements[1], testMeasurements[2], testMeasurements[3] }; + var types = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var encodings = new List { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; + var compressors = new List { Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED }; + //status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurements, types, encodings, compressors); + //System.Diagnostics.Debug.Assert(status == 0); + + var measures = new List + { testMeasurements[1], testMeasurements[2], testMeasurements[3] }; + var values = new List { "test_text", true, (int)123 }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 1; timestamp <= fetchSize * processedSize; timestamp++) + { + var rowRecord = new RowRecord(timestamp, values, measures); + var task = session_pool.InsertAlignedRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), rowRecord); + tasks.Add(task); + } + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total insert record time is {0}", end_ms - start_ms)); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedRecordAsync Passed"); + } + public async Task TestInsertAlignedStringRecord() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + + status = await session_pool.CreateAlignedTimeseriesAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), + new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }, + new List() { TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT }, + new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }, + new List() { Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED, Compressor.UNCOMPRESSED }); + + System.Diagnostics.Debug.Assert(status == 0); + var measurements = new List + {testMeasurements[0], testMeasurements[1], testMeasurements[2]}; + var values = new List { "test_text1", "test_text2", "test_text3" }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 1; timestamp <= fetchSize * processedSize; timestamp++) + { + var task = session_pool.InsertAlignedStringRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), measurements, values, timestamp); + tasks.Add(task); + } + + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total insert aligned string record time is {0}", end_ms - start_ms)); + var res = await session_pool.ExecuteQueryStatementAsync("select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_cnt = 0; + while (res.HasNext()) + { + res.Next(); + res_cnt++; + } + Console.WriteLine(res_cnt + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_cnt == fetchSize * processedSize); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedStringRecordAsync Passed"); + } + public async Task TestInsertAlignedRecords() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); - string prefixPath = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List() + string prefixPath = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }; - var data_type_lst = new List() + var data_type_lst = new List() { TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.TEXT }; - var encoding_lst = new List() + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - - var device_id = new List() { }; - for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() + status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + + var device_id = new List() { }; + for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4] }); - measurements_lst.Add(new List() + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { true, (int)123 }); - values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); - values_lst.Add(new List() + var values_lst = new List>() { }; + values_lst.Add(new List() { true, (int)123 }); + values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); + values_lst.Add(new List() {true, (int) 123, (long) 456, (double) 1.1, (float) 10001.1, "test_record"}); - var timestamp_lst = new List() { 1, 2, 3 }; - var rowRecords = new List() { }; - for (var i = 0; i < 3; i++) - { - var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); - rowRecords.Add(rowRecord); - } - - status = await session_pool.InsertAlignedRecordsAsync(device_id, rowRecords); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - Console.WriteLine(status); - - // large data test - device_id = new List() { }; - rowRecords = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, - new List() { test_measurements[1], test_measurements[2] })); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertAlignedRecordsAsync(device_id, rowRecords)); - device_id = new List() { }; - rowRecords = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var record_count = fetch_size * processed_size; - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == record_count); - System.Diagnostics.Debug.Assert(status == 0); - - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedRecords Passed!"); - } - public async Task TestInsertAlignedStringRecords() + var timestamp_lst = new List() { 1, 2, 3 }; + var rowRecords = new List() { }; + for (var i = 0; i < 3; i++) + { + var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); + rowRecords.Add(rowRecord); + } + + status = await session_pool.InsertAlignedRecordsAsync(device_id, rowRecords); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + Console.WriteLine(status); + + // large data test + device_id = new List() { }; + rowRecords = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, + new List() { testMeasurements[1], testMeasurements[2] })); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - - string prefixPath = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List() { test_measurements[1], test_measurements[2] }; - var data_type_lst = new List() { TSDataType.TEXT, TSDataType.TEXT }; - var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - - var device_id = new List() { }; - for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { "test1", "test2" }); - values_lst.Add(new List() { "test3", "test4" }); - values_lst.Add(new List() { "test5", "test6" }); - List timestamp_lst = new List() { 1, 2, 3 }; - - status = await session_pool.InsertAlignedStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - - // large data test - device_id = new List() { }; - measurements_lst = new List>() { }; - values_lst = new List>() { }; - timestamp_lst = new List() { }; - List> tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - values_lst.Add(new List() { "test1", "test2" }); - timestamp_lst.Add(timestamp); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertAlignedStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst)); - device_id = new List() { }; - measurements_lst = new List>() { }; - values_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedStringRecords Passed!"); + tasks.Add(session_pool.InsertAlignedRecordsAsync(device_id, rowRecords)); + device_id = new List() { }; + rowRecords = new List() { }; } - public async Task TestInsertAlignedRecordsOfOneDevice() + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var record_count = fetchSize * processedSize; + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == record_count); + System.Diagnostics.Debug.Assert(status == 0); + + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedRecords Passed!"); + } + public async Task TestInsertAlignedStringRecords() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + + string prefixPath = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List() { testMeasurements[1], testMeasurements[2] }; + var data_type_lst = new List() { TSDataType.TEXT, TSDataType.TEXT }; + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN }; + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY }; + status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + + var device_id = new List() { }; + for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + var values_lst = new List>() { }; + values_lst.Add(new List() { "test1", "test2" }); + values_lst.Add(new List() { "test3", "test4" }); + values_lst.Add(new List() { "test5", "test6" }); + List timestamp_lst = new List() { 1, 2, 3 }; + + status = await session_pool.InsertAlignedStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + + // large data test + device_id = new List() { }; + measurements_lst = new List>() { }; + values_lst = new List>() { }; + timestamp_lst = new List() { }; + List> tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + values_lst.Add(new List() { "test1", "test2" }); + timestamp_lst.Add(timestamp); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + tasks.Add(session_pool.InsertAlignedStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst)); + device_id = new List() { }; + measurements_lst = new List>() { }; + values_lst = new List>() { }; + timestamp_lst = new List() { }; + } + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedStringRecords Passed!"); + } + public async Task TestInsertAlignedRecordsOfOneDevice() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); - string prefixPath = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List() + string prefixPath = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }; - var data_type_lst = new List() + var data_type_lst = new List() { TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.TEXT }; - var encoding_lst = new List() + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4] }); - measurements_lst.Add(new List() + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { true, (int)123 }); - values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); - values_lst.Add(new List() + var values_lst = new List>() { }; + values_lst.Add(new List() { true, (int)123 }); + values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); + values_lst.Add(new List() {true, (int) 123, (long) 456, (double) 1.1, (float) 10001.1, "test_record"}); - var timestamp_lst = new List() { 1, 2, 3 }; - var rowRecords = new List() { }; - for (var i = 0; i < 3; i++) - { - var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); - rowRecords.Add(rowRecord); - } - status = await session_pool.InsertAlignedRecordsOfOneDeviceAsync(device_id, rowRecords); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - rowRecords = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, - new List() { test_measurements[1], test_measurements[2] })); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertAlignedRecordsOfOneDeviceAsync(device_id, rowRecords)); - rowRecords = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedRecordsOfOneDevice Passed!"); + var timestamp_lst = new List() { 1, 2, 3 }; + var rowRecords = new List() { }; + for (var i = 0; i < 3; i++) + { + var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); + rowRecords.Add(rowRecord); + } + status = await session_pool.InsertAlignedRecordsOfOneDeviceAsync(device_id, rowRecords); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + rowRecords = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, + new List() { testMeasurements[1], testMeasurements[2] })); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.InsertAlignedRecordsOfOneDeviceAsync(device_id, rowRecords)); + rowRecords = new List() { }; } - public async Task TestInsertAlignedStringRecordsOfOneDevice() + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedRecordsOfOneDevice Passed!"); + } + public async Task TestInsertAlignedStringRecordsOfOneDevice() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }; + var data_type_lst = new List() { TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT }; + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; + status = await session_pool.CreateAlignedTimeseriesAsync(device_id, measurements, data_type_lst, encoding_lst, compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + + var values_lst = new List>() { }; + values_lst.Add(new List() { "test1", "test2", "test3" }); + values_lst.Add(new List() { "test4", "test5", "test6" }); + values_lst.Add(new List() { "test7", "test8", "test9" }); + + var timestamp_lst = new List() { 1, 2, 3 }; + + status = await session_pool.InsertAlignedStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + // large data test + values_lst = new List>() { }; + var tasks = new List>(); + measurements_lst = new List>() { }; + timestamp_lst = new List() { }; + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + values_lst.Add(new List() { "test1", "test2" }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + timestamp_lst.Add(timestamp); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List() { test_measurements[0], test_measurements[1], test_measurements[2] }; - var data_type_lst = new List() { TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT }; - var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateAlignedTimeseriesAsync(device_id, measurements, data_type_lst, encoding_lst, compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - - var values_lst = new List>() { }; - values_lst.Add(new List() { "test1", "test2", "test3" }); - values_lst.Add(new List() { "test4", "test5", "test6" }); - values_lst.Add(new List() { "test7", "test8", "test9" }); - - var timestamp_lst = new List() { 1, 2, 3 }; - - status = await session_pool.InsertAlignedStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - // large data test - values_lst = new List>() { }; - var tasks = new List>(); - measurements_lst = new List>() { }; - timestamp_lst = new List() { }; - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - values_lst.Add(new List() { "test1", "test2" }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - timestamp_lst.Add(timestamp); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertAlignedStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst)); - values_lst = new List>() { }; - measurements_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedStringRecordsOfOneDevice Passed!"); + tasks.Add(session_pool.InsertAlignedStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst)); + values_lst = new List>() { }; + measurements_lst = new List>() { }; + timestamp_lst = new List() { }; } + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedStringRecordsOfOneDevice Passed!"); } -} \ No newline at end of file + } +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedTablet.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedTablet.cs index 1b6f044..393869f 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedTablet.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.AlignedTablet.cs @@ -25,100 +25,100 @@ namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestInsertAlignedTablet() { - public async Task TestInsertAlignedTablet() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List - { test_measurements[1], - test_measurements[2], - test_measurements[3] + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List + { testMeasurements[1], + testMeasurements[2], + testMeasurements[3] }; - var value_lst = new List> + var value_lst = new List> { new() {"iotdb", true, (int) 12}, new() {"c#", false, (int) 13}, new() {"client", true, (int) 14} }; - var timestamp_lst = new List { 1, 2, 3 }; - var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - status = await session_pool.InsertAlignedTabletAsync(tablet); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + var timestamp_lst = new List { 1, 2, 3 }; + var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + status = await session_pool.InsertAlignedTabletAsync(tablet); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - await res.Close(); - // large data test - value_lst = new List>() { }; - timestamp_lst = new List() { }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - timestamp_lst.Add(timestamp); - value_lst.Add(new List() { "iotdb", true, (int)timestamp }); - if (timestamp % fetch_size == 0) - { - tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - tasks.Add(session_pool.InsertAlignedTabletAsync(tablet)); - value_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } - Console.WriteLine(tasks.Count); + await res.Close(); + // large data test + value_lst = new List>() { }; + timestamp_lst = new List() { }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + timestamp_lst.Add(timestamp); + value_lst.Add(new List() { "iotdb", true, (int)timestamp }); + if (timestamp % fetchSize == 0) + { + tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + tasks.Add(session_pool.InsertAlignedTabletAsync(tablet)); + value_lst = new List>() { }; + timestamp_lst = new List() { }; + } + } + Console.WriteLine(tasks.Count); - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedTablet Passed!"); - } + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedTablet Passed!"); + } - public async Task TestInsertAlignedTablets() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestInsertAlignedTablets() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = new List() + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = new List() { - string.Format("{0}.{1}", test_database_name, test_devices[1]), - string.Format("{0}.{1}", test_database_name, test_devices[2]) + string.Format("{0}.{1}", testDatabaseName, testDevices[1]), + string.Format("{0}.{1}", testDatabaseName, testDevices[2]) }; - var measurements_lst = new List>() + var measurements_lst = new List>() { - new() {test_measurements[1], test_measurements[2], test_measurements[3] }, - new() {test_measurements[1], test_measurements[2], test_measurements[3] } + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3] }, + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3] } }; - var values_lst = new List>>() + var values_lst = new List>>() { new() { @@ -131,65 +131,65 @@ public async Task TestInsertAlignedTablets() new List() {"client_2", true, (int) 3} } }; - var datatype_lst = new List>() + var datatype_lst = new List>() { new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32}, new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32} }; - var timestamp_lst = new List>() + var timestamp_lst = new List>() {new() {2, 1, 3}, new() {3, 1, 2}}; - var tablets = new List() { }; - for (var i = 0; i < device_id.Count; i++) - { - var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); - tablets.Add(tablet); - } + var tablets = new List() { }; + for (var i = 0; i < device_id.Count; i++) + { + var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); + tablets.Add(tablet); + } - status = await session_pool.InsertAlignedTabletsAsync(tablets); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1]) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + status = await session_pool.InsertAlignedTabletsAsync(tablets); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1]) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - // large data test - var tasks = new List>(); - // tablets = new List() { }; - for (var timestamp = 4; timestamp <= processed_size * fetch_size; timestamp++) - { - var local_device_id = string.Format("{0}.{1}", test_database_name, test_devices[1]); - var local_measurements = new List() - {test_measurements[1], test_measurements[2], test_measurements[3]}; - var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; - var local_data_type = new List() { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var local_timestamp = new List { timestamp }; - var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); - tablets.Add(tablet); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertAlignedTabletsAsync(tablets)); - tablets = new List() { }; - } - } + // large data test + var tasks = new List>(); + // tablets = new List() { }; + for (var timestamp = 4; timestamp <= processedSize * fetchSize; timestamp++) + { + var local_device_id = string.Format("{0}.{1}", testDatabaseName, testDevices[1]); + var local_measurements = new List() + {testMeasurements[1], testMeasurements[2], testMeasurements[3]}; + var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; + var local_data_type = new List() { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var local_timestamp = new List { timestamp }; + var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); + tablets.Add(tablet); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.InsertAlignedTabletsAsync(tablets)); + tablets = new List() { }; + } + } - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1])); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1])); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertAlignedTablets Passed!"); - } + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertAlignedTablets Passed!"); } -} \ No newline at end of file + } +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.Record.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.Record.cs index a0b26e6..7604c9a 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.Record.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.Record.cs @@ -25,577 +25,577 @@ namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest - { + public partial class SessionPoolTest + { - public async Task TestInsertRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - int status; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - var measures = new List - {test_measurements[1], test_measurements[2], test_measurements[3]}; - var values = new List { "test_text", true, (int)123 }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 1; timestamp <= fetch_size * processed_size; timestamp++) - { - var rowRecord = new RowRecord(timestamp, values, measures); - var task = session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), rowRecord); - tasks.Add(task); - } - - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total insert aligned record time is {0}", end_ms - start_ms)); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestInsertRecordAsync Passed"); - } - public async Task TestInsertStringRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[0]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - var measurements = new List - {test_measurements[0], test_measurements[1], test_measurements[2]}; - var values = new List { "test_text1", "test_text2", "test_text3" }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 1; timestamp <= fetch_size * processed_size; timestamp++) - { - var task = session_pool.InsertStringRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), measurements, values, timestamp); - tasks.Add(task); - } - - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total insert string record time is {0}", end_ms - start_ms)); - var res = await session_pool.ExecuteQueryStatementAsync("select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_cnt = 0; - while (res.HasNext()) - { - res.Next(); - res_cnt++; - } - Console.WriteLine(res_cnt + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_cnt == fetch_size * processed_size); - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestInsertStringRecordAsync Passed"); - } - public async Task TestInsertStrRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - - var measures = new List { test_measurements[1], test_measurements[2] }; - var values = new List { (int)1, (int)2 }; - var rowRecord = new RowRecord(1, values, measures); - status = await session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), rowRecord); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<2"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - - var tasks = new List>(); - // large data test - var rowRecords = new List() { }; - for (var timestamp = 2; timestamp <= fetch_size * processed_size; timestamp++) - rowRecords.Add(new RowRecord(timestamp, values, measures)); - - for (var timestamp = 2; timestamp <= fetch_size * processed_size; timestamp++) - { - var task = session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), rowRecords[timestamp - 2]); - tasks.Add(task); - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestInsertStrRecord Passed!"); - } - public async Task TestInsertRecords() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[4]), - TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[5]), - TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[6]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - - var device_id = new List() { }; - for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() + public async Task TestInsertRecord() + { + var session_pool = new SessionPool(host, port, poolSize); + int status; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + var measures = new List + {testMeasurements[1], testMeasurements[2], testMeasurements[3]}; + var values = new List { "test_text", true, (int)123 }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 1; timestamp <= fetchSize * processedSize; timestamp++) + { + var rowRecord = new RowRecord(timestamp, values, measures); + var task = session_pool.InsertRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), rowRecord); + tasks.Add(task); + } + + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total insert aligned record time is {0}", end_ms - start_ms)); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestInsertRecordAsync Passed"); + } + public async Task TestInsertStringRecord() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[0]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + var measurements = new List + {testMeasurements[0], testMeasurements[1], testMeasurements[2]}; + var values = new List { "test_text1", "test_text2", "test_text3" }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 1; timestamp <= fetchSize * processedSize; timestamp++) + { + var task = session_pool.InsertStringRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), measurements, values, timestamp); + tasks.Add(task); + } + + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total insert string record time is {0}", end_ms - start_ms)); + var res = await session_pool.ExecuteQueryStatementAsync("select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_cnt = 0; + while (res.HasNext()) + { + res.Next(); + res_cnt++; + } + Console.WriteLine(res_cnt + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_cnt == fetchSize * processedSize); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestInsertStringRecordAsync Passed"); + } + public async Task TestInsertStrRecord() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + + var measures = new List { testMeasurements[1], testMeasurements[2] }; + var values = new List { (int)1, (int)2 }; + var rowRecord = new RowRecord(1, values, measures); + status = await session_pool.InsertRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), rowRecord); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<2"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + + var tasks = new List>(); + // large data test + var rowRecords = new List() { }; + for (var timestamp = 2; timestamp <= fetchSize * processedSize; timestamp++) + rowRecords.Add(new RowRecord(timestamp, values, measures)); + + for (var timestamp = 2; timestamp <= fetchSize * processedSize; timestamp++) + { + var task = session_pool.InsertRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), rowRecords[timestamp - 2]); + tasks.Add(task); + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestInsertStrRecord Passed!"); + } + public async Task TestInsertRecords() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[4]), + TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[5]), + TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[6]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + + var device_id = new List() { }; + for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4] }); - measurements_lst.Add(new List() + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { true, (int)123 }); - values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); - values_lst.Add(new List() + var values_lst = new List>() { }; + values_lst.Add(new List() { true, (int)123 }); + values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); + values_lst.Add(new List() {true, (int) 123, (long) 456, (double) 1.1, (float) 10001.1, "test_record"}); - var timestamp_lst = new List() { 1, 2, 3 }; - var rowRecords = new List() { }; - for (var i = 0; i < 3; i++) - { - var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); - rowRecords.Add(rowRecord); - } - - status = await session_pool.InsertRecordsAsync(device_id, rowRecords); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - Console.WriteLine(status); - - // large data test - device_id = new List() { }; - rowRecords = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, - new List() { test_measurements[1], test_measurements[2] })); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertRecordsAsync(device_id, rowRecords)); - device_id = new List() { }; - rowRecords = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var record_count = fetch_size * processed_size; - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == record_count); - System.Diagnostics.Debug.Assert(status == 0); - - string sql = string.Format("select {0}, {1}, {2} from ", test_measurements[3], test_measurements[1], test_measurements[2]) + string.Format("{0}.{1}", test_database_name, test_device); - res = await session_pool.ExecuteQueryStatementAsync(sql); - res.ShowTableNames(); - RowRecord row = null; - while (res.HasNext()) - { - row = res.Next(); - break; - } - - Console.WriteLine($"{test_database_name}.{test_device}.{row.Measurements[0]} {test_measurements[3]}"); - System.Diagnostics.Debug.Assert($"{test_database_name}.{test_device}.{test_measurements[3]}" == row.Measurements[0]); - System.Diagnostics.Debug.Assert($"{test_database_name}.{test_device}.{test_measurements[1]}" == row.Measurements[1]); - System.Diagnostics.Debug.Assert($"{test_database_name}.{test_device}.{test_measurements[2]}" == row.Measurements[2]); - - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertRecords Passed!"); - } - public async Task TestInsertStringRecords() + var timestamp_lst = new List() { 1, 2, 3 }; + var rowRecords = new List() { }; + for (var i = 0; i < 3; i++) + { + var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); + rowRecords.Add(rowRecord); + } + + status = await session_pool.InsertRecordsAsync(device_id, rowRecords); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + Console.WriteLine(status); + + // large data test + device_id = new List() { }; + rowRecords = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, + new List() { testMeasurements[1], testMeasurements[2] })); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - - var device_id = new List() { }; - for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { "test1", "test2" }); - values_lst.Add(new List() { "test3", "test4" }); - values_lst.Add(new List() { "test5", "test6" }); - var timestamp_lst = new List() { 1, 2, 3 }; - - status = await session_pool.InsertStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - - // large data test - device_id = new List() { }; - measurements_lst = new List>() { }; - values_lst = new List>() { }; - timestamp_lst = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - values_lst.Add(new List() { "test" + timestamp, "test" + timestamp }); - timestamp_lst.Add(timestamp); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst)); - device_id = new List() { }; - measurements_lst = new List>() { }; - values_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var record_count = fetch_size * processed_size; - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == record_count); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertStringRecords Passed!"); + tasks.Add(session_pool.InsertRecordsAsync(device_id, rowRecords)); + device_id = new List() { }; + rowRecords = new List() { }; } - public async Task TestInsertRecordsOfOneDevice() + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var record_count = fetchSize * processedSize; + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == record_count); + System.Diagnostics.Debug.Assert(status == 0); + + string sql = string.Format("select {0}, {1}, {2} from ", testMeasurements[3], testMeasurements[1], testMeasurements[2]) + string.Format("{0}.{1}", testDatabaseName, testDevice); + res = await session_pool.ExecuteQueryStatementAsync(sql); + res.ShowTableNames(); + RowRecord row = null; + while (res.HasNext()) + { + row = res.Next(); + break; + } + + Console.WriteLine($"{testDatabaseName}.{testDevice}.{row.Measurements[0]} {testMeasurements[3]}"); + System.Diagnostics.Debug.Assert($"{testDatabaseName}.{testDevice}.{testMeasurements[3]}" == row.Measurements[0]); + System.Diagnostics.Debug.Assert($"{testDatabaseName}.{testDevice}.{testMeasurements[1]}" == row.Measurements[1]); + System.Diagnostics.Debug.Assert($"{testDatabaseName}.{testDevice}.{testMeasurements[2]}" == row.Measurements[2]); + + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertRecords Passed!"); + } + public async Task TestInsertStringRecords() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + + var device_id = new List() { }; + for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + var values_lst = new List>() { }; + values_lst.Add(new List() { "test1", "test2" }); + values_lst.Add(new List() { "test3", "test4" }); + values_lst.Add(new List() { "test5", "test6" }); + var timestamp_lst = new List() { 1, 2, 3 }; + + status = await session_pool.InsertStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + + // large data test + device_id = new List() { }; + measurements_lst = new List>() { }; + values_lst = new List>() { }; + timestamp_lst = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + values_lst.Add(new List() { "test" + timestamp, "test" + timestamp }); + timestamp_lst.Add(timestamp); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[4]), - TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[5]), - TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[6]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() + tasks.Add(session_pool.InsertStringRecordsAsync(device_id, measurements_lst, values_lst, timestamp_lst)); + device_id = new List() { }; + measurements_lst = new List>() { }; + values_lst = new List>() { }; + timestamp_lst = new List() { }; + } + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var record_count = fetchSize * processedSize; + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == record_count); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertStringRecords Passed!"); + } + public async Task TestInsertRecordsOfOneDevice() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[4]), + TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[5]), + TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[6]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4] }); - measurements_lst.Add(new List() + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { true, (int)123 }); - values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); - values_lst.Add(new List() + var values_lst = new List>() { }; + values_lst.Add(new List() { true, (int)123 }); + values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); + values_lst.Add(new List() {true, (int) 123, (long) 456, (double) 1.1, (float) 10001.1, "test_record"}); - var timestamp_lst = new List() { 1, 2, 3 }; - var rowRecords = new List() { }; - for (var i = 0; i < 3; i++) - { - var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); - rowRecords.Add(rowRecord); - } - - status = await session_pool.InsertRecordsOfOneDeviceAsync(device_id, rowRecords); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - // large data test - rowRecords = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, - new List() { test_measurements[1], test_measurements[2] })); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertRecordsOfOneDeviceAsync(device_id, rowRecords)); - rowRecords = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertRecordsOfOneDevice Passed!"); + var timestamp_lst = new List() { 1, 2, 3 }; + var rowRecords = new List() { }; + for (var i = 0; i < 3; i++) + { + var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); + rowRecords.Add(rowRecord); + } + + status = await session_pool.InsertRecordsOfOneDeviceAsync(device_id, rowRecords); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + // large data test + rowRecords = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, + new List() { testMeasurements[1], testMeasurements[2] })); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.InsertRecordsOfOneDeviceAsync(device_id, rowRecords)); + rowRecords = new List() { }; } - public async Task TestInsertStringRecordsOfOneDevice() + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertRecordsOfOneDevice Passed!"); + } + public async Task TestInsertStringRecordsOfOneDevice() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); + + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[0]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + + var values_lst = new List>() { }; + values_lst.Add(new List() { "test1", "test2", "test3" }); + values_lst.Add(new List() { "test4", "test5", "test6" }); + values_lst.Add(new List() { "test7", "test8", "test9" }); + + var timestamp_lst = new List() { 1, 2, 3 }; + + status = await session_pool.InsertStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + + await res.Close(); + // large data test + values_lst = new List>() { }; + var tasks = new List>(); + measurements_lst = new List>() { }; + timestamp_lst = new List() { }; + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + values_lst.Add(new List() { "test1", "test2" }); + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + timestamp_lst.Add(timestamp); + if (timestamp % fetchSize == 0) { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); - - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[0]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() { test_measurements[0], test_measurements[1], test_measurements[2] }); - - var values_lst = new List>() { }; - values_lst.Add(new List() { "test1", "test2", "test3" }); - values_lst.Add(new List() { "test4", "test5", "test6" }); - values_lst.Add(new List() { "test7", "test8", "test9" }); - - var timestamp_lst = new List() { 1, 2, 3 }; - - status = await session_pool.InsertStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - - await res.Close(); - // large data test - values_lst = new List>() { }; - var tasks = new List>(); - measurements_lst = new List>() { }; - timestamp_lst = new List() { }; - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - values_lst.Add(new List() { "test1", "test2" }); - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - timestamp_lst.Add(timestamp); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst)); - values_lst = new List>() { }; - measurements_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertStringRecordsOfOneDevice Passed!"); + tasks.Add(session_pool.InsertStringRecordsOfOneDeviceAsync(device_id, timestamp_lst, measurements_lst, values_lst)); + values_lst = new List>() { }; + measurements_lst = new List>() { }; + timestamp_lst = new List() { }; } + } + + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertStringRecordsOfOneDevice Passed!"); + } - public async Task TestInsertRecordsWithAllType() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestInsertRecordsWithAllType() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); - var measurements = new List + var measurements = new List { "boolean_measurement", "int32_measurement", @@ -609,7 +609,7 @@ public async Task TestInsertRecordsWithAllType() "string_measurement" }; - var dataTypes = new List + var dataTypes = new List { "BOOLEAN", "INT32", @@ -624,44 +624,44 @@ public async Task TestInsertRecordsWithAllType() }; - var values1 = new List + var values1 = new List { true, 123, 123456789L, 1.23f, 1.23456789, "iotdb", ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds(), DateTime.Today, new byte[] {0x01, 0x02}, "string1" }; - var values2 = new List + var values2 = new List { false, 456, 987654321L, 4.56f, 9.87654321, "iotdb2", ((DateTimeOffset)DateTime.Now.AddSeconds(1)).ToUnixTimeMilliseconds(), DateTime.Today.AddDays(1), new byte[] {0x03, 0x04}, "string2" }; - var values3 = new List + var values3 = new List { true, 789, 123123123L, 7.89f, 7.89101112, "iotdb3", ((DateTimeOffset)DateTime.Now.AddSeconds(2)).ToUnixTimeMilliseconds(), DateTime.Today.AddDays(2), new byte[] {0x05, 0x06}, "string3" }; - var rowRecord1 = new RowRecord(1, values1, measurements, dataTypes); - var rowRecord2 = new RowRecord(2, values2, measurements, dataTypes); - var rowRecord3 = new RowRecord(3, values3, measurements, dataTypes); - - var device_id = new List { string.Format("{0}.{1}", test_database_name, test_device),string.Format("{0}.{1}", test_database_name, test_device),string.Format("{0}.{1}", test_database_name, test_device) }; - var rowRecords = new List { rowRecord1, rowRecord2, rowRecord3 }; - - status = await session_pool.InsertRecordsAsync(device_id, rowRecords); - System.Diagnostics.Debug.Assert(status == 0); - - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - Console.WriteLine(res.Next()); - res_count += 1; - } - - await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertRecordsWithAllType Passed!"); - } + var rowRecord1 = new RowRecord(1, values1, measurements, dataTypes); + var rowRecord2 = new RowRecord(2, values2, measurements, dataTypes); + var rowRecord3 = new RowRecord(3, values3, measurements, dataTypes); + + var device_id = new List { string.Format("{0}.{1}", testDatabaseName, testDevice), string.Format("{0}.{1}", testDatabaseName, testDevice), string.Format("{0}.{1}", testDatabaseName, testDevice) }; + var rowRecords = new List { rowRecord1, rowRecord2, rowRecord3 }; + + status = await session_pool.InsertRecordsAsync(device_id, rowRecords); + System.Diagnostics.Debug.Assert(status == 0); + + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + Console.WriteLine(res.Next()); + res_count += 1; + } + + await res.Close(); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertRecordsWithAllType Passed!"); } -} \ No newline at end of file + } +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.Tablet.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.Tablet.cs index e7c5f5b..1f14fdd 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.Tablet.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.Tablet.cs @@ -25,100 +25,100 @@ namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestInsertTablet() { - public async Task TestInsertTablet() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List { - test_measurements[1], - test_measurements[2], - test_measurements[3] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3] }; - var value_lst = new List> + var value_lst = new List> { new() {"iotdb", true, (int) 12}, new() {"c#", false, (int) 13}, new() {"client", true, (int) 14} }; - var timestamp_lst = new List { 1, 2, 3 }; - var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - status = await session_pool.InsertTabletAsync(tablet); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + var timestamp_lst = new List { 1, 2, 3 }; + var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + status = await session_pool.InsertTabletAsync(tablet); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - await res.Close(); - // large data test - value_lst = new List>() { }; - timestamp_lst = new List() { }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - timestamp_lst.Add(timestamp); - value_lst.Add(new List() { "iotdb", true, (int)timestamp }); - if (timestamp % fetch_size == 0) - { - tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - tasks.Add(session_pool.InsertTabletAsync(tablet)); - value_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } + await res.Close(); + // large data test + value_lst = new List>() { }; + timestamp_lst = new List() { }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + timestamp_lst.Add(timestamp); + value_lst.Add(new List() { "iotdb", true, (int)timestamp }); + if (timestamp % fetchSize == 0) + { + tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + tasks.Add(session_pool.InsertTabletAsync(tablet)); + value_lst = new List>() { }; + timestamp_lst = new List() { }; + } + } - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertTablet Passed!"); - } + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertTablet Passed!"); + } - public async Task TestInsertTablets() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestInsertTablets() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = new List() + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = new List() { - string.Format("{0}.{1}", test_database_name, test_devices[1]), - string.Format("{0}.{1}", test_database_name, test_devices[2]) + string.Format("{0}.{1}", testDatabaseName, testDevices[1]), + string.Format("{0}.{1}", testDatabaseName, testDevices[2]) }; - var measurements_lst = new List>() + var measurements_lst = new List>() { - new() {test_measurements[1], test_measurements[2], test_measurements[3]}, - new() {test_measurements[1], test_measurements[2], test_measurements[3]} + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3]}, + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3]} }; - var values_lst = new List>>() + var values_lst = new List>>() { new() { @@ -131,116 +131,116 @@ public async Task TestInsertTablets() new List() {"client_2", true, (int) 3} } }; - var datatype_lst = new List>() + var datatype_lst = new List>() { new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32}, new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32} }; - var timestamp_lst = new List>() + var timestamp_lst = new List>() {new() {2, 1, 3}, new() {3, 1, 2}}; - var tablets = new List() { }; - for (var i = 0; i < device_id.Count; i++) - { - var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); - tablets.Add(tablet); - } + var tablets = new List() { }; + for (var i = 0; i < device_id.Count; i++) + { + var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); + tablets.Add(tablet); + } - status = await session_pool.InsertTabletsAsync(tablets); - // System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1]) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + status = await session_pool.InsertTabletsAsync(tablets); + // System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1]) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - // large data test + // large data test - var tasks = new List>(); - // tablets = new List(); - for (var timestamp = 4; timestamp <= processed_size * fetch_size; timestamp++) - { - var local_device_id = string.Format("{0}.{1}", test_database_name, test_devices[1]); - var local_measurements = new List() - {test_measurements[1], test_measurements[2], test_measurements[3]}; - var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; - var local_timestamp = new List { timestamp }; - var local_data_type = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); - tablets.Add(tablet); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.InsertTabletsAsync(tablets)); - tablets = new List() { }; - } - } + var tasks = new List>(); + // tablets = new List(); + for (var timestamp = 4; timestamp <= processedSize * fetchSize; timestamp++) + { + var local_device_id = string.Format("{0}.{1}", testDatabaseName, testDevices[1]); + var local_measurements = new List() + {testMeasurements[1], testMeasurements[2], testMeasurements[3]}; + var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; + var local_timestamp = new List { timestamp }; + var local_data_type = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); + tablets.Add(tablet); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.InsertTabletsAsync(tablets)); + tablets = new List() { }; + } + } - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1])); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1])); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - Console.WriteLine(res_count + " " + fetch_size * processed_size); - System.Diagnostics.Debug.Assert(res_count == fetch_size * processed_size); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertTablets Passed!"); - } - public async Task TestInsertTabletWithNullValue() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + await res.Close(); + Console.WriteLine(res_count + " " + fetchSize * processedSize); + System.Diagnostics.Debug.Assert(res_count == fetchSize * processedSize); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertTablets Passed!"); + } + public async Task TestInsertTabletWithNullValue() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List() { test_measurements[1], test_measurements[2], test_measurements[3] }; - var values = new List>() + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List() { testMeasurements[1], testMeasurements[2], testMeasurements[3] }; + var values = new List>() { new List() {null, true, (int) 12}, new List() {"c#", null, (int) 13}, new List() {"client", true, null} }; - var datatype = new List() { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var timestamp = new List() { 2, 1, 3 }; - var tablet = new Tablet(device_id, measurements, datatype, values, timestamp); - status = await session_pool.InsertTabletAsync(tablet); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - Console.WriteLine(res.Next()); - res_count += 1; - } + var datatype = new List() { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var timestamp = new List() { 2, 1, 3 }; + var tablet = new Tablet(device_id, measurements, datatype, values, timestamp); + status = await session_pool.InsertTabletAsync(tablet); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + Console.WriteLine(res.Next()); + res_count += 1; + } - await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertTabletsWithNullValue Passed!"); - } + await res.Close(); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertTabletsWithNullValue Passed!"); + } - public async Task TestInsertTabletWithAllType() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestInsertTabletWithAllType() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List { "boolean_measurement", "int32_measurement", @@ -253,12 +253,12 @@ public async Task TestInsertTabletWithAllType() "blob_measurement", "string_measurement" }; - var values = new List> + var values = new List> { new() {true, 123, 123456789L, 1.23f, 1.23456789, "iotdb", ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds(), DateTime.Today, new byte[] {0x01, 0x02}, "string1"}, new() {false, 456, 987654321L, 4.56f, 9.87654321, "iotdb2", ((DateTimeOffset)DateTime.Now.AddSeconds(1)).ToUnixTimeMilliseconds(), DateTime.Today.AddDays(1), new byte[] {0x03, 0x04}, "string2"} }; - var datatypes = new List + var datatypes = new List { TSDataType.BOOLEAN, TSDataType.INT32, @@ -271,26 +271,26 @@ public async Task TestInsertTabletWithAllType() TSDataType.BLOB, TSDataType.STRING }; - var timestamps = new List {1, 2}; - var tablet = new Tablet(device_id, measurements, datatypes, values, timestamps); - status = await session_pool.InsertTabletAsync(tablet); - System.Diagnostics.Debug.Assert(status == 0); + var timestamps = new List { 1, 2 }; + var tablet = new Tablet(device_id, measurements, datatypes, values, timestamps); + status = await session_pool.InsertTabletAsync(tablet); + System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - Console.WriteLine(res.Next()); - res_count += 1; - } + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + Console.WriteLine(res.Next()); + res_count += 1; + } - await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestInsertTabletWithAllType Passed!"); - } + await res.Close(); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestInsertTabletWithAllType Passed!"); } + } } diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.Template.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.Template.cs index 5e0af66..00e443b 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.Template.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.Template.cs @@ -24,81 +24,81 @@ using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestCreateAndDropSchemaTemplate() { - public async Task TestCreateAndDropSchemaTemplate() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DropSchemaTemplateAsync(test_template_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DropSchemaTemplateAsync(testTemplateName); - MeasurementNode node1 = new MeasurementNode(test_measurements[1], TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node2 = new MeasurementNode(test_measurements[2], TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node3 = new MeasurementNode(test_measurements[3], TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node4 = new MeasurementNode(test_measurements[4], TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node1 = new MeasurementNode(testMeasurements[1], TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node2 = new MeasurementNode(testMeasurements[2], TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node3 = new MeasurementNode(testMeasurements[3], TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node4 = new MeasurementNode(testMeasurements[4], TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); - Template template = new Template(test_template_name); - template.addToTemplate(node1); - template.addToTemplate(node2); - template.addToTemplate(node3); - template.addToTemplate(node4); + Template template = new Template(testTemplateName); + template.addToTemplate(node1); + template.addToTemplate(node2); + template.addToTemplate(node3); + template.addToTemplate(node4); - status = await session_pool.CreateSchemaTemplateAsync(template); - System.Diagnostics.Debug.Assert(status == 0); - var templates = await session_pool.ShowAllTemplatesAsync(); - foreach (var t in templates) - { - Console.WriteLine("template name :\t{0}", t); - } - status = await session_pool.DropSchemaTemplateAsync(test_template_name); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestCreateAndDropSchemaTemplate Passed!"); - } + status = await session_pool.CreateSchemaTemplateAsync(template); + System.Diagnostics.Debug.Assert(status == 0); + var templates = await session_pool.ShowAllTemplatesAsync(); + foreach (var t in templates) + { + Console.WriteLine("template name :\t{0}", t); + } + status = await session_pool.DropSchemaTemplateAsync(testTemplateName); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestCreateAndDropSchemaTemplate Passed!"); + } - public async Task TestSetAndUnsetSchemaTemplate() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestSetAndUnsetSchemaTemplate() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.UnsetSchemaTemplateAsync(string.Format("{0}.{1}", test_database_name, test_device), "template"); - await session_pool.DropSchemaTemplateAsync(test_template_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.UnsetSchemaTemplateAsync(string.Format("{0}.{1}", testDatabaseName, testDevice), "template"); + await session_pool.DropSchemaTemplateAsync(testTemplateName); - MeasurementNode node1 = new MeasurementNode(test_measurements[1], TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node2 = new MeasurementNode(test_measurements[2], TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node3 = new MeasurementNode(test_measurements[3], TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); - MeasurementNode node4 = new MeasurementNode(test_measurements[4], TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node1 = new MeasurementNode(testMeasurements[1], TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node2 = new MeasurementNode(testMeasurements[2], TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node3 = new MeasurementNode(testMeasurements[3], TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); + MeasurementNode node4 = new MeasurementNode(testMeasurements[4], TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); - Template template = new Template(test_template_name); - template.addToTemplate(node1); - template.addToTemplate(node2); - template.addToTemplate(node3); - template.addToTemplate(node4); + Template template = new Template(testTemplateName); + template.addToTemplate(node1); + template.addToTemplate(node2); + template.addToTemplate(node3); + template.addToTemplate(node4); - status = await session_pool.CreateSchemaTemplateAsync(template); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.SetSchemaTemplateAsync(test_template_name, string.Format("{0}.{1}", test_database_name, test_device)); - var paths = await session_pool.ShowPathsTemplateSetOnAsync(test_template_name); - foreach (var p in paths) - { - Console.WriteLine("path :\t{0}", p); - } - status = await session_pool.UnsetSchemaTemplateAsync(string.Format("{0}.{1}", test_database_name, test_device), test_template_name); - status = await session_pool.DropSchemaTemplateAsync(test_template_name); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestSetAndUnsetSchemaTemplate Passed!"); - } + status = await session_pool.CreateSchemaTemplateAsync(template); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.SetSchemaTemplateAsync(testTemplateName, string.Format("{0}.{1}", testDatabaseName, testDevice)); + var paths = await session_pool.ShowPathsTemplateSetOnAsync(testTemplateName); + foreach (var p in paths) + { + Console.WriteLine("path :\t{0}", p); + } + status = await session_pool.UnsetSchemaTemplateAsync(string.Format("{0}.{1}", testDatabaseName, testDevice), testTemplateName); + status = await session_pool.DropSchemaTemplateAsync(testTemplateName); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestSetAndUnsetSchemaTemplate Passed!"); } + } -} \ No newline at end of file +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.TestNetwork.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.TestNetwork.cs index a0bc278..fad6591 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.TestNetwork.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.TestNetwork.cs @@ -24,259 +24,259 @@ using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestTestInsertRecord() { - public async Task TestTestInsertRecord() - { - var session_pool = new SessionPool(host, port, pool_size); - int status; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + var session_pool = new SessionPool(host, port, poolSize); + int status; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); - System.Diagnostics.Debug.Assert(status == 0); - var measures = new List + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); + System.Diagnostics.Debug.Assert(status == 0); + var measures = new List { - test_measurements[1], test_measurements[2], test_measurements[3] + testMeasurements[1], testMeasurements[2], testMeasurements[3] }; - var values = new List { "test_text", true, (int)123 }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 1; timestamp <= fetch_size * processed_size; timestamp++) - { - var rowRecord = new RowRecord(timestamp, values, measures); - var task = session_pool.TestInsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), rowRecord); - tasks.Add(task); - } + var values = new List { "test_text", true, (int)123 }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 1; timestamp <= fetchSize * processedSize; timestamp++) + { + var rowRecord = new RowRecord(timestamp, values, measures); + var task = session_pool.TestInsertRecordAsync( + string.Format("{0}.{1}", testDatabaseName, testDevice), rowRecord); + tasks.Add(task); + } - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total insert record time is {0}", end_ms - start_ms)); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestTestInsertRecordAsync Passed"); - } + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total insert record time is {0}", end_ms - start_ms)); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestTestInsertRecordAsync Passed"); + } - public async Task TestTestInsertRecords() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestTestInsertRecords() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - var status = 0; - await session_pool.DeleteDatabaseAsync(test_database_name); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[4]), - TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[5]), - TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[6]), TSDataType.TEXT, - TSEncoding.PLAIN, Compressor.SNAPPY); - System.Diagnostics.Debug.Assert(status == 0); + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + var status = 0; + await session_pool.DeleteDatabaseAsync(testDatabaseName); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[4]), + TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[5]), + TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[6]), TSDataType.TEXT, + TSEncoding.PLAIN, Compressor.SNAPPY); + System.Diagnostics.Debug.Assert(status == 0); - var device_id = new List() { }; - for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); + var device_id = new List() { }; + for (var i = 0; i < 3; i++) device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); - var measurements_lst = new List>() { }; - measurements_lst.Add(new List() { test_measurements[1], test_measurements[2] }); - measurements_lst.Add(new List() + var measurements_lst = new List>() { }; + measurements_lst.Add(new List() { testMeasurements[1], testMeasurements[2] }); + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4] }); - measurements_lst.Add(new List() + measurements_lst.Add(new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }); - var values_lst = new List>() { }; - values_lst.Add(new List() { true, (int)123 }); - values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); - values_lst.Add(new List() + var values_lst = new List>() { }; + values_lst.Add(new List() { true, (int)123 }); + values_lst.Add(new List() { true, (int)123, (long)456, (double)1.1 }); + values_lst.Add(new List() {true, (int) 123, (long) 456, (double) 1.1, (float) 10001.1, "test_record"}); - var timestamp_lst = new List() { 1, 2, 3 }; - var rowRecords = new List() { }; - for (var i = 0; i < 3; i++) - { - var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); - rowRecords.Add(rowRecord); - } + var timestamp_lst = new List() { 1, 2, 3 }; + var rowRecords = new List() { }; + for (var i = 0; i < 3; i++) + { + var rowRecord = new RowRecord(timestamp_lst[i], values_lst[i], measurements_lst[i]); + rowRecords.Add(rowRecord); + } - status = await session_pool.TestInsertRecordsAsync(device_id, rowRecords); - // System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + status = await session_pool.TestInsertRecordsAsync(device_id, rowRecords); + // System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - await res.Close(); + await res.Close(); - // large data test - device_id = new List() { }; - rowRecords = new List() { }; - var tasks = new List>(); - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - device_id.Add(string.Format("{0}.{1}", test_database_name, test_device)); - rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, - new List() { test_measurements[1], test_measurements[2] })); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.TestInsertRecordsAsync(device_id, rowRecords)); - device_id = new List() { }; - rowRecords = new List() { }; - } - } + // large data test + device_id = new List() { }; + rowRecords = new List() { }; + var tasks = new List>(); + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + device_id.Add(string.Format("{0}.{1}", testDatabaseName, testDevice)); + rowRecords.Add(new RowRecord(timestamp, new List() { true, (int)123 }, + new List() { testMeasurements[1], testMeasurements[2] })); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.TestInsertRecordsAsync(device_id, rowRecords)); + device_id = new List() { }; + rowRecords = new List() { }; + } + } - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var record_count = fetch_size * processed_size; - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var record_count = fetchSize * processedSize; + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - System.Diagnostics.Debug.Assert(res_count == 0); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestTestInsertRecords Passed!"); - } + await res.Close(); + System.Diagnostics.Debug.Assert(res_count == 0); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestTestInsertRecords Passed!"); + } - public async Task TestTestInsertTablet() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestTestInsertTablet() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List - { test_measurements[1], - test_measurements[2], - test_measurements[3] + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List + { testMeasurements[1], + testMeasurements[2], + testMeasurements[3] }; - var value_lst = new List> + var value_lst = new List> { new() {"iotdb", true, (int) 12}, new() {"c#", false, (int) 13}, new() {"client", true, (int) 14} }; - var timestamp_lst = new List { 2, 1, 3 }; - var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - status = await session_pool.TestInsertTabletAsync(tablet); - System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); + var timestamp_lst = new List { 2, 1, 3 }; + var datatype_lst = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + status = await session_pool.TestInsertTabletAsync(tablet); + System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); - await res.Close(); - // large data test - value_lst = new List>() { }; - timestamp_lst = new List() { }; - var tasks = new List>(); - var start_ms = DateTime.Now.Ticks / 10000; - for (var timestamp = 4; timestamp <= fetch_size * processed_size; timestamp++) - { - timestamp_lst.Add(timestamp); - value_lst.Add(new List() { "iotdb", true, (int)timestamp }); - if (timestamp % (fetch_size / 32) == 0) - { - tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); - tasks.Add(session_pool.TestInsertTabletAsync(tablet)); - value_lst = new List>() { }; - timestamp_lst = new List() { }; - } - } + await res.Close(); + // large data test + value_lst = new List>() { }; + timestamp_lst = new List() { }; + var tasks = new List>(); + var start_ms = DateTime.Now.Ticks / 10000; + for (var timestamp = 4; timestamp <= fetchSize * processedSize; timestamp++) + { + timestamp_lst.Add(timestamp); + value_lst.Add(new List() { "iotdb", true, (int)timestamp }); + if (timestamp % (fetchSize / 32) == 0) + { + tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); + tasks.Add(session_pool.TestInsertTabletAsync(tablet)); + value_lst = new List>() { }; + timestamp_lst = new List() { }; + } + } - Task.WaitAll(tasks.ToArray()); - var end_ms = DateTime.Now.Ticks / 10000; - Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device)); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } + Task.WaitAll(tasks.ToArray()); + var end_ms = DateTime.Now.Ticks / 10000; + Console.WriteLine(string.Format("total tablet insert time is {0}", end_ms - start_ms)); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice)); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } - await res.Close(); - System.Diagnostics.Debug.Assert(res_count == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestTestInsertTablet Passed!"); - } + await res.Close(); + System.Diagnostics.Debug.Assert(res_count == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestTestInsertTablet Passed!"); + } - public async Task TestTestInsertTablets() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + public async Task TestTestInsertTablets() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - var device_id = new List() + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + var device_id = new List() { - string.Format("{0}.{1}", test_database_name, test_devices[1]), - string.Format("{0}.{1}", test_database_name, test_devices[2]) + string.Format("{0}.{1}", testDatabaseName, testDevices[1]), + string.Format("{0}.{1}", testDatabaseName, testDevices[2]) }; - var measurements_lst = new List>() + var measurements_lst = new List>() { - new() {test_measurements[1], test_measurements[2], test_measurements[3]}, - new() {test_measurements[1], test_measurements[2], test_measurements[3]} + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3]}, + new() {testMeasurements[1], testMeasurements[2], testMeasurements[3]} }; - var values_lst = new List>>() + var values_lst = new List>>() { new() { @@ -289,66 +289,66 @@ public async Task TestTestInsertTablets() new List() {"client_2", true, (int) 3} } }; - var datatype_lst = new List>() + var datatype_lst = new List>() { new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32}, new() {TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32} }; - var timestamp_lst = new List>() + var timestamp_lst = new List>() {new() {2, 1, 3}, new() {3, 1, 2}}; - var tablets = new List() { }; - for (var i = 0; i < device_id.Count; i++) - { - var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); - tablets.Add(tablet); - } + var tablets = new List() { }; + for (var i = 0; i < device_id.Count; i++) + { + var tablet = new Tablet(device_id[i], measurements_lst[i], datatype_lst[i], values_lst[i], timestamp_lst[i]); + tablets.Add(tablet); + } - status = await session_pool.TestInsertTabletsAsync(tablets); - // System.Diagnostics.Debug.Assert(status == 0); - var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1]) + " where time<15"); - res.ShowTableNames(); - while (res.HasNext()) Console.WriteLine(res.Next()); - await res.Close(); + status = await session_pool.TestInsertTabletsAsync(tablets); + // System.Diagnostics.Debug.Assert(status == 0); + var res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1]) + " where time<15"); + res.ShowTableNames(); + while (res.HasNext()) Console.WriteLine(res.Next()); + await res.Close(); - // large data test + // large data test - var tasks = new List>(); - for (var timestamp = 4; timestamp <= processed_size * fetch_size; timestamp++) - { - var local_device_id = string.Format("{0}.{1}", test_database_name, test_devices[1]); - var local_measurements = new List() - {test_measurements[1], test_measurements[2], test_measurements[3]}; - var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; - var local_timestamp = new List { timestamp }; - var local_data_type = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; - var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); - tablets.Add(tablet); - if (timestamp % fetch_size == 0) - { - tasks.Add(session_pool.TestInsertTabletsAsync(tablets)); - tablets = new List() { }; - } - } - - Task.WaitAll(tasks.ToArray()); - res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_devices[1])); - res.ShowTableNames(); - var res_count = 0; - while (res.HasNext()) - { - res.Next(); - res_count += 1; - } - - await res.Close(); - System.Diagnostics.Debug.Assert(res_count == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestTestInsertTablets Passed!"); + var tasks = new List>(); + for (var timestamp = 4; timestamp <= processedSize * fetchSize; timestamp++) + { + var local_device_id = string.Format("{0}.{1}", testDatabaseName, testDevices[1]); + var local_measurements = new List() + {testMeasurements[1], testMeasurements[2], testMeasurements[3]}; + var local_value = new List>() { new() { "iotdb", true, (int)timestamp } }; + var local_timestamp = new List { timestamp }; + var local_data_type = new List { TSDataType.TEXT, TSDataType.BOOLEAN, TSDataType.INT32 }; + var tablet = new Tablet(local_device_id, local_measurements, local_data_type, local_value, local_timestamp); + tablets.Add(tablet); + if (timestamp % fetchSize == 0) + { + tasks.Add(session_pool.TestInsertTabletsAsync(tablets)); + tablets = new List() { }; } + } + Task.WaitAll(tasks.ToArray()); + res = await session_pool.ExecuteQueryStatementAsync( + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevices[1])); + res.ShowTableNames(); + var res_count = 0; + while (res.HasNext()) + { + res.Next(); + res_count += 1; + } + + await res.Close(); + System.Diagnostics.Debug.Assert(res_count == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestTestInsertTablets Passed!"); } -} \ No newline at end of file + + } +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.TimeSeries.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.TimeSeries.cs index 92ba363..ce98c60 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.TimeSeries.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.TimeSeries.cs @@ -25,173 +25,173 @@ using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Samples { - public partial class SessionPoolTest + public partial class SessionPoolTest + { + public async Task TestCreateMultiTimeSeries() { - public async Task TestCreateMultiTimeSeries() - { - // by Luzhan - var session_pool = new SessionPool(host, port, user, passwd, pool_size); - await session_pool.Open(false); - var status = 0; - if (debug) session_pool.OpenDebugMode(); + // by Luzhan + var session_pool = new SessionPool(host, port, username, password, poolSize); + await session_pool.Open(false); + var status = 0; + if (debug) session_pool.OpenDebugMode(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - var measurement_lst = new List { 1, 2, 3, 4, 5, 6 }; - var ts_path_lst = new List(measurement_lst.ConvertAll( - (measurement) => string.Format("{0}.{1}.{2}{3}", test_database_name, test_device, test_measurement, measurement))); - var data_type_lst = new List() + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + var measurement_lst = new List { 1, 2, 3, 4, 5, 6 }; + var ts_path_lst = new List(measurement_lst.ConvertAll( + (measurement) => string.Format("{0}.{1}.{2}{3}", testDatabaseName, testDevice, testMeasurement, measurement))); + var data_type_lst = new List() { TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT }; - var encoding_lst = new List() + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateMultiTimeSeriesAsync(ts_path_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestCreateMultiTimeSeries Passed!"); - } + status = await session_pool.CreateMultiTimeSeriesAsync(ts_path_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestCreateMultiTimeSeries Passed!"); + } - public async Task TestDeleteTimeSeries() - { - var session_pool = new SessionPool(host, port, user, passwd, pool_size); - await session_pool.Open(false); - var status = 0; - if (debug) session_pool.OpenDebugMode(); + public async Task TestDeleteTimeSeries() + { + var session_pool = new SessionPool(host, port, username, password, poolSize); + await session_pool.Open(false); + var status = 0; + if (debug) session_pool.OpenDebugMode(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - var measurement_lst = new List { 1, 2, 3, 4, 5, 6 }; - var ts_path_lst = new List(measurement_lst.ConvertAll( - (measurement) => string.Format("{0}.{1}.{2}{3}", test_database_name, test_device, test_measurement, measurement))); - var data_type_lst = new List() + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + var measurement_lst = new List { 1, 2, 3, 4, 5, 6 }; + var ts_path_lst = new List(measurement_lst.ConvertAll( + (measurement) => string.Format("{0}.{1}.{2}{3}", testDatabaseName, testDevice, testMeasurement, measurement))); + var data_type_lst = new List() { TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT }; - var encoding_lst = new List() + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateMultiTimeSeriesAsync(ts_path_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteTimeSeriesAsync(ts_path_lst); - System.Diagnostics.Debug.Assert(status == 0); - Console.WriteLine("TestDeleteTimeSeries Passed!"); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - } - public async Task TestCreateTimeSeries() - { - var session_pool = new SessionPool(host, port, pool_size); - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + status = await session_pool.CreateMultiTimeSeriesAsync(ts_path_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteTimeSeriesAsync(ts_path_lst); + System.Diagnostics.Debug.Assert(status == 0); + Console.WriteLine("TestDeleteTimeSeries Passed!"); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + } + public async Task TestCreateTimeSeries() + { + var session_pool = new SessionPool(host, port, poolSize); + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), - TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), - TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[4]), - TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[5]), - TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[6]), - TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.Close(); - Console.WriteLine("TestCreateTimeSeries Passed!"); - } + await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), + TSDataType.INT32, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), + TSDataType.INT64, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[4]), + TSDataType.FLOAT, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[5]), + TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + System.Diagnostics.Debug.Assert(await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[6]), + TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY) == 0); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.Close(); + Console.WriteLine("TestCreateTimeSeries Passed!"); + } - public async Task TestCreateAlignedTimeseries() - { - var session_pool = new SessionPool(host, port, user, passwd, pool_size); - await session_pool.Open(false); - var status = 0; - if (debug) session_pool.OpenDebugMode(); + public async Task TestCreateAlignedTimeseries() + { + var session_pool = new SessionPool(host, port, username, password, poolSize); + await session_pool.Open(false); + var status = 0; + if (debug) session_pool.OpenDebugMode(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); - string prefixPath = string.Format("{0}.{1}", test_database_name, test_device); - var measurement_lst = new List() + string prefixPath = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurement_lst = new List() { - test_measurements[1], - test_measurements[2], - test_measurements[3], - test_measurements[4], - test_measurements[5], - test_measurements[6] + testMeasurements[1], + testMeasurements[2], + testMeasurements[3], + testMeasurements[4], + testMeasurements[5], + testMeasurements[6] }; - var data_type_lst = new List() + var data_type_lst = new List() { TSDataType.BOOLEAN, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE, TSDataType.TEXT }; - var encoding_lst = new List() + var encoding_lst = new List() { TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN }; - var compressor_lst = new List() + var compressor_lst = new List() { Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY, Compressor.SNAPPY }; - status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, - compressor_lst); - System.Diagnostics.Debug.Assert(status == 0); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestCreateAlignedTimeSeries Passed!"); - } - public async Task TestCheckTimeSeriesExists() - { - var session_pool = new SessionPool(host, port, pool_size); - var status = 0; - await session_pool.Open(false); - if (debug) session_pool.OpenDebugMode(); + status = await session_pool.CreateAlignedTimeseriesAsync(prefixPath, measurement_lst, data_type_lst, encoding_lst, + compressor_lst); + System.Diagnostics.Debug.Assert(status == 0); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestCreateAlignedTimeSeries Passed!"); + } + public async Task TestCheckTimeSeriesExists() + { + var session_pool = new SessionPool(host, port, poolSize); + var status = 0; + await session_pool.Open(false); + if (debug) session_pool.OpenDebugMode(); - System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - await session_pool.DeleteDatabaseAsync(test_database_name); - await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); - var ifExist_1 = await session_pool.CheckTimeSeriesExistsAsync( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1])); - var ifExist_2 = await session_pool.CheckTimeSeriesExistsAsync( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2])); - System.Diagnostics.Debug.Assert(ifExist_1 == true && ifExist_2 == false); - status = await session_pool.DeleteDatabaseAsync(test_database_name); - System.Diagnostics.Debug.Assert(status == 0); - await session_pool.Close(); - Console.WriteLine("TestCheckTimeSeriesExists Passed!"); - } + System.Diagnostics.Debug.Assert(session_pool.IsOpen()); + await session_pool.DeleteDatabaseAsync(testDatabaseName); + await session_pool.CreateTimeSeries( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); + var ifExist_1 = await session_pool.CheckTimeSeriesExistsAsync( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1])); + var ifExist_2 = await session_pool.CheckTimeSeriesExistsAsync( + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2])); + System.Diagnostics.Debug.Assert(ifExist_1 == true && ifExist_2 == false); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); + System.Diagnostics.Debug.Assert(status == 0); + await session_pool.Close(); + Console.WriteLine("TestCheckTimeSeriesExists Passed!"); } + } -} \ No newline at end of file +} diff --git a/samples/Apache.IoTDB.Samples/SessionPoolTest.cs b/samples/Apache.IoTDB.Samples/SessionPoolTest.cs index 03d211e..8b27c97 100644 --- a/samples/Apache.IoTDB.Samples/SessionPoolTest.cs +++ b/samples/Apache.IoTDB.Samples/SessionPoolTest.cs @@ -19,13 +19,13 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; using Apache.IoTDB.Data; using Apache.IoTDB.DataStructure; using ConsoleTableExt; -using System.Net.Sockets; -using System.Diagnostics; namespace Apache.IoTDB.Samples { @@ -33,29 +33,29 @@ public partial class SessionPoolTest { public string host = "localhost"; public int port = 6667; - public string user = "root"; - public string passwd = "root"; - public List node_urls = new(); - public int fetch_size = 500; - public int processed_size = 4; + public string username = "root"; + public string password = "root"; + public List nodeUrls = new(); + public int fetchSize = 500; + public int processedSize = 4; public bool debug = false; - private int pool_size = 2; - public static string test_template_name = "TEST_CSHARP_CLIENT_TEMPLATE_97209"; - public static string test_database_name = "root.TEST_CSHARP_CLIENT_GROUP_97209"; - public static string test_device = "TEST_CSHARP_CLIENT_DEVICE"; - public static string test_measurement = "TEST_CSHARP_CLIENT_TS"; - public static List device_count = new List() { 0, 1, 2, 3 }; - public static List measurement_count = new List() { 0, 1, 2, 3, 4, 5, 6 }; - public static List test_devices = new List( - device_count.ConvertAll(x => test_device + x.ToString()).ToArray() + private int poolSize = 2; + public static string testTemplateName = "TEST_CSHARP_CLIENT_TEMPLATE_97209"; + public static string testDatabaseName = "root.TEST_CSHARP_CLIENT_GROUP_97209"; + public static string testDevice = "TEST_CSHARP_CLIENT_DEVICE"; + public static string testMeasurement = "TEST_CSHARP_CLIENT_TS"; + public static List deviceCount = new List() { 0, 1, 2, 3 }; + public static List measurementCount = new List() { 0, 1, 2, 3, 4, 5, 6 }; + public static List testDevices = new List( + deviceCount.ConvertAll(x => testDevice + x.ToString()).ToArray() ); - public List test_measurements = new List( - measurement_count.ConvertAll(x => test_measurement + x.ToString()).ToArray() + public List testMeasurements = new List( + measurementCount.ConvertAll(x => testMeasurement + x.ToString()).ToArray() ); public SessionPoolTest(string _host = "localhost") { host = _host; - node_urls.Add(host + ":" + port); + nodeUrls.Add(host + ":" + port); } public SessionPoolTest(List _nodeUrls) @@ -64,7 +64,8 @@ public SessionPoolTest(List _nodeUrls) } public async Task Test() { - if(nodeUrls.Count == 1){ + if (nodeUrls.Count == 1) + { await TestOpenWithNodeUrls(); await TestOpenWith2NodeUrls(); @@ -147,13 +148,14 @@ public async Task Test() await TestNonSqlBy_ADO(); } - else { + else + { await TestMultiNodeDataFetch(); } } public async Task TestOpenWithNodeUrls() { - var session_pool = new SessionPool(node_urls, 8); + var session_pool = new SessionPool(nodeUrls, 8); await session_pool.Open(false); Debug.Assert(session_pool.IsOpen()); if (debug) session_pool.OpenDebugMode(); @@ -177,21 +179,21 @@ public async Task TestOpenWith2NodeUrls() } public async Task TestOpenWithNodeUrlsAndInsertOneRecord() { - var session_pool = new SessionPool(node_urls, 8); + var session_pool = new SessionPool(nodeUrls, 8); await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - await session_pool.DeleteDatabaseAsync(test_database_name); + await session_pool.DeleteDatabaseAsync(testDatabaseName); var status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[0]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[0]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); - var rowRecord = new RowRecord(1668404120807, new() { "1111111", "22222", "333333" }, new() { test_measurements[0], test_measurements[1], test_measurements[2] }); - status = await session_pool.InsertRecordsAsync(new List() { string.Format("{0}.{1}", test_database_name, test_device) }, new List() { rowRecord }); + var rowRecord = new RowRecord(1668404120807, new() { "1111111", "22222", "333333" }, new() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + status = await session_pool.InsertRecordsAsync(new List() { string.Format("{0}.{1}", testDatabaseName, testDevice) }, new List() { rowRecord }); Debug.Assert(status == 0); Console.WriteLine("TestOpenWithNodeUrlsAndInsertOneRecord Passed!"); } @@ -200,26 +202,26 @@ public async Task TestInsertOneRecord() var session_pool = new SessionPool(host, port, 1); await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - await session_pool.DeleteDatabaseAsync(test_database_name); + await session_pool.DeleteDatabaseAsync(testDatabaseName); var status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[0]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[0]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); - var rowRecord = new RowRecord(1668404120807, new() { "1111111", "22222", "333333" }, new() { test_measurements[0], test_measurements[1], test_measurements[2] }); - status = await session_pool.InsertRecordsAsync(new List() { string.Format("{0}.{1}", test_database_name, test_device) }, new List() { rowRecord }); + var rowRecord = new RowRecord(1668404120807, new() { "1111111", "22222", "333333" }, new() { testMeasurements[0], testMeasurements[1], testMeasurements[2] }); + status = await session_pool.InsertRecordsAsync(new List() { string.Format("{0}.{1}", testDatabaseName, testDevice) }, new List() { rowRecord }); } public async Task TestGetTimeZone() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - await session_pool.DeleteDatabaseAsync(test_database_name); + await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); var time_zone = await session_pool.GetTimeZone(); System.Diagnostics.Debug.Assert(time_zone == "UTC+08:00"); @@ -231,35 +233,35 @@ public async Task TestGetTimeZone() public async Task TestCreateAndDeleteDatabase() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert( - await session_pool.CreateDatabase(test_database_name) == 0); + await session_pool.CreateDatabase(testDatabaseName) == 0); System.Diagnostics.Debug.Assert( - await session_pool.DeleteDatabaseAsync(test_database_name) == 0); + await session_pool.DeleteDatabaseAsync(testDatabaseName) == 0); await session_pool.Close(); Console.WriteLine("TestSetAndDeleteStorageGroup Passed!"); } public async Task TestDeleteDatabase() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - await session_pool.CreateDatabase(string.Format("{0}{1}", test_database_name, "_01")); - await session_pool.CreateDatabase(string.Format("{0}{1}", test_database_name, "_02")); - await session_pool.CreateDatabase(string.Format("{0}{1}", test_database_name, "_03")); - await session_pool.CreateDatabase(string.Format("{0}{1}", test_database_name, "_04")); + await session_pool.CreateDatabase(string.Format("{0}{1}", testDatabaseName, "_01")); + await session_pool.CreateDatabase(string.Format("{0}{1}", testDatabaseName, "_02")); + await session_pool.CreateDatabase(string.Format("{0}{1}", testDatabaseName, "_03")); + await session_pool.CreateDatabase(string.Format("{0}{1}", testDatabaseName, "_04")); var database_names = new List() { }; - database_names.Add(string.Format("{0}{1}", test_database_name, "_01")); - database_names.Add(string.Format("{0}{1}", test_database_name, "_02")); - database_names.Add(string.Format("{0}{1}", test_database_name, "_03")); - database_names.Add(string.Format("{0}{1}", test_database_name, "_04")); + database_names.Add(string.Format("{0}{1}", testDatabaseName, "_01")); + database_names.Add(string.Format("{0}{1}", testDatabaseName, "_02")); + database_names.Add(string.Format("{0}{1}", testDatabaseName, "_03")); + database_names.Add(string.Format("{0}{1}", testDatabaseName, "_04")); System.Diagnostics.Debug.Assert(await session_pool.DeleteDatabasesAsync(database_names) == 0); await session_pool.Close(); Console.WriteLine("TestDeleteStorageGroups Passed!"); @@ -268,11 +270,11 @@ public async Task TestDeleteDatabase() public async Task TestSetTimeZone() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); - await session_pool.DeleteDatabaseAsync(test_database_name); + await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); await session_pool.SetTimeZone("GMT+8:00"); System.Diagnostics.Debug.Assert(await session_pool.GetTimeZone() == "GMT+8:00"); @@ -282,63 +284,63 @@ public async Task TestSetTimeZone() public async Task TestDeleteData() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), TSDataType.TEXT, + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), TSDataType.TEXT, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); System.Diagnostics.Debug.Assert(status == 0); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); System.Diagnostics.Debug.Assert(status == 0); status = await session_pool.CreateTimeSeries( - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[3]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[3]), TSDataType.INT32, TSEncoding.PLAIN, Compressor.UNCOMPRESSED); System.Diagnostics.Debug.Assert(status == 0); var measures = new List { - test_measurements[1], test_measurements[2], test_measurements[3] + testMeasurements[1], testMeasurements[2], testMeasurements[3] }; var values = new List { "test_text", true, (int)123 }; status = await session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), new RowRecord(1, values, measures)); + string.Format("{0}.{1}", testDatabaseName, testDevice), new RowRecord(1, values, measures)); System.Diagnostics.Debug.Assert(status == 0); status = await session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), new RowRecord(2, values, measures)); + string.Format("{0}.{1}", testDatabaseName, testDevice), new RowRecord(2, values, measures)); System.Diagnostics.Debug.Assert(status == 0); status = await session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), new RowRecord(3, values, measures)); + string.Format("{0}.{1}", testDatabaseName, testDevice), new RowRecord(3, values, measures)); System.Diagnostics.Debug.Assert(status == 0); status = await session_pool.InsertRecordAsync( - string.Format("{0}.{1}", test_database_name, test_device), new RowRecord(4, values, measures)); + string.Format("{0}.{1}", testDatabaseName, testDevice), new RowRecord(4, values, measures)); System.Diagnostics.Debug.Assert(status == 0); var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); res.ShowTableNames(); while (res.HasNext()) Console.WriteLine(res.Next()); await res.Close(); var ts_path_lst = new List() { - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[1]), - string.Format("{0}.{1}.{2}", test_database_name, test_device, test_measurements[2]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]), + string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[2]), }; await session_pool.DeleteDataAsync(ts_path_lst, 2, 3); res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); res.ShowTableNames(); while (res.HasNext()) Console.WriteLine(res.Next()); await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(status == 0); await session_pool.Close(); Console.WriteLine("TestDeleteData Passed!"); @@ -346,37 +348,37 @@ public async Task TestDeleteData() public async Task TestNonSql() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".status with datatype=BOOLEAN,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".status with datatype=BOOLEAN,encoding=PLAIN"); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".temperature with datatype=FLOAT,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".temperature with datatype=FLOAT,encoding=PLAIN"); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".hardware with datatype=TEXT,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".hardware with datatype=TEXT,encoding=PLAIN"); status = await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')"); System.Diagnostics.Debug.Assert(status == 0); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); var res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); res.ShowTableNames(); while (res.HasNext()) Console.WriteLine(res.Next()); await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(status == 0); await session_pool.Close(); Console.WriteLine("TestNonSql Passed"); @@ -391,31 +393,31 @@ public async Task TestNonSqlBy_ADO() await cnt.OpenAsync(); var session_pool = cnt.SessionPool; System.Diagnostics.Debug.Assert(cnt.State == System.Data.ConnectionState.Open); - var status = await session_pool.DeleteDatabaseAsync(test_database_name); + var status = await session_pool.DeleteDatabaseAsync(testDatabaseName); await cnt.CreateCommand( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".status with datatype=BOOLEAN,encoding=PLAIN").ExecuteNonQueryAsync(); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".status with datatype=BOOLEAN,encoding=PLAIN").ExecuteNonQueryAsync(); await cnt.CreateCommand( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".temperature with datatype=FLOAT,encoding=PLAIN").ExecuteNonQueryAsync(); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".temperature with datatype=FLOAT,encoding=PLAIN").ExecuteNonQueryAsync(); await cnt.CreateCommand( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".hardware with datatype=TEXT,encoding=PLAIN").ExecuteNonQueryAsync(); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".hardware with datatype=TEXT,encoding=PLAIN").ExecuteNonQueryAsync(); status = await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (3, false, 20, '1yxl')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (3, false, 20, '1yxl')").ExecuteNonQueryAsync(); status = await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')").ExecuteNonQueryAsync(); System.Diagnostics.Debug.Assert(status == 0); await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')").ExecuteNonQueryAsync(); await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')").ExecuteNonQueryAsync(); await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')").ExecuteNonQueryAsync(); await cnt.CreateCommand( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')").ExecuteNonQueryAsync(); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')").ExecuteNonQueryAsync(); var reader = await cnt.CreateCommand( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10").ExecuteReaderAsync(); + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10").ExecuteReaderAsync(); ConsoleTableBuilder.From(reader.ToDataTable()).WithFormatter(0, fc => $"{fc:yyyy-MM-dd HH:mm:ss.fff}").WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); await cnt.CloseAsync(); System.Diagnostics.Debug.Assert(status == 0); @@ -425,29 +427,29 @@ await cnt.CreateCommand( public async Task TestSqlQuery() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".status with datatype=BOOLEAN,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".status with datatype=BOOLEAN,encoding=PLAIN"); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".temperature with datatype=FLOAT,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".temperature with datatype=FLOAT,encoding=PLAIN"); await session_pool.ExecuteNonQueryStatementAsync( - "create timeseries " + string.Format("{0}.{1}", test_database_name, test_device) + ".hardware with datatype=TEXT,encoding=PLAIN"); + "create timeseries " + string.Format("{0}.{1}", testDatabaseName, testDevice) + ".hardware with datatype=TEXT,encoding=PLAIN"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (4, false, 20, 'yxl')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (5, true, 12, 'myy')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, temperature, hardware) VALUES (6, true, 21, 'lz')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); await session_pool.ExecuteNonQueryStatementAsync( - "insert into " + string.Format("{0}.{1}", test_database_name, test_device) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); + "insert into " + string.Format("{0}.{1}", testDatabaseName, testDevice) + "(timestamp, status, hardware) VALUES (7, true,'lz')"); var res = await session_pool.ExecuteQueryStatementAsync("show timeseries root"); res.ShowTableNames(); @@ -474,28 +476,28 @@ await session_pool.ExecuteNonQueryStatementAsync( await res.Close(); Console.WriteLine("SELECT sql Passed"); res = await session_pool.ExecuteQueryStatementAsync( - "select * from " + string.Format("{0}.{1}", test_database_name, test_device) + " where time<10"); + "select * from " + string.Format("{0}.{1}", testDatabaseName, testDevice) + " where time<10"); res.ShowTableNames(); while (res.HasNext()) Console.WriteLine(res.Next()); await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(status == 0); await session_pool.Close(); Console.WriteLine("SELECT sql Passed"); } public async Task TestRawDataQuery() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List { test_measurements[0], test_measurements[1] }; + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List { testMeasurements[0], testMeasurements[1] }; var data_type_lst = new List { TSDataType.BOOLEAN, TSDataType.FLOAT }; var encoding_lst = new List { TSEncoding.PLAIN, TSEncoding.PLAIN }; var compressor_lst = new List { Compressor.SNAPPY, Compressor.SNAPPY }; @@ -504,7 +506,7 @@ public async Task TestRawDataQuery() var records = new List(); var values = new List() { true, 20.0f }; var device_id_lst = new List() { }; - for (int i = 1; i <= fetch_size * processed_size; i++) + for (int i = 1; i <= fetchSize * processedSize; i++) { var record = new RowRecord(i, values, measurements); records.Add(record); @@ -513,36 +515,36 @@ public async Task TestRawDataQuery() status = await session_pool.InsertAlignedRecordsAsync(device_id_lst, records); System.Diagnostics.Debug.Assert(status == 0); - var paths = new List() { string.Format("{0}.{1}", device_id, test_measurements[0]), string.Format("{0}.{1}", device_id, test_measurements[1]) }; + var paths = new List() { string.Format("{0}.{1}", device_id, testMeasurements[0]), string.Format("{0}.{1}", device_id, testMeasurements[1]) }; - var res = await session_pool.ExecuteRawDataQuery(paths, 10, fetch_size * processed_size); + var res = await session_pool.ExecuteRawDataQuery(paths, 10, fetchSize * processedSize); var count = 0; while (res.HasNext()) { var record = res.Next(); count++; } - Console.WriteLine(count + " " + (fetch_size * processed_size - 10)); - System.Diagnostics.Debug.Assert(count == fetch_size * processed_size - 10); + Console.WriteLine(count + " " + (fetchSize * processedSize - 10)); + System.Diagnostics.Debug.Assert(count == fetchSize * processedSize - 10); await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(status == 0); await session_pool.Close(); Console.WriteLine("RawDataQuery Passed"); } public async Task TestLastDataQuery() { - var session_pool = new SessionPool(host, port, pool_size); + var session_pool = new SessionPool(host, port, poolSize); var status = 0; await session_pool.Open(false); if (debug) session_pool.OpenDebugMode(); System.Diagnostics.Debug.Assert(session_pool.IsOpen()); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); - var device_id = string.Format("{0}.{1}", test_database_name, test_device); - var measurements = new List { test_measurements[0], test_measurements[1] }; + var device_id = string.Format("{0}.{1}", testDatabaseName, testDevice); + var measurements = new List { testMeasurements[0], testMeasurements[1] }; var data_type_lst = new List { TSDataType.BOOLEAN, TSDataType.FLOAT }; var encoding_lst = new List { TSEncoding.PLAIN, TSEncoding.PLAIN }; var compressor_lst = new List { Compressor.SNAPPY, Compressor.SNAPPY }; @@ -551,7 +553,7 @@ public async Task TestLastDataQuery() var records = new List(); var values = new List() { true, 20.0f }; var device_id_lst = new List() { }; - for (int i = 1; i <= fetch_size * processed_size; i++) + for (int i = 1; i <= fetchSize * processedSize; i++) { var record = new RowRecord(i, values, measurements); records.Add(record); @@ -560,9 +562,9 @@ public async Task TestLastDataQuery() status = await session_pool.InsertAlignedRecordsAsync(device_id_lst, records); System.Diagnostics.Debug.Assert(status == 0); - var paths = new List() { string.Format("{0}.{1}", device_id, test_measurements[0]), string.Format("{0}.{1}", device_id, test_measurements[1]) }; + var paths = new List() { string.Format("{0}.{1}", device_id, testMeasurements[0]), string.Format("{0}.{1}", device_id, testMeasurements[1]) }; - var res = await session_pool.ExecuteLastDataQueryAsync(paths, fetch_size * processed_size - 10); + var res = await session_pool.ExecuteLastDataQueryAsync(paths, fetchSize * processedSize - 10); var count = 0; while (res.HasNext()) { @@ -570,17 +572,18 @@ public async Task TestLastDataQuery() Console.WriteLine(record); count++; } - Console.WriteLine(count + " " + (fetch_size * processed_size - 10)); + Console.WriteLine(count + " " + (fetchSize * processedSize - 10)); System.Diagnostics.Debug.Assert(count == 2); await res.Close(); - status = await session_pool.DeleteDatabaseAsync(test_database_name); + status = await session_pool.DeleteDatabaseAsync(testDatabaseName); System.Diagnostics.Debug.Assert(status == 0); await session_pool.Close(); Console.WriteLine("LastDataQuery Passed"); } - public async Task TestMultiNodeDataFetch(){ + public async Task TestMultiNodeDataFetch() + { System.Diagnostics.Debug.Assert(nodeUrls.Count > 1, "nodeUrls.Count should be greater than 1 in MultiNode Test"); var session_pool = new SessionPool.Builder() .SetUsername(username) @@ -596,7 +599,7 @@ public async Task TestMultiNodeDataFetch(){ var data_type_lst = new List { TSDataType.BOOLEAN, TSDataType.FLOAT }; var encoding_lst = new List { TSEncoding.PLAIN, TSEncoding.PLAIN }; var compressor_lst = new List { Compressor.SNAPPY, Compressor.SNAPPY }; - var ts_path_lst = new List() { + var ts_path_lst = new List() { string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[0]), string.Format("{0}.{1}.{2}", testDatabaseName, testDevice, testMeasurements[1]) }; @@ -631,4 +634,4 @@ public async Task TestMultiNodeDataFetch(){ Console.WriteLine("MultiNodeDataFetch Passed"); } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB.Data/DataReaderExtensions.cs b/src/Apache.IoTDB.Data/DataReaderExtensions.cs index 75f1137..afb8eb7 100644 --- a/src/Apache.IoTDB.Data/DataReaderExtensions.cs +++ b/src/Apache.IoTDB.Data/DataReaderExtensions.cs @@ -32,7 +32,7 @@ public static class DataReaderExtensions { public static SessionPool CreateSession(this IoTDBConnectionStringBuilder db) { - return new SessionPool(db.DataSource, db.Port, db.Username, db.Password, db.FetchSize, db.ZoneId, db.PoolSize,db.Compression,db.TimeOut); + return new SessionPool(db.DataSource, db.Port, db.Username, db.Password, db.FetchSize, db.ZoneId, db.PoolSize, db.Compression, db.TimeOut); } public static List ToObject(this IDataReader dataReader) diff --git a/src/Apache.IoTDB.Data/IoTDBCommand.cs b/src/Apache.IoTDB.Data/IoTDBCommand.cs index adc9159..1d3c2b9 100644 --- a/src/Apache.IoTDB.Data/IoTDBCommand.cs +++ b/src/Apache.IoTDB.Data/IoTDBCommand.cs @@ -17,7 +17,6 @@ * under the License. */ -using Apache.IoTDB.DataStructure; using System; using System.Collections.Generic; using System.ComponentModel; @@ -30,6 +29,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Data @@ -314,7 +314,7 @@ public override void Prepare() Debug.WriteLine($"_commandText:{_commandText}"); #endif int _affectRows = 0; - SessionDataSet dataSet=null; + SessionDataSet dataSet = null; bool isok = false; Task taskDataSet = null; if (_parameters.IsValueCreated) @@ -336,9 +336,9 @@ public override void Prepare() } } - if (isok && dataSet != null ) + if (isok && dataSet != null) { - dataReader = new IoTDBDataReader(this, dataSet, closeConnection ); + dataReader = new IoTDBDataReader(this, dataSet, closeConnection); } else if (taskDataSet.Status == TaskStatus.Running || !isok) { @@ -367,7 +367,7 @@ public override void Prepare() private RowRecord BindParamters(IoTDBParameterCollection pms) { var measures = new List(); - var values = new List (); + var values = new List(); for (int i = 0; i < pms.Count; i++) @@ -375,11 +375,11 @@ private RowRecord BindParamters(IoTDBParameterCollection pms) var tp = pms[i]; measures.Add(tp.ParameterName); - // _commandText = _commandText.Replace(tp.ParameterName, "?"); + // _commandText = _commandText.Replace(tp.ParameterName, "?"); switch (TypeInfo.GetTypeCode(tp.Value?.GetType())) { case TypeCode.Boolean: - values.Add ((tp.Value as bool?).GetValueOrDefault()); + values.Add((tp.Value as bool?).GetValueOrDefault()); break; case TypeCode.Char: values.Add(tp.Value as string); @@ -431,7 +431,7 @@ private RowRecord BindParamters(IoTDBParameterCollection pms) } } - return new RowRecord(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),values,measures); + return new RowRecord(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), values, measures); } /// @@ -523,8 +523,8 @@ public override int ExecuteNonQuery() throw new InvalidOperationException($"CallRequiresSetCommandText{nameof(ExecuteNonQuery)}"); } var result = Task.Run(() => _IoTDB.ExecuteNonQueryStatementAsync(_commandText)); - var ok = result.Wait(TimeSpan.FromSeconds(CommandTimeout)); - if (!ok) throw new TimeoutException(); + var ok = result.Wait(TimeSpan.FromSeconds(CommandTimeout)); + if (!ok) throw new TimeoutException(); return result.Result; } diff --git a/src/Apache.IoTDB.Data/IoTDBConnection.cs b/src/Apache.IoTDB.Data/IoTDBConnection.cs index 860f25e..507a153 100644 --- a/src/Apache.IoTDB.Data/IoTDBConnection.cs +++ b/src/Apache.IoTDB.Data/IoTDBConnection.cs @@ -23,14 +23,13 @@ using System.Data.Common; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; - -using System.Linq; -using System.Threading.Tasks; using System.Threading; +using System.Threading.Tasks; namespace Apache.IoTDB.Data { @@ -45,7 +44,7 @@ public partial class IoTDBConnection : DbConnection private string _connectionString; private ConnectionState _state; - internal SessionPool _IoTDB; + internal SessionPool _IoTDB; @@ -125,7 +124,7 @@ public override string ServerVersion throw new NotImplementedException(); } } - public string ClientVersion + public string ClientVersion { get { @@ -177,7 +176,7 @@ public override void Open() { OpenAsync().GetAwaiter().GetResult(); } - public override async Task OpenAsync(CancellationToken cancellationToken=default) + public override async Task OpenAsync(CancellationToken cancellationToken = default) { if (State == ConnectionState.Open) @@ -190,7 +189,7 @@ public override async Task OpenAsync(CancellationToken cancellationToken=def } await _IoTDB.Open(ConnectionStringBuilder.Compression, cancellationToken); - if (!_IoTDB.IsOpen()) + if (!_IoTDB.IsOpen()) { IoTDBException.ThrowExceptionForRC(-1, "Can't open IoTDB server."); } @@ -214,7 +213,7 @@ public override async Task CloseAsync() #endif { if (State != ConnectionState.Closed) - await _IoTDB.Close(); + await _IoTDB.Close(); Transaction?.Dispose(); _nowdatabase = string.Empty; foreach (var reference in _commands) @@ -343,9 +342,9 @@ protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLeve } internal string _nowdatabase = string.Empty; - internal bool SelectedDataBase => _nowdatabase != string.Empty ; + internal bool SelectedDataBase => _nowdatabase != string.Empty; - public override string Database => throw new NotSupportedException(); + public override string Database => throw new NotSupportedException(); /// /// Changes the current database. diff --git a/src/Apache.IoTDB.Data/IoTDBConnectionStringBuilder.cs b/src/Apache.IoTDB.Data/IoTDBConnectionStringBuilder.cs index 8c71b5e..c2cac87 100644 --- a/src/Apache.IoTDB.Data/IoTDBConnectionStringBuilder.cs +++ b/src/Apache.IoTDB.Data/IoTDBConnectionStringBuilder.cs @@ -65,24 +65,24 @@ private enum Keywords private string _userName = "root"; private string _password = "root"; private bool _enableRpcCompression = false; - private int _fetchSize = 1800; + private int _fetchSize = 1800; private string _zoneId = "UTC+08:00"; - private int _port = 6667; - private int _poolSize =8; - private int _timeOut=10000; + private int _port = 6667; + private int _poolSize = 8; + private int _timeOut = 10000; static IoTDBConnectionStringBuilder() { var validKeywords = new string[9]; validKeywords[(int)Keywords.DataSource] = DataSourceKeyword; - validKeywords[(int)Keywords.Username] = UserNameKeyword; + validKeywords[(int)Keywords.Username] = UserNameKeyword; validKeywords[(int)Keywords.Password] = PasswordKeyword; validKeywords[(int)Keywords.Port] = PortKeyword; validKeywords[(int)Keywords.FetchSize] = FetchSizeKeyword; validKeywords[(int)Keywords.Compression] = CompressionKeyword; validKeywords[(int)Keywords.PoolSize] = PoolSizeKeyword; validKeywords[(int)Keywords.ZoneId] = ZoneIdKeyword; - validKeywords[(int)Keywords.TimeOut] =TimeOutKeyword; + validKeywords[(int)Keywords.TimeOut] = TimeOutKeyword; _validKeywords = validKeywords; _keywords = new Dictionary(9, StringComparer.OrdinalIgnoreCase) @@ -129,13 +129,13 @@ public virtual string Username get => _userName; set => base[UserNameKeyword] = _userName = value; } - + public virtual string Password { get => _password; set => base[PasswordKeyword] = _password = value; } - public virtual int Port + public virtual int Port { get => _port; set => base[PortKeyword] = _port = value; @@ -163,7 +163,7 @@ public virtual string ZoneId } public virtual int TimeOut - { + { get => _timeOut; set => base[PoolSizeKeyword] = _timeOut = value; } @@ -215,19 +215,19 @@ public override object this[string keyword] return; } - + switch (GetIndex(keyword)) { case Keywords.DataSource: DataSource = Convert.ToString(value, CultureInfo.InvariantCulture); return; case Keywords.Username: - Username= Convert.ToString(value, CultureInfo.InvariantCulture); + Username = Convert.ToString(value, CultureInfo.InvariantCulture); return; case Keywords.Password: Password = Convert.ToString(value, CultureInfo.InvariantCulture); return; - + case Keywords.Port: Port = Convert.ToInt32(value, CultureInfo.InvariantCulture); return; @@ -354,7 +354,7 @@ public override bool TryGetValue(string keyword, out object value) private object GetAt(Keywords index) { - + switch (index) { case Keywords.DataSource: @@ -363,7 +363,7 @@ private object GetAt(Keywords index) return Password; case Keywords.Username: return Username; - + case Keywords.Port: return Port; case Keywords.FetchSize: @@ -401,7 +401,7 @@ private void Reset(Keywords index) _userName = "root"; return; case Keywords.Port: - _port=6667; + _port = 6667; return; case Keywords.FetchSize: _fetchSize = 1800; diff --git a/src/Apache.IoTDB.Data/IoTDBDataReader.cs b/src/Apache.IoTDB.Data/IoTDBDataReader.cs index 88c4de2..156844e 100644 --- a/src/Apache.IoTDB.Data/IoTDBDataReader.cs +++ b/src/Apache.IoTDB.Data/IoTDBDataReader.cs @@ -17,7 +17,6 @@ * under the License. */ -using Apache.IoTDB.DataStructure; using System; using System.Collections; using System.Collections.Generic; @@ -27,6 +26,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; +using Apache.IoTDB.DataStructure; namespace Apache.IoTDB.Data @@ -41,12 +41,12 @@ public class IoTDBDataReader : DbDataReader private bool _hasRows; private readonly int _recordsAffected; private bool _closed; - private readonly List _metas; + private readonly List _metas; private bool _closeConnection; private int _fieldCount; - RowRecord rowdata= null; + RowRecord rowdata = null; SessionDataSet _dataSet; @@ -57,7 +57,7 @@ internal IoTDBDataReader(IoTDBCommand IoTDBCommand, SessionDataSet dataSet, bool _closeConnection = closeConnection; _fieldCount = dataSet.ColumnNames.Count; _hasRows = dataSet.RowCount > 0; - _recordsAffected =dataSet.RowCount; + _recordsAffected = dataSet.RowCount; _closed = _closeConnection; _metas = dataSet.ColumnNames; _dataSet = dataSet; @@ -73,7 +73,7 @@ internal IoTDBDataReader(IoTDBCommand IoTDBCommand, SessionDataSet dataSet, bool /// Gets the number of columns in the current row. /// /// The number of columns in the current row. - public override int FieldCount => _fieldCount+1; + public override int FieldCount => _fieldCount + 1; /// /// Gets a value indicating whether the data reader contains any rows. @@ -178,7 +178,7 @@ protected override void Dispose(bool disposing) _dataSet.Close().GetAwaiter().GetResult(); _command.DataReader = null; - if (_closeConnection ) + if (_closeConnection) { _command.Connection.Close(); _closed = true; @@ -194,7 +194,7 @@ protected override void Dispose(bool disposing) /// The name of the column. public override string GetName(int ordinal) { - return ordinal==0? "timestamp" : rowdata.Measurements[ordinal-1]; + return ordinal == 0 ? "timestamp" : rowdata.Measurements[ordinal - 1]; } /// @@ -203,7 +203,7 @@ public override string GetName(int ordinal) /// The name of the column. /// The zero-based column ordinal. public override int GetOrdinal(string name) - => "timestamp"==name?0: rowdata.Measurements.IndexOf( name)+1; + => "timestamp" == name ? 0 : rowdata.Measurements.IndexOf(name) + 1; public override string GetDataTypeName(int ordinal) { @@ -218,7 +218,7 @@ public override string GetDataTypeName(int ordinal) public override Type GetFieldType(int ordinal) { - return ordinal==0?typeof(DateTime): rowdata.GetCrlType(ordinal-1); + return ordinal == 0 ? typeof(DateTime) : rowdata.GetCrlType(ordinal - 1); } /// @@ -438,9 +438,9 @@ public override int GetValues(object[] values) for (int i = 0; i < _fieldCount; i++) { var obj = rowdata.Values[i]; - if (obj != null ) + if (obj != null) { - values[i+1] = obj; + values[i + 1] = obj; count++; } } @@ -458,8 +458,8 @@ public override DataTable GetSchemaTable() { rowdata = _dataSet.GetRow(); } - var schemaTable = new DataTable("SchemaTable"); - if (_metas != null && rowdata !=null) + var schemaTable = new DataTable("SchemaTable"); + if (_metas != null && rowdata != null) { var ColumnName = new DataColumn(SchemaTableColumn.ColumnName, typeof(string)); var ColumnOrdinal = new DataColumn(SchemaTableColumn.ColumnOrdinal, typeof(int)); @@ -525,7 +525,7 @@ public override DataTable GetSchemaTable() var tableName1 = string.Empty; schemaRow1[BaseTableName] = tableName1; schemaRow1[DataType] = typeof(DateTime); - schemaRow1[DataTypeName] = typeof(DateTime).Name; + schemaRow1[DataTypeName] = nameof(DateTime); schemaRow1[IsExpression] = columnName1 == null; schemaRow1[IsLong] = DBNull.Value; schemaRow1[IsKey] = true; @@ -534,11 +534,11 @@ public override DataTable GetSchemaTable() schemaTable.Rows.Add(schemaRow1); - for (var i = 1; i < rowdata.Measurements.Count+1; i++) + for (var i = 1; i < rowdata.Measurements.Count + 1; i++) { var schemaRow = schemaTable.NewRow(); - var columnName = rowdata.Measurements[i-1] ; + var columnName = rowdata.Measurements[i - 1]; schemaRow[ColumnName] = columnName; schemaRow[ColumnOrdinal] = i; @@ -554,7 +554,7 @@ public override DataTable GetSchemaTable() schemaRow[DataTypeName] = GetDataTypeName(i); schemaRow[IsExpression] = columnName == null; schemaRow[IsLong] = DBNull.Value; - schemaRow[IsKey]= false; + schemaRow[IsKey] = false; schemaRow[AllowDBNull] = true; schemaTable.Rows.Add(schemaRow); } diff --git a/src/Apache.IoTDB.Data/IoTDBException.cs b/src/Apache.IoTDB.Data/IoTDBException.cs index 978c9e8..8fc645a 100644 --- a/src/Apache.IoTDB.Data/IoTDBException.cs +++ b/src/Apache.IoTDB.Data/IoTDBException.cs @@ -47,7 +47,7 @@ public IoTDBException(IoTDBErrorResult IoTDBError, Exception ex) : base(IoTDBErr public override string Message => _IoTDBError?.Error; - public override int ErrorCode => (int) _IoTDBError?.Code; + public override int ErrorCode => (int)_IoTDBError?.Code; /// /// Throws an exception with a specific IoTDB error code value. /// @@ -62,14 +62,14 @@ public static void ThrowExceptionForRC(string _commandText, IoTDBErrorResult IoT te.Data.Add("commandText", _commandText); throw te; } - public static void ThrowExceptionForRC( IoTDBErrorResult IoTDBError) + public static void ThrowExceptionForRC(IoTDBErrorResult IoTDBError) { var te = new IoTDBException(IoTDBError); throw te; } public static void ThrowExceptionForRC(IntPtr _IoTDB) { - var te = new IoTDBException(new IoTDBErrorResult() { }); + var te = new IoTDBException(new IoTDBErrorResult() { }); throw te; } public static void ThrowExceptionForRC(int code, string message, Exception ex) diff --git a/src/Apache.IoTDB.Data/IoTDBParameter.cs b/src/Apache.IoTDB.Data/IoTDBParameter.cs index 03b7667..f49ea99 100644 --- a/src/Apache.IoTDB.Data/IoTDBParameter.cs +++ b/src/Apache.IoTDB.Data/IoTDBParameter.cs @@ -17,7 +17,7 @@ * under the License. */ - using System; +using System; using System.Data; using System.Data.Common; @@ -42,7 +42,7 @@ public class IoTDBParameter : DbParameter public IoTDBParameter() { } - + /// /// Initializes a new instance of the class. /// @@ -101,7 +101,7 @@ public IoTDBParameter(string name, TSDataType type, int size, string sourceColum /// /// The type of the parameter. /// Due to IoTDB's dynamic type system, parameter values are not converted. - + public override DbType DbType { get; set; } = DbType.String; /// @@ -221,6 +221,6 @@ public virtual void ResetIoTDBType() IoTDBType = TSDataType.NONE; } - + } } diff --git a/src/Apache.IoTDB.Data/IoTDBParameterCollection.cs b/src/Apache.IoTDB.Data/IoTDBParameterCollection.cs index 201448d..830e1e6 100644 --- a/src/Apache.IoTDB.Data/IoTDBParameterCollection.cs +++ b/src/Apache.IoTDB.Data/IoTDBParameterCollection.cs @@ -183,7 +183,7 @@ public virtual IoTDBParameter AddWithValue(string parameterName, object value) /// The name of the parameter. /// The value of the parameter. Can be null. /// The parameter that was added. - public virtual IoTDBParameter AddWithValue( object value) + public virtual IoTDBParameter AddWithValue(object value) { var parameter = new IoTDBParameter(Guid.NewGuid().ToString(), value); Add(parameter); @@ -354,7 +354,7 @@ protected override void SetParameter(int index, DbParameter value) protected override void SetParameter(string parameterName, DbParameter value) => SetParameter(IndexOfChecked(parameterName), value); - + private int IndexOfChecked(string parameterName) { diff --git a/src/Apache.IoTDB.Data/IoTDBResult.cs b/src/Apache.IoTDB.Data/IoTDBResult.cs index 1da73f2..fae9066 100644 --- a/src/Apache.IoTDB.Data/IoTDBResult.cs +++ b/src/Apache.IoTDB.Data/IoTDBResult.cs @@ -26,10 +26,10 @@ namespace Apache.IoTDB.Data public class IoTDBErrorResult { - public int Code { get; set; } + public int Code { get; set; } /// /// /// - public string Error { get; set; } + public string Error { get; set; } } } diff --git a/src/Apache.IoTDB.Data/IoTDBTransaction.cs b/src/Apache.IoTDB.Data/IoTDBTransaction.cs index a0a4c79..34fc547 100644 --- a/src/Apache.IoTDB.Data/IoTDBTransaction.cs +++ b/src/Apache.IoTDB.Data/IoTDBTransaction.cs @@ -62,7 +62,7 @@ internal bool ExternalRollback /// /// The isolation level for the transaction. public override IsolationLevel IsolationLevel => IsolationLevel.Unspecified; - + /// /// Applies the changes made in the transaction. @@ -73,7 +73,7 @@ public override void Commit() //{ // throw new InvalidOperationException(Resources.TransactionCompleted); //} - + //_connection.ExecuteNonQuery("COMMIT;"); Complete(); } @@ -109,7 +109,7 @@ protected override void Dispose(bool disposing) private void Complete() { - if (_connection!=null)_connection.Transaction = null; + if (_connection != null) _connection.Transaction = null; _connection = null; _completed = true; } diff --git a/src/Apache.IoTDB/Client.cs b/src/Apache.IoTDB/Client.cs index dead7b6..03238d2 100644 --- a/src/Apache.IoTDB/Client.cs +++ b/src/Apache.IoTDB/Client.cs @@ -38,4 +38,4 @@ public Client(IClientRPCService.Client client, long sessionId, long statementId, EndPoint = endpoint; } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/ConcurrentClientQueue.cs b/src/Apache.IoTDB/ConcurrentClientQueue.cs index 0c54a12..e53d3f3 100644 --- a/src/Apache.IoTDB/ConcurrentClientQueue.cs +++ b/src/Apache.IoTDB/ConcurrentClientQueue.cs @@ -71,7 +71,8 @@ public Client Take() { Client client = null; Monitor.Enter(ClientQueue); - while(true){ + while (true) + { bool timeout = false; if (ClientQueue.IsEmpty) { @@ -79,7 +80,8 @@ public Client Take() } ClientQueue.TryDequeue(out client); - if(client != null || timeout){ + if (client != null || timeout) + { break; } } @@ -91,4 +93,4 @@ public Client Take() return client; } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/DataStructure/BitMap.cs b/src/Apache.IoTDB/DataStructure/BitMap.cs index d5a66c6..75b2d58 100644 --- a/src/Apache.IoTDB/DataStructure/BitMap.cs +++ b/src/Apache.IoTDB/DataStructure/BitMap.cs @@ -23,7 +23,7 @@ #endif public class BitMap { - private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, 255 }; + private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, unchecked((byte)-128) }; private static byte[] UNMARK_BIT_UTIL = new byte[] { (byte) 0XFE, // 11111110 @@ -94,7 +94,7 @@ public void mark(int position) public void reset() { #if NET461_OR_GREATER || NETSTANDARD2_0 - bits.Fill((byte)0xFF); + bits.Fill((byte)0); #else Array.Fill(bits, (byte)0); #endif @@ -146,4 +146,4 @@ public bool isAllMarked() } return true; } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/DataStructure/ByteBuffer.cs b/src/Apache.IoTDB/DataStructure/ByteBuffer.cs index b97583f..a3e1823 100644 --- a/src/Apache.IoTDB/DataStructure/ByteBuffer.cs +++ b/src/Apache.IoTDB/DataStructure/ByteBuffer.cs @@ -135,10 +135,10 @@ public string GetStr() public byte[] GetBinary() { - var length = GetInt(); - var buff = _buffer[_readPos..(_readPos + length)]; - _readPos += length; - return buff; + var length = GetInt(); + var buff = _buffer[_readPos..(_readPos + length)]; + _readPos += length; + return buff; } public byte[] GetBuffer() @@ -225,7 +225,7 @@ public void AddStr(string value) _writePos += strBuf.Length; } - public void AddBinary(byte[] value) + public void AddBinary(byte[] value) { AddInt(value.Length); @@ -251,4 +251,4 @@ public void AddByte(byte value) _writePos += 1; } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/DataStructure/RowRecord.cs b/src/Apache.IoTDB/DataStructure/RowRecord.cs index 9674f49..c5853bf 100644 --- a/src/Apache.IoTDB/DataStructure/RowRecord.cs +++ b/src/Apache.IoTDB/DataStructure/RowRecord.cs @@ -32,18 +32,18 @@ public class RowRecord public List DataTypes { get; } public RowRecord(DateTime timestamp, List values, List measurements, List dataTypes) - :this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values,measurements, dataTypes) + : this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values, measurements, dataTypes) { } public RowRecord(DateTime timestamp, List values, List measurements, List dataTypes) - :this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values,measurements, dataTypes) + : this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values, measurements, dataTypes) { } [Obsolete("Use the constructor with List instead")] public RowRecord(DateTime timestamp, List values, List measurements) - :this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values,measurements) + : this(new DateTimeOffset(timestamp.ToUniversalTime()).ToUnixTimeMilliseconds(), values, measurements) { } [Obsolete("Use the constructor with List instead")] @@ -53,7 +53,8 @@ public RowRecord(long timestamps, List values, List measurements Values = values; Measurements = measurements; } - public RowRecord(long timestamps, List values, List measurements, List dataTypes){ + public RowRecord(long timestamps, List values, List measurements, List dataTypes) + { Timestamps = timestamps; Values = values; Measurements = measurements; @@ -132,27 +133,27 @@ public override string ToString() foreach (var rowValue in Values) { str += "\t\t"; - if(rowValue is byte[] bytes) + if (rowValue is byte[] bytes) { - str += Utils.ByteArrayToHexString(bytes); + str += Utils.ByteArrayToHexString(bytes); } else { - str += rowValue.ToString(); + str += rowValue.ToString(); } } return str; } - + public Type GetCrlType(int index) { - Type tSDataType = typeof(object); + Type tSDataType = typeof(object); var valueType = Values[index]; switch (valueType) { case bool _: - tSDataType = typeof( bool); + tSDataType = typeof(bool); break; case int _: tSDataType = typeof(int); @@ -190,43 +191,43 @@ public byte[] ToBytes() switch (dataType) { case TSDataType.BOOLEAN: - buffer.AddByte((byte) TSDataType.BOOLEAN); + buffer.AddByte((byte)TSDataType.BOOLEAN); buffer.AddBool((bool)value); break; case TSDataType.INT32: - buffer.AddByte((byte) TSDataType.INT32); + buffer.AddByte((byte)TSDataType.INT32); buffer.AddInt((int)value); break; case TSDataType.INT64: - buffer.AddByte((byte) TSDataType.INT64); + buffer.AddByte((byte)TSDataType.INT64); buffer.AddLong((long)value); break; case TSDataType.FLOAT: - buffer.AddByte((byte) TSDataType.FLOAT); + buffer.AddByte((byte)TSDataType.FLOAT); buffer.AddFloat((float)value); break; case TSDataType.DOUBLE: - buffer.AddByte((byte) TSDataType.DOUBLE); + buffer.AddByte((byte)TSDataType.DOUBLE); buffer.AddDouble((double)value); break; case TSDataType.TEXT: - buffer.AddByte((byte) TSDataType.TEXT); + buffer.AddByte((byte)TSDataType.TEXT); buffer.AddStr((string)value); break; case TSDataType.TIMESTAMP: - buffer.AddByte((byte) TSDataType.TIMESTAMP); + buffer.AddByte((byte)TSDataType.TIMESTAMP); buffer.AddLong((long)value); break; case TSDataType.BLOB: - buffer.AddByte((byte) TSDataType.BLOB); + buffer.AddByte((byte)TSDataType.BLOB); buffer.AddBinary((byte[])value); break; case TSDataType.DATE: - buffer.AddByte((byte) TSDataType.DATE); + buffer.AddByte((byte)TSDataType.DATE); buffer.AddInt(Utils.ParseDateToInt((DateTime)value)); break; case TSDataType.STRING: - buffer.AddByte((byte) TSDataType.STRING); + buffer.AddByte((byte)TSDataType.STRING); buffer.AddStr((string)value); break; default: @@ -262,4 +263,4 @@ private TSDataType GetTSDataType(object value) } } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/DataStructure/SessionDataSet.cs b/src/Apache.IoTDB/DataStructure/SessionDataSet.cs index 7ba49ea..539de1f 100644 --- a/src/Apache.IoTDB/DataStructure/SessionDataSet.cs +++ b/src/Apache.IoTDB/DataStructure/SessionDataSet.cs @@ -81,18 +81,25 @@ public SessionDataSet(string sql, TSExecuteStatementResp resp, Client client, Co int deduplicateIdx = 0; Dictionary columnToFirstIndexMap = new Dictionary(); - for(var i = 0; i < _columnSize; i++){ + for (var i = 0; i < _columnSize; i++) + { var columnName = _columnNames[i]; - if(_columnNameIndexMap.ContainsKey(columnName)){ + if (_columnNameIndexMap.ContainsKey(columnName)) + { _duplicateLocation[i] = columnToFirstIndexMap[columnName]; - } else { + } + else + { columnToFirstIndexMap[columnName] = i; - if(resp.ColumnNameIndexMap != null) { + if (resp.ColumnNameIndexMap != null) + { int valueIndex = resp.ColumnNameIndexMap[columnName]; _columnNameIndexMap[columnName] = valueIndex; _valueBufferLst.Add(new ByteBuffer(_queryDataset.ValueList[valueIndex])); _bitmapBufferLst.Add(new ByteBuffer(_queryDataset.BitmapList[valueIndex])); - } else { + } + else + { _columnNameIndexMap[columnName] = deduplicateIdx; _valueBufferLst.Add(new ByteBuffer(_queryDataset.ValueList[deduplicateIdx])); _bitmapBufferLst.Add(new ByteBuffer(_queryDataset.BitmapList[deduplicateIdx])); @@ -213,7 +220,7 @@ private void ConstructOneRow() localField = columnValueBuffer.GetBool(); break; case TSDataType.INT32: - // case TSDataType.DATE: + // case TSDataType.DATE: localField = columnValueBuffer.GetInt(); break; case TSDataType.DATE: @@ -231,7 +238,7 @@ private void ConstructOneRow() break; case TSDataType.TEXT: case TSDataType.STRING: - // case TSDataType.BLOB: + // case TSDataType.BLOB: localField = columnValueBuffer.GetStr(); break; case TSDataType.BLOB: @@ -359,4 +366,4 @@ public void Dispose() GC.SuppressFinalize(this); } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/DataStructure/Tablet.cs b/src/Apache.IoTDB/DataStructure/Tablet.cs index 3a19a94..2d979c6 100644 --- a/src/Apache.IoTDB/DataStructure/Tablet.cs +++ b/src/Apache.IoTDB/DataStructure/Tablet.cs @@ -44,6 +44,8 @@ namespace Apache.IoTDB.DataStructure */ public class Tablet { + + private static int EMPTY_DATE_INT = 10000101; private readonly List _timestamps; private readonly List> _values; @@ -295,85 +297,85 @@ public byte[] GetBinaryValues() switch (dataType) { case TSDataType.BOOLEAN: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddBool(value != null ? (bool)value : false); - } - - break; + var value = _values[j][i]; + buffer.AddBool(value != null ? (bool)value : false); } + + break; + } case TSDataType.INT32: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddInt(value != null ? (int)value : int.MinValue); - } - - break; + var value = _values[j][i]; + buffer.AddInt(value != null ? (int)value : int.MinValue); } + + break; + } case TSDataType.INT64: case TSDataType.TIMESTAMP: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddLong(value != null ? (long)value : long.MinValue); - } - - break; + var value = _values[j][i]; + buffer.AddLong(value != null ? (long)value : long.MinValue); } + + break; + } case TSDataType.FLOAT: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddFloat(value != null ? (float)value : float.MinValue); - } - - break; + var value = _values[j][i]; + buffer.AddFloat(value != null ? (float)value : float.MinValue); } + + break; + } case TSDataType.DOUBLE: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddDouble(value != null ? (double)value : double.MinValue); - } - - break; + var value = _values[j][i]; + buffer.AddDouble(value != null ? (double)value : double.MinValue); } + + break; + } case TSDataType.TEXT: case TSDataType.STRING: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddStr(value != null ? (string)value : string.Empty); - } - - break; + var value = _values[j][i]; + buffer.AddStr(value != null ? (string)value : string.Empty); } + + break; + } case TSDataType.DATE: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : int.MinValue); - } - break; + var value = _values[j][i]; + buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : EMPTY_DATE_INT); } + break; + } case TSDataType.BLOB: + { + for (int j = 0; j < RowNumber; j++) { - for (int j = 0; j < RowNumber; j++) - { - var value = _values[j][i]; - buffer.AddBinary(value != null ? (byte[])value : new byte[] { }); - } - break; + var value = _values[j][i]; + buffer.AddBinary(value != null ? (byte[])value : new byte[] { }); } + break; + } default: throw new Exception($"Unsupported data type {dataType}", null); } @@ -398,4 +400,4 @@ public byte[] GetBinaryValues() return buffer.GetBuffer(); } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/IoTDBConstants.cs b/src/Apache.IoTDB/IoTDBConstants.cs index 5faac76..0e53123 100644 --- a/src/Apache.IoTDB/IoTDBConstants.cs +++ b/src/Apache.IoTDB/IoTDBConstants.cs @@ -90,4 +90,4 @@ public class TsFileConstant private TsFileConstant() { } } -} \ No newline at end of file +} diff --git a/src/Apache.IoTDB/SessionPool.Builder.cs b/src/Apache.IoTDB/SessionPool.Builder.cs new file mode 100644 index 0000000..39c11b4 --- /dev/null +++ b/src/Apache.IoTDB/SessionPool.Builder.cs @@ -0,0 +1,123 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; + +namespace Apache.IoTDB; + +public partial class SessionPool +{ + public class Builder + { + private string _host = "localhost"; + private int _port = 6667; + private string _username = "root"; + private string _password = "root"; + private int _fetchSize = 1024; + private string _zoneId = "UTC+08:00"; + private int _poolSize = 8; + private bool _enableRpcCompression = false; + private int _connectionTimeoutInMs = 500; + private List _nodeUrls = new List(); + + public Builder SetHost(string host) + { + _host = host; + return this; + } + + public Builder SetPort(int port) + { + _port = port; + return this; + } + + public Builder SetUsername(string username) + { + _username = username; + return this; + } + + public Builder SetPassword(string password) + { + _password = password; + return this; + } + + public Builder SetFetchSize(int fetchSize) + { + _fetchSize = fetchSize; + return this; + } + + public Builder SetZoneId(string zoneId) + { + _zoneId = zoneId; + return this; + } + + public Builder SetPoolSize(int poolSize) + { + _poolSize = poolSize; + return this; + } + + public Builder SetEnableRpcCompression(bool enableRpcCompression) + { + _enableRpcCompression = enableRpcCompression; + return this; + } + + public Builder SetConnectionTimeoutInMs(int timeout) + { + _connectionTimeoutInMs = timeout; + return this; + } + + public Builder SetNodeUrl(List nodeUrls) + { + _nodeUrls = nodeUrls; + return this; + } + + public Builder() + { + _host = "localhost"; + _port = 6667; + _username = "root"; + _password = "root"; + _fetchSize = 1024; + _zoneId = "UTC+08:00"; + _poolSize = 8; + _enableRpcCompression = false; + _connectionTimeoutInMs = 500; + } + + public SessionPool Build() + { + // if nodeUrls is not empty, use nodeUrls to create session pool + if (_nodeUrls.Count > 0) + { + return new SessionPool(_nodeUrls, _username, _password, _fetchSize, _zoneId, _poolSize, _enableRpcCompression, _connectionTimeoutInMs); + } + return new SessionPool(_host, _port, _username, _password, _fetchSize, _zoneId, _poolSize, _enableRpcCompression, _connectionTimeoutInMs); + } + } +} diff --git a/src/Apache.IoTDB/SessionPool.cs b/src/Apache.IoTDB/SessionPool.cs index f5337e4..3cb3e08 100644 --- a/src/Apache.IoTDB/SessionPool.cs +++ b/src/Apache.IoTDB/SessionPool.cs @@ -35,7 +35,7 @@ namespace Apache.IoTDB { - public class SessionPool : IDisposable + public partial class SessionPool : IDisposable { private static readonly TSProtocolVersion ProtocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3; @@ -141,10 +141,12 @@ public async Task ExecuteClientOperationAsync(AsyncOperation ExecuteClientOperationAsync(AsyncOperation ExecuteClientOperationAsync(AsyncOperation