Apache Ignite v2.7:无法更改列数据类型-错误或预期行为?

时间:2019-04-08 17:57:12

标签: odbc ignite

通过ODBC连接运行一组SQL语句会更改列的数据类型时,出现错误。

错误:

[HY000]设置了错误的值[typeName = SQL_PUBLIC_X_0aae5780_0c94_4706_b144_f2ca2336a96e,fieldName = VALUE,fieldType = String,assignedValueType = int]

是预期的行为还是预期的错误?在将来的发行版中,此行为是否会更改以支持更改列的数据类型?

我正在使用通过OdbcConnection(System.Data.Odbc v4.5.0)从.Net Core(v2.2)连接的新的默认Ignite(v2.7)实例。

堆栈跟踪:

System.Data.Odbc.OdbcException (0x80131937): ERROR [HY000] Wrong value has been set [typeName=SQL_PUBLIC_X_0aae5780_0c94_4706_b144_f2ca2336a96e, fieldName=VALUE, fieldType=String, assignedValueType=int]
   at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
   at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
   at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
   at IgniteReproducer.Program.ChangeColumnType() in C:\...\IgniteMultistatementReproducer\IgniteMultistatementReproducer\Program.cs:line 51

复制者:

using System;
using System.Data.Odbc;

namespace IgniteReproducer {
    internal class Program {
        private static void Main(string[] args) {
            ChangeColumnType();
        }

        private static void ChangeColumnType() {
            try {
                using (var conn = new OdbcConnection($"DRIVER={{Apache Ignite}};ADDRESS=localhost:10800;")) {
                    conn.Open();
                    var cmd = new OdbcCommand {
                        Connection = conn
                    };

                    cmd.CommandText = "DROP TABLE IF EXISTS X;";
                    var numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "CREATE TABLE X (Id INT, Value VARCHAR(36), PRIMARY KEY (Id));";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "INSERT INTO X (Id, Value) VALUES (1, 'a');";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "INSERT INTO X (Id, Value) VALUES (2, 'b');";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "ALTER TABLE X ADD COLUMN Temp INT;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "UPDATE X SET Temp = 1;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "ALTER TABLE X DROP COLUMN Value;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "ALTER TABLE X ADD COLUMN Value INT;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "UPDATE X SET Value = Temp;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");

                    cmd.CommandText = "ALTER TABLE X DROP COLUMN Temp;";
                    numRecordsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine($"Num Records Affected: {numRecordsAffected}");
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

here表示,删除列时实际上并没有从集群中删除该列。

  

该命令不会从集群中删除实际数据,这意味着如果删除了“名称”列,则“名称”的值仍将存储在集群中。此限制将在以后的版本中解决。

这应该是错误的原因。 varchar数据仍然存在。

从此报价看来,这将在以后的版本中得到解决。