WO2016173428A1 - 一种数据传输方法及装置 - Google Patents
一种数据传输方法及装置 Download PDFInfo
- Publication number
- WO2016173428A1 WO2016173428A1 PCT/CN2016/079649 CN2016079649W WO2016173428A1 WO 2016173428 A1 WO2016173428 A1 WO 2016173428A1 CN 2016079649 W CN2016079649 W CN 2016079649W WO 2016173428 A1 WO2016173428 A1 WO 2016173428A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- data
- data type
- converted
- type
- abstract
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
- G06F16/258—Data format conversion from or to a database
Definitions
- the invention belongs to the field of database technology, and in particular relates to a data transmission method and device between heterogeneous data systems.
- big data In the current era of big data, more and more companies and companies are gradually realizing that the acquisition, analysis and mining of big data can provide valuable reference models for later business decisions, market forecasts, and company development.
- the value that big data can play is based on the large amount of data, the large data entry, and the large scale of data collection. It can provide sufficient data basis for enterprise development services.
- the primary problem that big data needs to solve is to concentrate a large number of users and system-generated data, and only large data can generate big data.
- the massive amounts of data generated by various online business systems (user centers, commodity centers, and transaction centers) are stored in various heterogeneous data systems.
- Data synchronization requires the transmission of data generated by various data sources. Synchronize and aggregate into a unified big data storage/computing system (such as Hadoop, or the ODPS of the Ali Group).
- data synchronization will directly face various types of data types, different access interfaces, different transaction models, different flow control models, and other issues.
- data synchronization will face a geometrical data transmission channel, which will cause huge development, operation and maintenance, and technical support costs for the later data synchronization capability expansion.
- Sqoop is a tool based on the Hadoop MapReduce running framework provided by the Hadoop open source community to synchronize data between Hadoop and RDBMS.
- Sqoop only faces the interaction of Hadoop/HDFS and RDBMS storage systems.
- the simplest CSV text is used as the transport exchange protocol. Take Mysql to transfer data to HDFS as an example:
- Sqoop starts the MapReduce job on Hadoop.
- the Job actually runs the Sqoop data transfer task.
- Sqoop starts the data channel in the MapReduce Map stage, extracts Mysql data and converts it to CSV format as the intermediate format.
- Sqoop writes the above CSV format data directly into the Hadoop/HDFS file system.
- this method only supports the number of Hadoop and RDBMS. According to synchronization, the following technical problems exist:
- the data type conversion behavior is undefined.
- the conversion method of each data source is used.
- the conversion behavior changes with the data system, even with the data system. Changes in specific versions have caused data system upgrades to cause data synchronization data changes that induce data quality problems.
- the object of the present invention is to provide a data transmission method and apparatus, which solves the prior art and only supports data transmission between specific data systems, and has technical problems such as data distortion and data type loss.
- a data transmission method for transmitting data between a source data system and a destination data system comprising the steps of:
- the current field that has been mapped to the abstract data type is read, and the current field that has been mapped to the abstract data type is mapped to the data type corresponding to the destination data system according to the correspondence between the preset abstract data type and the destination data system data type.
- the preset abstract data types include Long, Double, String, Date, Bool, and Bytes, corresponding to different source data systems and destination data systems, respectively pre-mapped with abstract data types and data types of the source data system.
- mapping the current field to the preset abstract data type according to the data type of the current field and the correspondence between the preset abstract data type and the data type of the source data system includes the following steps:
- the current field that has been mapped to the abstract data type is mapped to the data type corresponding to the destination data system, including the steps:
- the Long of the present invention supports an infinite length
- the Double supports infinite precision
- the String supports an infinite character length
- the data transmission method further includes the steps of:
- the abstract data type corresponding to the current field is converted into abstract data directly mapped to the data type of the destination data system. Types of.
- the abstract data type corresponding to the current field is converted into an abstract data type that has a direct mapping relationship with the data type of the destination data system, and the specific conversion rules include:
- Date is changed to Long, and Date is converted to Unix timestamp
- Date is converted to String, converted to a string according to the custom time format
- Bool is converted to Long, true is changed to 1, and false is changed to 0;
- the invention also proposes a data transmission device for transmitting data between a source data system and a destination data system,
- the data transmission device includes:
- the reading module is configured to read the current field of the data from the source data system, and map the current field to the preset abstraction according to the data type of the current field and the correspondence between the preset abstract data type and the data type of the source data system. type of data;
- the writing module is configured to read the current field that has been mapped to the abstract data type, and map the current field that has been mapped to the abstract data type to the destination data system according to the correspondence between the preset abstract data type and the destination data system data type.
- the type of data is configured to read the current field that has been mapped to the abstract data type, and map the current field that has been mapped to the abstract data type to the destination data system according to the correspondence between the preset abstract data type and the destination data system data type. The type of data.
- the data transmission device is further provided with a configuration module, configured to preset an abstract data type, where the preset abstract data types include Long, Double, String, Date, Bool, and Bytes, corresponding to different source data systems and
- the destination data system is pre-configured with a mapping relationship table between the abstract data type and the data type of the source data system, and a mapping relationship table between the abstract data type and the data type of the destination data system;
- the write module maps the current field that has been mapped to the abstract data type to the data type corresponding to the destination data system, and performs the following operations:
- the writing module is further configured to: when the data type of the current field of the read abstract data type has no corresponding data type directly mapped in the destination data system, convert the abstract data type corresponding to the current field into the destination data.
- System data types have abstract data types that are directly mapped.
- the data transmission method and device provided by the invention completes the data transmission between any heterogeneous data system by setting a unified abstract data type, and there is no data conversion distortion phenomenon; the intermediate data is saved with maximum precision/length to avoid Loss of data precision; support for binary type data transfer, other types can also be supported by extending abstract data types, even if newly developed databases are equally well supported; and because of the use of abstract data types for transmission, avoid Data type loss.
- Figure 1 is a schematic diagram of data transmission of a big data storage/computing system
- FIG. 2 is a schematic diagram of a complex data transmission network
- FIG. 3 is a flow chart of a method for data transmission between data systems according to the present invention.
- FIG. 4 is a schematic diagram of data transmission between different data systems according to the present invention.
- FIG. 5 is a schematic structural diagram of a data transmission apparatus according to the present invention.
- a data transmission method includes the following steps:
- Step S1 The current field of the data is read from the source data system, and the current field is mapped to the preset abstract data type according to the data type of the current field and the correspondence between the preset abstract data type and the data type of the source data system. .
- This embodiment presets an abstract data type that can adapt to most mainstream data types, as shown in Table 1:
- Abstract data type instruction manual Long Infinite length, supports all fixed points, including Int, Short, Long, BigInteger Double (floating point type) Infinite precision, support for all floating point numbers, including Float, Double, BigDecimal String (string type) Infinite character length, support for string types, use of universal character set (Unicode) Date (time type) Support time type, including date, time, datetime type Bool (Boolean type) Support for boolean values Bytes (byte type) Support for binary, such as storing unstructured data such as MP3
- the preset abstract data type of this embodiment has a wide coverage, and can connect to most mainstream data types supported by most data systems, so that data types of different data systems can be mapped to preset abstract data types. , or from a preset abstract data type to a data type required by the destination data system.
- Table 1 only pre-sets the mapping relationship between the current mainstream data system data types and the abstract data types of this embodiment. Those skilled in the art should know that for the unlisted mapping relationships, the actual application can be applied. In the expansion settings.
- JSON field types that support a new definition of a new data system
- types of abstract data types you can achieve JSON type docking.
- Step S2 reading the current field that has been mapped to the abstract data type, and mapping the current field that has been mapped to the abstract data type to the data corresponding to the destination data system according to the correspondence between the preset abstract data type and the data type of the destination data system. Types of.
- the current field mapped from the source data system is mapped to the unified abstract data type of the embodiment, it can be directly stored in the memory, which is convenient for reading and converting to the data type corresponding to the destination data system, and can also be stored in a dedicated In the storage device, the invention is not limited to a specific implementation form.
- Figure 4 shows a schematic diagram of the transmission of several different data systems in accordance with the data transmission method of the present invention.
- the data transmission phase of extracting data to writing data is realized by using the abstract data type for transmission.
- the abstract data class of this embodiment uses a strong data type (the correspondence between data types), rather than a weak data type like CSV, does not cause data distortion.
- the conversion of each data type of the data transmission processing by the prior art is handled by each data system. Taking Sqoop as an example, Sqoop uses the textual CSV format, so that the data is transferred to the destination data system.
- the data conversion to the destination data format depends on the destination data system to convert itself, and the conversion process is not uniform and unreliable.
- data types of data systems vary from company to company, and data types of some source data systems do not have the same type of data in the destination data system.
- the Date in the source data system Mysql has no similar data type in the destination data system such as Facebook's OTS, but there is a bigint in the OTS. The user needs to use bigint to correspond to the Date data type in Mysql.
- the embodiment first maps the Date in Mysql to the Date of the abstract data type, and then converts the data of the abstract data type Date into the abstract data type Long, and the abstract data type Long has a direct mapping relationship with the bigint. This makes it easy to map the abstract data type Long to the bigint in the destination data system OTS.
- the data transmission method of this embodiment further includes the steps of:
- the abstract data type of the current data type of the read data type has no corresponding data type that can be directly mapped in the destination data system
- the abstract data type corresponding to the current field is converted into an abstraction directly related to the data type of the destination data system. type of data.
- the abstract data type Date is converted to the abstract data type Long. Since the abstract data type Long has a direct mapping relationship with the bigint of the destination data system, it can be mapped from the abstract data type Long to the bigint when writing to the destination data system.
- This embodiment is directed to mutual conversion between different abstract data types, and different rules are built in to avoid undefined cross-type data conversion behavior.
- Table 3 shows the conversion relationship between a typical abstract data type:
- Date is converted to Long, and Date is converted to Unix timestamp.
- Date is converted to String and converted to a string according to a user-defined time format (eg YYYY-MM-DD).
- a user-defined time format eg YYYY-MM-DD.
- Table 3 shows a conversion relationship between typical abstract data types
- the database can be mapped according to the data type of the field in the database, and converted into a unified data type system. Since the data does not have cross-type data conversion, there is no data conversion distortion phenomenon; at the same time, the unified data type system uses the maximum precision/length to save the intermediate data to avoid data loss.
- the preset abstract data type in this embodiment also supports binary. Type data transfer. And because the abstract data type is used for transmission, for example, the shaped data is also transmitted using the shaped data type to avoid data type loss.
- This embodiment also provides an apparatus based on the foregoing transmission method, as shown in FIG. 5, including:
- the reading module is configured to read the current field of the data from the source data system, and map the current field to the preset abstraction according to the data type of the current field and the correspondence between the preset abstract data type and the data type of the source data system. type of data;
- the writing module is configured to read the current field that has been mapped to the abstract data type, and map the current field that has been mapped to the abstract data type to the destination data system according to the correspondence between the preset abstract data type and the destination data system data type.
- the type of data is configured to read the current field that has been mapped to the abstract data type, and map the current field that has been mapped to the abstract data type to the destination data system according to the correspondence between the preset abstract data type and the destination data system data type. The type of data.
- mapping relationship table between the abstract data type and the data type of the source data system, and a mapping relationship table between the abstract data type and the data type of the destination data system are respectively pre-configured.
- the mapping relationship table can be pre-set and stored directly in the reading module and the writing module.
- a special configuration module can be additionally configured to preset the abstract data type and the mapping relationship table and store the mapping relationship table.
- the dedicated configuration module is easy to expand and can be adjusted according to the specific data system to achieve more flexibility.
- the reading module of the embodiment performs the following operations:
- the write module maps the current field that has been mapped to the abstract data type to the data type corresponding to the destination data system, and performs the following operations:
- the writing module is further configured to: when the data type of the current field of the read abstract data type has no corresponding data type directly mapped in the destination data system, convert the abstract data type corresponding to the current field into the data data of the destination data system.
- An abstract data type whose type has a direct mapping relationship.
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种数据传输方法及装置,用于在源数据系统与目的数据系统间传输数据,所述数据传输方法从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。对应地,本发明的数据传输装置包括读模块和写模块。本发明的方法及装置通过设定统一的抽象数据类型,完成任意异构数据系统之间数据的传输,同时不存在数据转换失真现象和数据类型丢失的情况。
Description
本申请要求2015年04月26日递交的申请号为201510200985.7、发明名称为“一种数据传输方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本发明属于数据库技术领域,尤其涉及异构数据系统之间数据传输方法及装置。
在当前大数据时代,越来越多的企业与公司逐渐意识到对大数据的获取、分析、挖掘可以为后期商务决策、市场预估、公司发展等提供极具价值的参考模型。大数据能够发挥的价值基于数据量之大、数据入口之大、数据采集规模之大,能提供充分的数据依据为企业发展服务。然而大数据需要解决的首要问题在于将大量用户、系统生成的数据进行大集中,只有数据大集中才能产生大数据。如图1所示,各类在线业务系统(用户中心、商品中心、交易中心)下生成的海量数据存放在各类异构数据系统之中,数据同步需要将各类数据源生成的数据进行传输、同步、汇总到统一的大数据存储/计算体系之中(例如Hadoop、或者阿里集团的ODPS)。
因此数据同步将直接面临各类数据类型不一、存取接口不一、事务模型不一、流量控制模型不一,等各类问题。同时,随着对接的数据存储日益增长,数据同步将面临几何级的数据传输通道增加,给后期数据同步能力扩展造成了巨大的开发、运维、技术支持成本。
对于一个复杂的数据同步网络,如图2所示,在网络中存在很多不同的数据源时,如同时存在Hadoop、Mysql、Oracle、Sqlserver、ODPS等数据源,将这些数据源进行数据同步比较困难。Sqoop是Hadoop开源社区提供的基于Hadoop MapReduce运行框架,将Hadoop和RDBMS间数据同步的工具,Sqoop在解决异构数据传输过程中,仅仅面对Hadoop/HDFS和RDBMS两类存储系统的交互,使用了最简单的CSV文本作为传输交换协议。以Mysql传输数据到HDFS为例:
用户使用Sqoop Client启动Sqoop,Sqoop在Hadoop上启动MapReduce的Job,该Job实际运行的是Sqoop的数据传输任务。Sqoop在MapReduce的Map阶段启动数据通道,将Mysql数据进行抽取同时转为CSV格式作为中间格式。Sqoop将上述CSV格式数据直接写入Hadoop/HDFS文件系统中。然而该方法仅仅支持Hadoop和RDBMS间数
据同步,存在如下的技术问题:
a.数据传输易失真:以开源社区的Sqoop为例,数据全部使用CSV文本格式进行保存,存在将其他非String类型转为String类型的过程,该过程容易导致数据转换失真。
b.部分类型无法支持:以开源社区的Sqoop为例,由于文本化的CSV格式决定了不能转换为String格式的数据必定是无法支持的,导致同步产品功能存在缺陷,例如二进制数据无法通过该方式进行数据传输。
c.数据类型丢失:一旦其他类型转为String,类型完全丢失,对于类型存在强要求的传输领域无法适配,例如数据同步用户要求源端为整形数据,到目标端一定全部为整形数据,否则失败。但由于类型丢失,该需求无法完成。
d.数据类型转换行为未定义,使用各个数据源的转换方式,没有统一的转换行为定义,导致数据同步对接不同数据系统使用不同的转换方式,转换行为随数据系统变化而变化,甚至随数据系统特定版本变化而变化,导致数据系统升级易导致数据同步数据变化诱发数据质量问题。
发明内容
本发明的目的就是提供一种数据传输方法及装置,解决现有技术仅支持特定的数据系统间的数据传输,并且存在数据失真、数据类型丢失等技术问题。
为了实现上述目的,本发明技术方案如下:
一种数据传输方法,用于在源数据系统与目的数据系统间传输数据,其特征在于,所述数据传输方法包括步骤:
从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;
读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
其中,所述预设的抽象数据类型包括Long、Double、String、Date、Bool和Bytes,对应不同的源数据系统和目的数据系统,分别预设有抽象数据类型与源数据系统的数据类型的映射关系表、抽象数据类型与目的数据系统的数据类型的映射关系表;
进一步地,所述根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型,包括步骤:
判断当前字段的数据类型,查找抽象数据类型与源数据系统的数据类型的映射关系
表,找到直接对应的抽象数据类型;
将当前字段的数据类型映射到所找到的直接对应的抽象数据类型;
同理,所述根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型,包括步骤:
根据当前字段的抽象数据类型,查找抽象数据类型与目的数据系统的数据类型的映射关系表,找到直接对应的目的数据系统的数据类型;
将当前字段的抽象数据类型映射到直接对应的目的数据系统的数据类型。
本发明所述Long支持无限长度,所述Double支持无限精度,所述String支持无限字符长度。
进一步地,所述数据传输方法,还包括步骤:
当读取的抽象数据类型当前字段的数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
通过本步骤可以有效降低抽象数据类型与源数据系统和目的数据系统数据类型之间映射关系表的复杂度。
进一步地,所述将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型,具体转换规则包括:
1)、Long转换为Date,将Long数值视作Unix时间戳转换为Date,精度为毫秒;
2)、Long转换为Bool,0视为false,否则为true;
3)、String转换为Long,整数型字符串支持转换为Long,否则报错,不支持科学计数法字符串;
4)、String转换为Double,浮点型字符串支持转换为Long,否则报错,不支持科学计数法;
5)、String转换为Date,根据自定义时间格式满足用户时间格式时转换,否则报错;
6)、String转换为Bool,“true”转为true,”false”转为false,其他报错;
7)、Date转为Long,将Date转为Unix时间戳;
8)、Date转换为String,根据自定义时间格式转换为字符串;
9)、Bool转换为Long,true转为1,false转为0;
10)、Bytes转换为String,根据用户指定的字符集编码转为String。
本发明还提出了一种数据传输装置,用于在源数据系统与目的数据系统间传输数据,
所述数据传输装置包括:
读模块,用于从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;
写模块,用于读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
进一步地,所述数据传输装置还设置有配置模块,用于预设抽象数据类型,所述预设的抽象数据类型包括Long、Double、String、Date、Bool和Bytes,对应不同的源数据系统和目的数据系统,分别预设有抽象数据类型与源数据系统的数据类型的映射关系表、抽象数据类型与目的数据系统的数据类型的映射关系表;
则,所述读模块在将当前字段映射到预设的抽象数据类型时,执行如下操作:
判断当前字段的数据类型,查找抽象数据类型与源数据系统的数据类型的映射关系表,找到直接对应的抽象数据类型;
将当前字段的数据类型映射到所找到的直接对应的抽象数据类型;
同理,所述写模块在将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型,执行如下操作:
根据当前字段的抽象数据类型,查找抽象数据类型与目的数据系统的数据类型的映射关系表,找到直接对应的目的数据系统的数据类型;
将当前字段的抽象数据类型映射到直接对应的目的数据系统的数据类型。
进一步地,所述写模块还用于在读取的抽象数据类型当前字段的数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
本发明提出的数据传输方法及装置,通过设定统一的抽象数据类型,完成任意异构数据系统之间数据的传输,同时不存在数据转换失真现象;采用了最大精度/长度保存中间数据,避免数据精度丢失情况;支持二进制类型数据传输,其他更多类型也可以通过扩展抽象数据类型来支持,即使出现新开发的数据库也能同样很好的支持;并且由于使用抽象数据类型来进行传输,避免数据类型丢失情况。
图1为大数据存储/计算系统数据传输示意图;
图2为复杂的数据传输网络示意图;
图3为本发明数据系统之间数据传输方法流程图;
图4为本发明不同数据系统间数据传输示意图;
图5为本发明数据传输装置结构示意图。
下面结合附图和实施例对本发明技术方案做进一步详细说明,以下实施例不构成对本发明的限定。
如图3所示,本发明实施例一种数据传输方法包括如下步骤:
步骤S1、从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型。
本实施例预设了能适配绝大部分主流数据类型的抽象数据类型,具体如表1所示:
表1本实施例预设的抽象数据类型
| 抽象数据类型 | 备注说明 |
| Long(整形类型) | 无限长度,支持所有定点数,包括Int、Short、Long、BigInteger |
| Double(浮点类型) | 无限精度,支持所有浮点数,包括Float、Double、BigDecimal |
| String(字符串类型) | 无限字符长度,支持字符串类型,使用通用字符集(Unicode) |
| Date(时间类型) | 支持时间类型,包括日期、时间、日期时间类型 |
| Bool(布尔类型) | 支持布尔值 |
| Bytes(字节类型) | 支持二进制,例如存放诸如MP3等非结构化数据 |
如表1所示,本实施例预设的抽象数据类型覆盖范围广,能够对接绝大部分数据系统支持的主流数据类型,从而能够将不同数据系统的数据类型映射到预设的抽象数据类型上,或从预设的抽象数据类型转换为目的数据系统需要的数据类型。
表2 Mysql各种数据类型与本实施例抽象数据类型的映射关系
| 抽象数据类型 | Mysql插件对应类型 |
| Long | int,tinyint,smallint,mediumint,int,bigint |
| Double | float,double,decimal |
| String | varchar,char,tinytext,text,mediumtext,longtext,year |
| Date | date,datetime,timestamp,time |
| Bool | bit,bool |
| Bytes | tinyblob,mediumblob,blob,longblob,varbinary |
以Mysql为例,具有如表2所示的列表,详细设置了Mysql各种数据类型与本实施
例抽象数据类型的映射关系。
对于从Mysql抽取数据的逻辑,该逻辑的过程如下:
读取源数据系统的当前字段,判断该字段的数据类型,如果是int、tinyint、smallint、mediumint、int、bigint等数据类型,就转换为抽象数据类型Long,如果是float、double、decimal等数据类型,就转换为抽象数据类型Double,其他根据表2以此类推。
容易理解的是,对于Hadoop、Oracle、Sqlserver、ODPS等数据系统,同样设置有如表2类似的列表,便于根据设置的列表完成源数据系统与本实施例抽象数据类型的转换,或完成本实施例抽象数据类型与目的数据系统数据类型的转换。在本实施例中不一一列举其他数据系统数据类型与本实施例抽象数据类型的对应关系。
进一步地,表1也只预设了目前绝大多数主流数据系统数据类型与本实施例抽象数据类型的映射关系,本技术领域人员应该知道,对于未列出的映射关系,可以在实际的应用中进行扩展设置。
例如其他更多类型可以通过扩展抽象数据类型来支持,即使出现新开发的数据库也能同样很好的支持,例如为支持一种新数据系统新定义的JSON字段类型,同样扩展抽象数据类型的种类,即可实现JSON类型对接。
步骤S2、读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
从源数据系统读取的当前字段映射为本实施例统一的抽象数据类型后,可以直接存储在内存之中,便于进行读取并转换为目的数据系统对应的数据类型,也可以存储在专门的存储设备中,本发明并不限于具体的实现形式。
而将当前字段写入到目的数据系统中时,抽象数据类型与目的数据系统的数据类型对应关系同样如表1所示,如果目的数据系统是Mysql,则采用表2的对应关系进行转换,表2是表1的一种具体实施例。
容易理解的是,所有对接的数据系统的数据抽取、写入均使用表1的数据模型进行传递数据,将不同的数据源支持的不同数据类型统一抽象到同一套数据模型中,保证所有的数据系统使用同一套协议进行通信,使得任意异构数据存储均可以实现互联互通。图4示出了几个不同数据系统间按照本发明数据传输方法进行传输的示意图。
通过上述步骤就实现了抽取数据到写入数据的数据传输阶段全部使用抽象数据类型进行传输。同时为避免类似CSV格式数据类型传输过程丢失情况,本实施例抽象数据类
型采用了强数据类型(数据类型之间建立对应关系),而非类似CSV的弱数据类型,不会导致数据失真。而现有技术对于数据传输处理各个数据类型的转换交由各个数据系统自行处理,以Sqoop为例,Sqoop将数据全部使用文本化的CSV格式,这样在数据传输到目的数据系统过程将文本化的数据转换到目的数据格式依靠目的数据系统自行转换,转换过程不统一且不可靠。
由于现有技术中存在非常多种类的数据系统,各公司的数据系统数据类型不一,有些源数据系统的数据类型在目的数据系统中没有同类的数据类型。例如:源数据系统Mysql中的Date,在目的数据系统如阿里巴巴的OTS中就没有同类的数据类型,但是OTS中有bigint,用户需要用bigint来与Mysql中的Date数据类型对应。
为了解决上述问题,本实施例采用先将Mysql中的Date映射为抽象数据类型的Date,然后将抽象数据类型Date的数据转换为抽象数据类型Long,而抽象数据类型Long与bigint存在直接的映射关系,这样就很方便地将抽象数据类型Long映射到目的数据系统OTS中的bigint。
这样做的好处是,在设定目的数据系统数据类型与抽象数据类型的映射关系时,只需要设定Long与bigint的映射关系,而不要设置Date与bigint的映射关系。否则每一种抽象数据类型都对应非常复杂的其他数据系统的数据类型,将导致数据类型间的映射关系混乱,表2的内容将非常复杂。
因此,本实施例的数据传输方法还包括步骤:
当读取的抽象数据类型当前字段的抽象数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
即将抽象数据类型Date向转换为抽象数据类型Long,由于抽象数据类型Long与目的数据系统的bigint有直接映射关系,从而在写入目的数据系统时,可以从抽象数据类型Long映射到bigint。
本实施例针对不同抽象数据类型之间的相互转换,内置不同的规则,避免跨类型数据转换行为未定义。表3示出了一种典型的抽象数据类型之间的转换关系:
其中,Y表示自动类型转换或同类型转换,N表示不能跨类型转换,数字代表有条件类型转换:
[1]Long转换为Date,将Long数值视作Unix时间戳转换为Date,精度为毫秒。
[2]Long转换为Bool,0视为false,否则为true。
[3]String转换为Long,整数型字符串支持转换为Long,否则报错。不支持科学计数法字符串。
[4]String转换为Double,浮点型字符串支持转换为Long,否则报错。不支持科学计数法。
[5]String转换为Date,用户自定义时间格式(例如YYYY-MM-DD),满足用户时间格式可以转换,否则报错。
[6]String转换为Bool,“true”转为true,”false”转为false,其他报错。
[7]Date转为Long,将Date转为Unix时间戳。
[8]Date转换为String,根据用户自定义时间格式(例如YYYY-MM-DD)转换为字符串。
[9]Bool转换为Long,true转为1,false转为0。
[10]Bytes转换为String,根据用户指定的字符集编码转为String。
表3一种典型的抽象数据类型之间的转换关系
从而无论源数据系统、目的数据系统是何种数据库,都能根据该数据库中字段的数据类型进行相应的映射,转换为统一的数据类型体系。由于数据没有发生跨类型数据转换,不存在数据转换失真现象;同时统一的数据类型体系采用了最大精度/长度保存中间数据,避免数据精度丢失情况;本实施例预设的抽象数据类型还支持二进制类型数据传输。并且由于使用抽象数据类型来进行传输,例如整形数据同样使用整形数据类型进行传输,避免数据类型丢失情况。
本实施例还提出了基于上述传输方法的装置,如图5所示,包括:
读模块,用于从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;
写模块,用于读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
本实施例中,对应不同的源数据系统和目的数据系统,分别预设有抽象数据类型与源数据系统的数据类型的映射关系表、抽象数据类型与目的数据系统的数据类型的映射关系表。映射关系表可以预先设置好,直接存储在读模块和写模块中,也可以另外设置专门的配置模块,用于预设抽象数据类型及映射关系表并存储映射关系表。专门设置配置模块便于进行扩展,根据具体的数据系统进行调整,实现起来更加灵活。
本实施例读模块在将当前字段映射到预设的抽象数据类型时,执行如下操作:
判断当前字段的数据类型,查找抽象数据类型与源数据系统的数据类型的映射关系表,找到直接对应的抽象数据类型;
将当前字段的数据类型映射到所找到的直接对应的抽象数据类型;
同理,写模块在将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型,执行如下操作:
根据当前字段的抽象数据类型,查找抽象数据类型与目的数据系统的数据类型的映射关系表,找到直接对应的目的数据系统的数据类型;
将当前字段的抽象数据类型映射到直接对应的目的数据系统的数据类型。
进一步地,写模块还用于在读取的抽象数据类型当前字段的数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
以上实施例仅用以说明本发明的技术方案而非对其进行限制,在不背离本发明精神及其实质的情况下,熟悉本领域的技术人员当可根据本发明作出各种相应的改变和变形,但这些相应的改变和变形都应属于本发明所附的权利要求的保护范围。
Claims (10)
- 一种数据传输方法,用于在源数据系统与目的数据系统间传输数据,其特征在于,所述数据传输方法包括步骤:从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
- 根据权利要求1所述的数据传输方法,其特征在于,所述预设的抽象数据类型包括Long、Double、String、Date、Bool和Bytes,对应不同的源数据系统和目的数据系统,分别预设有抽象数据类型与源数据系统的数据类型的映射关系表、抽象数据类型与目的数据系统的数据类型的映射关系表;所述根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型,包括步骤:判断当前字段的数据类型,查找抽象数据类型与源数据系统的数据类型的映射关系表,找到直接对应的抽象数据类型;将当前字段的数据类型映射到所找到的直接对应的抽象数据类型;所述根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型,包括步骤:根据当前字段的抽象数据类型,查找抽象数据类型与目的数据系统的数据类型的映射关系表,找到直接对应的目的数据系统的数据类型;将当前字段的抽象数据类型映射到直接对应的目的数据系统的数据类型。
- 根据权利要求2所述的数据传输方法,其特征在于,所述Long支持无限长度,所述Double支持无限精度,所述String支持无限字符长度。
- 根据权利要求2所述的数据传输方法,其特征在于,所述数据传输方法,还包括步骤:当读取的抽象数据类型当前字段的数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
- 根据权利要求4所述的数据传输方法,其特征在于,所述将当前字段对应的抽 象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型,具体转换规则包括:1)、Long转换为Date,将Long数值视作Unix时间戳转换为Date,精度为毫秒;2)、Long转换为Bool,0视为false,否则为true;3)、String转换为Long,整数型字符串支持转换为Long,否则报错,不支持科学计数法字符串;4)、String转换为Double,浮点型字符串支持转换为Long,否则报错,不支持科学计数法;5)、String转换为Date,根据自定义时间格式满足用户时间格式时转换,否则报错;6)、String转换为Bool,“true”转为true,”false”转为false,其他报错;7)、Date转为Long,将Date转为Unix时间戳;8)、Date转换为String,根据自定义时间格式转换为字符串;9)、Bool转换为Long,true转为1,false转为0;10)、Bytes转换为String,根据用户指定的字符集编码转为String。
- 一种数据传输装置,用于在源数据系统与目的数据系统间传输数据,其特征在于,所述数据传输装置包括:读模块,用于从源数据系统读取数据的当前字段,根据当前字段的数据类型、以及预设的抽象数据类型与源数据系统的数据类型的对应关系,将当前字段映射到预设的抽象数据类型;写模块,用于读取已经映射为抽象数据类型的当前字段,根据预设的抽象数据类型与目的数据系统数据类型的对应关系,将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型。
- 根据权利要求6所述的数据传输装置,其特征在于,所述数据传输装置还设置有配置模块,用于预设抽象数据类型,所述预设的抽象数据类型包括Long、Double、String、Date、Bool和Bytes,对应不同的源数据系统和目的数据系统,分别预设有抽象数据类型与源数据系统的数据类型的映射关系表、抽象数据类型与目的数据系统的数据类型的映射关系表;所述读模块在将当前字段映射到预设的抽象数据类型时,执行如下操作:判断当前字段的数据类型,查找抽象数据类型与源数据系统的数据类型的映射关系 表,找到直接对应的抽象数据类型;将当前字段的数据类型映射到所找到的直接对应的抽象数据类型;所述写模块在将已经映射为抽象数据类型的当前字段映射到目的数据系统对应的数据类型,执行如下操作:根据当前字段的抽象数据类型,查找抽象数据类型与目的数据系统的数据类型的映射关系表,找到直接对应的目的数据系统的数据类型;将当前字段的抽象数据类型映射到直接对应的目的数据系统的数据类型。
- 根据权利要求7所述的数据传输装置,其特征在于,所述Long支持无限长度,所述Double支持无限精度,所述String支持无限字符长度。
- 根据权利要求7所述的数据传输装置,其特征在于,所述写模块还用于在读取的抽象数据类型当前字段的数据类型在目的数据系统中没有可以直接映射的对应数据类型时,将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型。
- 根据权利要求9所述的数据传输装置,其特征在于,所述将当前字段对应的抽象数据类型转换为与目的数据系统数据类型有直接映射关系的抽象数据类型,具体转换规则包括:1)、Long转换为Date,将Long数值视作Unix时间戳转换为Date,精度为毫秒;2)、Long转换为Bool,0视为false,否则为true;3)、String转换为Long,整数型字符串支持转换为Long,否则报错,不支持科学计数法字符串;4)、String转换为Double,浮点型字符串支持转换为Long,否则报错,不支持科学计数法;5)、String转换为Date,根据自定义时间格式满足用户时间格式时转换,否则报错;6)、String转换为Bool,“true”转为true,”false”转为false,其他报错;7)、Date转为Long,将Date转为Unix时间戳;8)、Date转换为String,根据自定义时间格式转换为字符串;9)、Bool转换为Long,true转为1,false转为0;10)、Bytes转换为String,根据用户指定的字符集编码转为String。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510200985.7A CN106156227A (zh) | 2015-04-26 | 2015-04-26 | 一种数据传输方法及装置 |
| CN201510200985.7 | 2015-04-26 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2016173428A1 true WO2016173428A1 (zh) | 2016-11-03 |
Family
ID=57198159
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2016/079649 Ceased WO2016173428A1 (zh) | 2015-04-26 | 2016-04-19 | 一种数据传输方法及装置 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN106156227A (zh) |
| WO (1) | WO2016173428A1 (zh) |
Cited By (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111522817A (zh) * | 2020-04-22 | 2020-08-11 | 支付宝(杭州)信息技术有限公司 | 表格内容映射系统、方法及非暂时性存储介质 |
| CN113590581A (zh) * | 2021-06-28 | 2021-11-02 | 中国农业银行股份有限公司 | 数据传输方法、装置、设备及存储介质 |
| CN114422377A (zh) * | 2021-12-30 | 2022-04-29 | 北京润科通用技术有限公司 | 数据转发模型的生成方法及装置 |
| CN115129777A (zh) * | 2022-06-30 | 2022-09-30 | 杭州数梦工场科技有限公司 | 一种数据表转换方法、装置、电子设备及存储介质 |
| CN116955464A (zh) * | 2023-06-26 | 2023-10-27 | 杭州未名信科科技有限公司 | 数据处理方法和装置、存储介质及电子设备 |
| CN118170851A (zh) * | 2024-05-11 | 2024-06-11 | 浪潮云信息技术股份公司 | 异构数据库数据字段同步方法及系统 |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN107798059B (zh) * | 2017-09-08 | 2023-05-26 | 中国电力科学研究院 | 一种nco气象数据结构化存储方法和装置 |
| CN111737404A (zh) * | 2020-06-26 | 2020-10-02 | 豆盟(北京)科技股份有限公司 | 数据处理方法、装置、设备和计算机存储介质 |
| CN115549862B (zh) * | 2022-12-05 | 2023-03-31 | 大方智造(天津)科技有限公司 | 基于动态解析的mes系统并发性能测试数据接收方法 |
| CN117033495A (zh) * | 2023-08-25 | 2023-11-10 | 浪潮卓数大数据产业发展有限公司 | 一种不同种类数据库转储数据时字段类型映射的方法 |
| CN116841773B (zh) * | 2023-09-01 | 2023-12-12 | 北京翼辉信息技术有限公司 | 数据交互方法、装置、电子设备及存储介质 |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101364240A (zh) * | 2008-10-14 | 2009-02-11 | 杭州华三通信技术有限公司 | 元数据管理方法及装置 |
| US20130103705A1 (en) * | 2006-02-28 | 2013-04-25 | Sap Ag | Schema mapping and data transformation on the basis of a conceptual model |
| CN104376062A (zh) * | 2014-11-11 | 2015-02-25 | 中国有色金属长沙勘察设计研究院有限公司 | 一种异构数据库平台数据的同步方法 |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US8620897B2 (en) * | 2011-03-11 | 2013-12-31 | Microsoft Corporation | Indexing and searching features including using reusable index fields |
| US9077765B2 (en) * | 2012-10-09 | 2015-07-07 | Microsoft Technology Licensing, Llc | Content management and delivery |
-
2015
- 2015-04-26 CN CN201510200985.7A patent/CN106156227A/zh active Pending
-
2016
- 2016-04-19 WO PCT/CN2016/079649 patent/WO2016173428A1/zh not_active Ceased
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20130103705A1 (en) * | 2006-02-28 | 2013-04-25 | Sap Ag | Schema mapping and data transformation on the basis of a conceptual model |
| CN101364240A (zh) * | 2008-10-14 | 2009-02-11 | 杭州华三通信技术有限公司 | 元数据管理方法及装置 |
| CN104376062A (zh) * | 2014-11-11 | 2015-02-25 | 中国有色金属长沙勘察设计研究院有限公司 | 一种异构数据库平台数据的同步方法 |
Cited By (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111522817A (zh) * | 2020-04-22 | 2020-08-11 | 支付宝(杭州)信息技术有限公司 | 表格内容映射系统、方法及非暂时性存储介质 |
| CN111522817B (zh) * | 2020-04-22 | 2023-05-12 | 支付宝(杭州)信息技术有限公司 | 表格内容映射系统、方法及非暂时性存储介质 |
| CN113590581A (zh) * | 2021-06-28 | 2021-11-02 | 中国农业银行股份有限公司 | 数据传输方法、装置、设备及存储介质 |
| CN113590581B (zh) * | 2021-06-28 | 2024-05-14 | 中国农业银行股份有限公司 | 数据传输方法、装置、设备及存储介质 |
| CN114422377A (zh) * | 2021-12-30 | 2022-04-29 | 北京润科通用技术有限公司 | 数据转发模型的生成方法及装置 |
| CN114422377B (zh) * | 2021-12-30 | 2023-09-22 | 北京润科通用技术有限公司 | 数据转发模型的生成方法及装置 |
| CN115129777A (zh) * | 2022-06-30 | 2022-09-30 | 杭州数梦工场科技有限公司 | 一种数据表转换方法、装置、电子设备及存储介质 |
| CN115129777B (zh) * | 2022-06-30 | 2025-10-31 | 杭州数梦工场科技有限公司 | 一种数据表转换方法、装置、电子设备及存储介质 |
| CN116955464A (zh) * | 2023-06-26 | 2023-10-27 | 杭州未名信科科技有限公司 | 数据处理方法和装置、存储介质及电子设备 |
| CN118170851A (zh) * | 2024-05-11 | 2024-06-11 | 浪潮云信息技术股份公司 | 异构数据库数据字段同步方法及系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106156227A (zh) | 2016-11-23 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2016173428A1 (zh) | 一种数据传输方法及装置 | |
| CN106339274B (zh) | 一种数据快照获取的方法及系统 | |
| CN106682119B (zh) | 基于http服务切面与日志系统的异步数据同步方法和系统 | |
| CN110647579A (zh) | 数据同步方法及装置、计算机设备与可读介质 | |
| CN104967658A (zh) | 一种多终端设备上的数据同步方法 | |
| CN103593352A (zh) | 一种海量数据清洗方法及装置 | |
| CN114356884A (zh) | 数据迁移方法和装置 | |
| CN107122428A (zh) | 一种数据库异构数据复制格式转换方法 | |
| CN107609085A (zh) | 一种基于大数据技术的智能电网量测数据处理方法及系统 | |
| CN112817930A (zh) | 一种数据迁移的方法和装置 | |
| CN110781197A (zh) | 一种hive离线同步校验方法、装置及电子设备 | |
| CN108241676A (zh) | 实现数据同步的方法及设备 | |
| WO2022247019A1 (zh) | 一种基于fpga的工业协议映射结构和方法 | |
| CN110795418A (zh) | 一种基于json的mongoDB到mysql的数据抽取方法 | |
| CN108108392B (zh) | 商品数据管理方法、装置、计算机设备及存储介质 | |
| CN105447069B (zh) | 基于bw平台的对账平台数据同步方法及系统 | |
| CN116010172B (zh) | 一种数据同步方法、数据库、数据同步装置和产品 | |
| CN104052804A (zh) | 一种不同任务拓扑间共享数据流的方法、装置及集群 | |
| CN110928839B (zh) | 国际运价数据的存储方法和系统 | |
| CN111427845A (zh) | 一种交互式建模分析算子数据交换方法 | |
| US20190012596A1 (en) | Data processing system, method, and device | |
| CN106909570B (zh) | 一种数据转换方法及装置 | |
| CN116107971A (zh) | 模型的数据处理方法、装置、电子设备以及存储介质 | |
| CN112130846A (zh) | 一种三微一屏发布引擎系统及发布方法 | |
| CN112052254A (zh) | 数据封装方法、电子设备及存储介质 |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 16785859 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 16785859 Country of ref document: EP Kind code of ref document: A1 |
