Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql同步出错 #8

Closed
Lor23C opened this issue Jul 13, 2021 · 2 comments
Closed

mysql同步出错 #8

Lor23C opened this issue Jul 13, 2021 · 2 comments

Comments

@Lor23C
Copy link

Lor23C commented Jul 13, 2021

-- mysql表
CREATE TABLE clickhousetest(
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
verificatTaskUuid varchar(50) NOT NULL COMMENT 'uuid',
checkDuration int(11) DEFAULT NULL,
PRIMARY KEY (id)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT charset=utf8mb4;

使用命令
chm --src mysql --src-host 192.168.1.2 --src-port 3306 --src-user root --src-password 12d@s --src-database test --src-table clickhousetest --drop-table true --host 192.168.1.1 --port 9000 --user default --password 22sWd --database test

出错信息:

WARN: DROP TABLE IF EXISTS test.clickhousetest;
Progress: 7 rows (1 rows/s.)ERROR: System.InvalidCastException: Unable to cast object of type 'System.UInt64' to type 'System.Int64'.
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()
at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at ClickHouse.Ado.Impl.ColumnTypes.SimpleColumnType`1.ValuesFromConst(IEnumerable objects)
at ClickHouse.Ado.ClickHouseCommand.Execute(Boolean readResponse, ClickHouseConnection connection)
at ClickHouse.Ado.ClickHouseCommand.ExecuteNonQuery()
at ClickHouseMigrator.Migrator.<>c__DisplayClass14_0.b__2() in C:\Users\Administrator\source\repos\ClickHouseMigrator-master\src\ClickHouseMigrator
Migrator.cs:line 166

Elapsed 5 sec. Processed 7 rows (1 rows/s.)

@Lor23C
Copy link
Author

Lor23C commented Jul 13, 2021

找到原因了,同步出错,是因为mysql 主键 id bigint(20) unsigned 没有适配到clickhouse对应数据类型
我改了一下
protected override string ConvertToClickHouseDataType(string type)
{

		var sizePrefixIndex = type.IndexOf('(');
		var normalTypeName = Regex.Replace(type, @"[0-9()]+", "");//sizePrefixIndex <= 0 ? type : type.Substring(0, sizePrefixIndex);
		switch (normalTypeName)
		{
			case "tinyint unsigned":
		    {
				return "UInt8";
		    }
			case "smallint unsigned":
			{
				return "UInt16";
			}
			case "int unsigned": 
		    {
				return "UInt32";
		    }
			case "mediumint unsigned":
		    {
				return "UInt32";
		    }
			case "datetime": 
		    {
				return "DateTime";
			}
			case "timestamp":
			{
				return "DateTime";
			}
			case "date":
			{
				return "Date";
			}
			case "tinyint":
			{
				return "UInt8";
			}
			case "smallint":
			{
				return "Int16";
			}
			case "int":
			{
				return "Int32";
			}
			case "mediumint":
		    {
				return "Int32";
		    }
			case "bigint unsigned":
		    {
				return "UInt64";
			}
			case "float":
			{
				return "Float32";
			}
			case "double":
			{
				return "Float64";
			}
			case "decimal":
			{
				return "Float64";
			}
			case "bigint":
			{
				return "Int64";
			}
			default:
			{
				return "String";
			}
		}
	}

就可以了

@zlzforever
Copy link
Owner

修复提交了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants