@ -15,407 +15,413 @@
* limitations under the License .
* limitations under the License .
* /
* /
import { h , onMounted , Ref , ref , watch } from 'vue'
import { h , onMounted , Ref , ref , watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useI18n } from 'vue-i18n'
import { useDatasource } from './use-sqoop-datasource'
import { useDatasource } from './use-sqoop-datasource'
import styles from '../index.module.scss'
import styles from '../index.module.scss'
import type { IJsonItem , IOption , SourceType } from '../types'
import type { IJsonItem , IOption , SourceType } from '../types'
export function useTargetType (
export function useTargetType (
model : { [ field : string ] : any } ,
model : { [ field : string ] : any } ,
unCustomSpan : Ref < number >
unCustomSpan : Ref < number >
) : IJsonItem [ ] {
) : IJsonItem [ ] {
const { t } = useI18n ( )
const { t } = useI18n ( )
const hiveSpan = ref ( 24 )
const hiveSpan = ref ( 24 )
const hdfsSpan = ref ( 0 )
const hdfsSpan = ref ( 0 )
const rdbmsSpan = ref ( 0 )
const rdbmsSpan = ref ( 0 )
const dataSourceSpan = ref ( 0 )
const dataSourceSpan = ref ( 0 )
const updateSpan = ref ( 0 )
const updateSpan = ref ( 0 )
const isChange : any = ref ( false )
const isChange : any = ref ( false )
const rdbmsSourceTypes = ref ( [
const rdbmsSourceTypes = ref ( [
{
{
label : 'MYSQL' ,
label : 'MYSQL' ,
value : 'MYSQL'
value : 'MYSQL'
} ,
} ,
{
{
label : 'ORACLE' ,
label : 'ORACLE' ,
value : 'ORACLE'
value : 'ORACLE'
} ,
} ,
{
{
label : 'SQLSERVER' ,
label : 'SQLSERVER' ,
value : 'SQLSERVER'
value : 'SQLSERVER'
} ,
} ,
{
{
label : 'HANA' ,
label : 'HANA' ,
value : 'HANA'
value : 'HANA'
}
}
] as IOption [ ] )
] as IOption [ ] )
const hadoopSourceTypes = ref ( [
const hadoopSourceTypes = ref ( [
{
{
label : 'HIVE' ,
label : 'HIVE' ,
value : 'HIVE'
value : 'HIVE'
} , {
} ,
label : 'HDFS' ,
{
value : 'HDFS'
label : 'HDFS' ,
}
value : 'HDFS'
] as IOption [ ] )
const targetTypes = ref ( )
const resetSpan = ( ) = > {
hiveSpan . value = unCustomSpan . value && model . targetType === 'HIVE' ? 24 : 0
hdfsSpan . value = unCustomSpan . value && model . targetType === 'HDFS' ? 24 : 0
rdbmsSpan . value =
unCustomSpan . value && rdbmsSourceTypes . value . some ( target = > target . value === model . targetType ) ? 24 : 0
dataSourceSpan . value =
unCustomSpan . value && rdbmsSourceTypes . value . some ( target = > target . value === model . targetType ) ? 24 : 0
updateSpan . value = rdbmsSpan . value && model . targetMysqlIsUpdate ? 24 : 0
}
}
] as IOption [ ] )
const targetTypes = ref ( )
const getTargetTypesBySourceType = (
const resetSpan = ( ) = > {
sourceType : SourceType ,
hiveSpan . value = unCustomSpan . value && model . targetType === 'HIVE' ? 24 : 0
srcQueryType : string
hdfsSpan . value = unCustomSpan . value && model . targetType === 'HDFS' ? 24 : 0
) : IOption [ ] = > {
rdbmsSpan . value =
switch ( sourceType ) {
unCustomSpan . value &&
case 'MYSQL' :
rdbmsSourceTypes . value . some ( ( target ) = > target . value === model . targetType )
if ( srcQueryType === '1' ) {
? 24
return hadoopSourceTypes . value
: 0
}
dataSourceSpan . value =
return hadoopSourceTypes . value
unCustomSpan . value &&
case 'HDFS' :
rdbmsSourceTypes . value . some ( ( target ) = > target . value === model . targetType )
case 'HIVE' :
? 24
return rdbmsSourceTypes . value
: 0
default :
updateSpan . value = rdbmsSpan . value && model . targetMysqlIsUpdate ? 24 : 0
return hadoopSourceTypes . value
}
const getTargetTypesBySourceType = (
sourceType : SourceType ,
srcQueryType : string
) : IOption [ ] = > {
switch ( sourceType ) {
case 'MYSQL' :
if ( srcQueryType === '1' ) {
return hadoopSourceTypes . value
}
}
return hadoopSourceTypes . value
case 'HDFS' :
case 'HIVE' :
return rdbmsSourceTypes . value
default :
return hadoopSourceTypes . value
}
}
}
const resetValue = ( ) = > {
const resetValue = ( ) = > {
if ( ! isChange . value ) {
if ( ! isChange . value ) {
isChange . value = true
isChange . value = true
return
return
}
}
switch ( model . modelType ) {
switch ( model . modelType ) {
case 'import' :
case 'import' :
model . targetHiveDatabase = '' ;
model . targetHiveDatabase = ''
model . targetHiveTable = '' ;
model . targetHiveTable = ''
model . targetHdfsTargetPath = '' ;
model . targetHdfsTargetPath = ''
break
break
case 'export' :
case 'export' :
model . targetMysqlDatasource = '' ;
model . targetMysqlDatasource = ''
model . targetMysqlTable = '' ;
model . targetMysqlTable = ''
model . targetMysqlColumns = '' ;
model . targetMysqlColumns = ''
model . targetMysqlFieldsTerminated = '' ;
model . targetMysqlFieldsTerminated = ''
model . targetMysqlLinesTerminated = '' ;
model . targetMysqlLinesTerminated = ''
model . targetMysqlTable = '' ;
model . targetMysqlTable = ''
break
break
default :
default :
model . sourceMysqlDatasource = '' ;
model . sourceMysqlDatasource = ''
}
}
}
onMounted ( ( ) = > {
targetTypes . value = [ . . . hadoopSourceTypes . value ]
} )
watch (
( ) = > [ model . sourceType , model . srcQueryType ] ,
( [ sourceType , srcQueryType ] ) = > {
targetTypes . value = getTargetTypesBySourceType ( sourceType , srcQueryType )
model . targetType = targetTypes . value [ 0 ] . value
}
}
)
onMounted ( ( ) = > {
watch (
targetTypes . value = [ . . . hadoopSourceTypes . value ] ;
( ) = > [ unCustomSpan . value , model . targetType , model . targetMysqlIsUpdate ] ,
} )
( ) = > {
resetValue ( )
resetSpan ( )
}
)
watch (
return [
( ) = > [ model . sourceType , model . srcQueryType ] ,
{
( [ sourceType , srcQueryType ] ) = > {
type : 'custom' ,
targetTypes . value = getTargetTypesBySourceType ( sourceType , srcQueryType )
field : 'custom-title-target' ,
model . targetType = targetTypes . value [ 0 ] . value
span : unCustomSpan ,
widget : h (
'div' ,
{ class : styles [ 'field-title' ] } ,
t ( 'project.node.data_target' )
)
} ,
{
type : 'select' ,
field : 'targetType' ,
name : t ( 'project.node.type' ) ,
span : unCustomSpan ,
options : targetTypes
} ,
{
type : 'input' ,
field : 'targetHiveDatabase' ,
name : t ( 'project.node.database' ) ,
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.database_tips' )
} ,
validate : {
trigger : [ 'blur' , 'input' ] ,
required : true ,
validator ( validate , value ) {
if ( hiveSpan . value && ! value ) {
return new Error ( t ( 'project.node.database_tips' ) )
}
}
}
)
}
} ,
watch (
{
( ) = > [ unCustomSpan . value , model . targetType , model . targetMysqlIsUpdate ] ,
type : 'input' ,
( ) = > {
field : 'targetHiveTable' ,
resetValue ( ) ;
name : t ( 'project.node.table' ) ,
resetSpan ( )
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.table' )
} ,
validate : {
trigger : [ 'blur' , 'input' ] ,
required : true ,
validator ( rule , value ) {
if ( hiveSpan . value && ! value ) {
return new Error ( t ( 'project.node.table_tips' ) )
}
}
}
)
}
} ,
return [
{
{
type : 'switch' ,
type : 'custom' ,
field : 'targetHiveCreateTable' ,
field : 'custom-title-target' ,
span : hiveSpan ,
span : unCustomSpan ,
name : t ( 'project.node.create_hive_table' )
widget : h (
} ,
'div' ,
{
{ class : styles [ 'field-title' ] } ,
type : 'switch' ,
t ( 'project.node.data_target' )
field : 'targetHiveDropDelimiter' ,
)
span : hiveSpan ,
} ,
name : t ( 'project.node.drop_delimiter' )
{
} ,
type : 'select' ,
{
field : 'targetType' ,
type : 'switch' ,
name : t ( 'project.node.type' ) ,
field : 'targetHiveOverWrite' ,
span : unCustomSpan ,
span : hiveSpan ,
options : targetTypes
name : t ( 'project.node.over_write_src' )
} ,
} ,
{
{
type : 'input' ,
type : 'input' ,
field : 'targetHiveDatabase' ,
field : 'targetHiveTargetDir' ,
name : t ( 'project.node.database' ) ,
name : t ( 'project.node.hive_target_dir' ) ,
span : hiveSpan ,
span : hiveSpan ,
props : {
props : {
placeholder : t ( 'project.node.database_tips' )
placeholder : t ( 'project.node.hive_target_dir_tips' )
} ,
}
validate : {
} ,
trigger : [ 'blur' , 'input' ] ,
{
required : true ,
type : 'input' ,
validator ( validate , value ) {
field : 'targetHiveReplaceDelimiter' ,
if ( hiveSpan . value && ! value ) {
name : t ( 'project.node.replace_delimiter' ) ,
return new Error ( t ( 'project.node.database_tips' ) )
span : hiveSpan ,
}
props : {
}
placeholder : t ( 'project.node.replace_delimiter_tips' )
}
}
} ,
} ,
{
{
type : 'input' ,
type : 'input' ,
field : 'targetHiveTable' ,
field : 'targetHivePartitionKey' ,
name : t ( 'project.node.table' ) ,
name : t ( 'project.node.hive_partition_keys' ) ,
span : hiveSpan ,
span : hiveSpan ,
props : {
props : {
placeholder : t ( 'project.node.table' )
placeholder : t ( 'project.node.hive_partition_keys_tips' )
} ,
}
validate : {
} ,
trigger : [ 'blur' , 'input' ] ,
{
required : true ,
type : 'input' ,
validator ( rule , value ) {
field : 'targetHivePartitionValue' ,
if ( hiveSpan . value && ! value ) {
name : t ( 'project.node.hive_partition_values' ) ,
return new Error ( t ( 'project.node.table_tips' ) )
span : hiveSpan ,
}
props : {
}
placeholder : t ( 'project.node.hive_partition_values_tips' )
}
}
} ,
} ,
{
{
type : 'switch' ,
type : 'input' ,
field : 'targetHiveCreateTable' ,
field : 'targetHdfsTargetPath' ,
span : hiveSpan ,
name : t ( 'project.node.target_dir' ) ,
name : t ( 'project.node.create_hive_table' )
span : hdfsSpan ,
} ,
props : {
{
placeholder : t ( 'project.node.target_dir_tips' )
type : 'switch' ,
} ,
field : 'targetHiveDropDelimiter' ,
validate : {
span : hiveSpan ,
trigger : [ 'blur' , 'input' ] ,
name : t ( 'project.node.drop_delimiter' )
required : true ,
} ,
validator ( rule , value ) {
{
if ( hdfsSpan . value && ! value ) {
type : 'switch' ,
return new Error ( t ( 'project.node.target_dir_tips' ) )
field : 'targetHiveOverWrite' ,
}
span : hiveSpan ,
name : t ( 'project.node.over_write_src' )
} ,
{
type : 'input' ,
field : 'targetHiveTargetDir' ,
name : t ( 'project.node.hive_target_dir' ) ,
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.hive_target_dir_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHiveReplaceDelimiter' ,
name : t ( 'project.node.replace_delimiter' ) ,
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.replace_delimiter_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHivePartitionKey' ,
name : t ( 'project.node.hive_partition_keys' ) ,
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.hive_partition_keys_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHivePartitionValue' ,
name : t ( 'project.node.hive_partition_values' ) ,
span : hiveSpan ,
props : {
placeholder : t ( 'project.node.hive_partition_values_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHdfsTargetPath' ,
name : t ( 'project.node.target_dir' ) ,
span : hdfsSpan ,
props : {
placeholder : t ( 'project.node.target_dir_tips' )
} ,
validate : {
trigger : [ 'blur' , 'input' ] ,
required : true ,
validator ( rule , value ) {
if ( hdfsSpan . value && ! value ) {
return new Error ( t ( 'project.node.target_dir_tips' ) )
}
}
}
} ,
{
type : 'switch' ,
field : 'targetHdfsDeleteTargetDir' ,
name : t ( 'project.node.delete_target_dir' ) ,
span : hdfsSpan
} ,
{
type : 'radio' ,
field : 'targetHdfsCompressionCodec' ,
name : t ( 'project.node.compression_codec' ) ,
span : hdfsSpan ,
options : COMPRESSIONCODECS
} ,
{
type : 'radio' ,
field : 'targetHdfsFileType' ,
name : t ( 'project.node.file_type' ) ,
span : hdfsSpan ,
options : FILETYPES
} ,
{
type : 'input' ,
field : 'targetHdfsFieldsTerminated' ,
name : t ( 'project.node.fields_terminated' ) ,
span : hdfsSpan ,
props : {
placeholder : t ( 'project.node.fields_terminated_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHdfsLinesTerminated' ,
name : t ( 'project.node.lines_terminated' ) ,
span : hdfsSpan ,
props : {
placeholder : t ( 'project.node.lines_terminated_tips' )
}
} ,
. . . useDatasource (
model ,
dataSourceSpan ,
'targetMysqlType' ,
'targetMysqlDatasource'
) ,
{
type : 'input' ,
field : 'targetMysqlTable' ,
name : t ( 'project.node.table' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.table_tips' )
} ,
validate : {
trigger : [ 'blur' , 'input' ] ,
required : true ,
validator ( validate , value ) {
if ( rdbmsSpan . value && ! value ) {
return new Error ( t ( 'project.node.table_tips' ) )
}
}
}
} ,
{
type : 'input' ,
field : 'targetMysqlColumns' ,
name : t ( 'project.node.column' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.column_tips' )
}
} ,
{
type : 'input' ,
field : 'targetMysqlFieldsTerminated' ,
name : t ( 'project.node.fields_terminated' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.fields_terminated_tips' )
}
} ,
{
type : 'input' ,
field : 'targetMysqlLinesTerminated' ,
name : t ( 'project.node.lines_terminated' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.lines_terminated_tips' )
}
} ,
{
type : 'switch' ,
field : 'targetMysqlIsUpdate' ,
span : rdbmsSpan ,
name : t ( 'project.node.is_update' )
} ,
{
type : 'input' ,
field : 'targetMysqlTargetUpdateKey' ,
name : t ( 'project.node.update_key' ) ,
span : updateSpan ,
props : {
placeholder : t ( 'project.node.update_key_tips' )
}
} ,
{
type : 'radio' ,
field : 'targetMysqlUpdateMode' ,
name : t ( 'project.node.update_mode' ) ,
span : updateSpan ,
options : [
{
label : t ( 'project.node.only_update' ) ,
value : 'updateonly'
} ,
{
label : t ( 'project.node.allow_insert' ) ,
value : 'allowinsert'
}
]
}
}
]
}
}
} ,
const COMPRESSIONCODECS = [
{
{
label : 'snappy' ,
type : 'switch' ,
value : 'snappy'
field : 'targetHdfsDeleteTargetDir' ,
name : t ( 'project.node.delete_target_dir' ) ,
span : hdfsSpan
} ,
} ,
{
{
label : 'lzo' ,
type : 'radio' ,
value : 'lzo'
field : 'targetHdfsCompressionCodec' ,
name : t ( 'project.node.compression_codec' ) ,
span : hdfsSpan ,
options : COMPRESSIONCODECS
} ,
} ,
{
{
label : 'gzip' ,
type : 'radio' ,
value : 'gzip'
field : 'targetHdfsFileType' ,
name : t ( 'project.node.file_type' ) ,
span : hdfsSpan ,
options : FILETYPES
} ,
} ,
{
{
label : 'no' ,
type : 'input' ,
value : ''
field : 'targetHdfsFieldsTerminated' ,
}
name : t ( 'project.node.fields_terminated' ) ,
]
span : hdfsSpan ,
const FILETYPES = [
props : {
placeholder : t ( 'project.node.fields_terminated_tips' )
}
} ,
{
type : 'input' ,
field : 'targetHdfsLinesTerminated' ,
name : t ( 'project.node.lines_terminated' ) ,
span : hdfsSpan ,
props : {
placeholder : t ( 'project.node.lines_terminated_tips' )
}
} ,
. . . useDatasource (
model ,
dataSourceSpan ,
'targetMysqlType' ,
'targetMysqlDatasource'
) ,
{
{
label : 'avro' ,
type : 'input' ,
value : '--as-avrodatafile'
field : 'targetMysqlTable' ,
name : t ( 'project.node.table' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.table_tips' )
} ,
validate : {
trigger : [ 'blur' , 'input' ] ,
required : true ,
validator ( validate , value ) {
if ( rdbmsSpan . value && ! value ) {
return new Error ( t ( 'project.node.table_tips' ) )
}
}
}
} ,
} ,
{
{
label : 'sequence' ,
type : 'input' ,
value : '--as-sequencefile'
field : 'targetMysqlColumns' ,
name : t ( 'project.node.column' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.column_tips' )
}
} ,
} ,
{
{
label : 'text' ,
type : 'input' ,
value : '--as-textfile'
field : 'targetMysqlFieldsTerminated' ,
name : t ( 'project.node.fields_terminated' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.fields_terminated_tips' )
}
} ,
} ,
{
{
label : 'parquet' ,
type : 'input' ,
value : '--as-parquetfile'
field : 'targetMysqlLinesTerminated' ,
name : t ( 'project.node.lines_terminated' ) ,
span : rdbmsSpan ,
props : {
placeholder : t ( 'project.node.lines_terminated_tips' )
}
} ,
{
type : 'switch' ,
field : 'targetMysqlIsUpdate' ,
span : rdbmsSpan ,
name : t ( 'project.node.is_update' )
} ,
{
type : 'input' ,
field : 'targetMysqlTargetUpdateKey' ,
name : t ( 'project.node.update_key' ) ,
span : updateSpan ,
props : {
placeholder : t ( 'project.node.update_key_tips' )
}
} ,
{
type : 'radio' ,
field : 'targetMysqlUpdateMode' ,
name : t ( 'project.node.update_mode' ) ,
span : updateSpan ,
options : [
{
label : t ( 'project.node.only_update' ) ,
value : 'updateonly'
} ,
{
label : t ( 'project.node.allow_insert' ) ,
value : 'allowinsert'
}
]
}
}
]
}
const COMPRESSIONCODECS = [
{
label : 'snappy' ,
value : 'snappy'
} ,
{
label : 'lzo' ,
value : 'lzo'
} ,
{
label : 'gzip' ,
value : 'gzip'
} ,
{
label : 'no' ,
value : ''
}
]
const FILETYPES = [
{
label : 'avro' ,
value : '--as-avrodatafile'
} ,
{
label : 'sequence' ,
value : '--as-sequencefile'
} ,
{
label : 'text' ,
value : '--as-textfile'
} ,
{
label : 'parquet' ,
value : '--as-parquetfile'
}
]
]