// deriveFeatureColumn will fill in "fcMap" with derivated FeatureColumns.
deriveFeatureColumn will fill in "fcMap" with derivated FeatureColumns.
// deriveFeatureColumn will fill in " fcMap " with derivated FeatureColumns .
func deriveFeatureColumn(fcMap ColumnMap, columnTargets []string, fdMap FieldDescMap, selectFieldTypeMap fieldTypes, trainStmt *TrainStmt) error {
	 need to store FeatureColumn under it's target in case of
	 the same column used for different target, e.g.
	 COLUMN EMBEDDING(c1) for deep
	        EMBEDDING(c2) for deep
	        EMBEDDING(c1) for wide
	for _, target := range columnTargets {
		fcTargetMap, ok := fcMap[target]
		if !ok {
			 create map for current target
			fcMap[target] = make(map[string][]FeatureColumn)
			fcTargetMap = fcMap[target]
		}
		fcMap[target] = make(map[string][]FeatureColumn)
		for f := range fcTargetMap {
			if _, ok := selectFieldTypeMap[f]; !ok {
				if len(fcTargetMap[f]) != 1 {
					return fmt.Errorf("cannot expand '%s' in 'column clause'", f)
				}
				 Try as regex to match the selected fields
				r, e := regexp.Compile("(?i)^" + f + "$")
				if e != nil {
					return fmt.Errorf("unknown column '%s' in 'column clause'", f)
				}
				hasMatch := false
				for sf := range selectFieldTypeMap {
					if r.MatchString(sf) {
						applied, err := fcTargetMap[f][0].ApplyTo(fdMap[sf])
						if err != nil {
							return err
						}
						fcMap[target][sf] = []FeatureColumn{applied}
						hasMatch = true
					}
				}
				if !hasMatch {
					return fmt.Errorf("'%s' in 'column clause' does not match any selected fields", f)
				}
				delete(fdMap, f)
			} else {
				fcMap[target][f] = fcTargetMap[f]
			}
		}
		fcTargetMap = fcMap[target]
		 ================== MAIN LOOP ==================
		 Update or generate FeatureColumn for each selected field:
		for slctKey := range selectFieldTypeMap {
			 skip label field
			if trainStmt.Label.GetFieldDesc()[0].Name == slctKey {
				continue
			}
			if fcList, ok := fcTargetMap[slctKey]; ok {
				err := updateFeatureColumn(fcList, fdMap)
				if err != nil {
					return err
				}
			} else {
				if len(columnTargets) > 1 {
					 if column clause have more than one target, each target should specify the
					 full list of the columns to use.
					continue
				}
				err := newFeatureColumn(fcTargetMap, fdMap, slctKey)
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
func deriveFeatureColumn ( fcMap ColumnMap , columnTargets [ ] string , fdMap FieldDescMap , selectFieldTypeMap fieldTypes , trainStmt * TrainStmt ) error { for _ , target := range columnTargets { fcTargetMap , ok := fcMap [ target ] if ! ok { fcMap [ target ] = make ( map [ string ] [ ] FeatureColumn ) fcTargetMap = fcMap [ target ] } fcMap [ target ] = make ( map [ string ] [ ] FeatureColumn ) for f := range fcTargetMap { if _ , ok := selectFieldTypeMap [ f ] ; ! ok { if len ( fcTargetMap [ f ] ) != 1 { return fmt . Errorf ( " " , f ) } r , e := regexp . Compile ( " " + f + " " ) if e != nil { return fmt . Errorf ( " " , f ) } hasMatch := false for sf := range selectFieldTypeMap { if r . MatchString ( sf ) { applied , err := fcTargetMap [ f ] [ 0 ] . ApplyTo ( fdMap [ sf ] ) if err != nil { return err } fcMap [ target ] [ sf ] = [ ] FeatureColumn { applied } hasMatch = true } } if ! hasMatch { return fmt . Errorf ( " " , f ) } delete ( fdMap , f ) } else { fcMap [ target ] [ f ] = fcTargetMap [ f ] } } fcTargetMap = fcMap [ target ] for slctKey := range selectFieldTypeMap { if trainStmt . Label . GetFieldDesc ( ) [ 0 ] . Name == slctKey { continue } if fcList , ok := fcTargetMap [ slctKey ] ; ok { err := updateFeatureColumn ( fcList , fdMap ) if err != nil { return err } } else { if len ( columnTargets ) > 1 { continue } err := newFeatureColumn ( fcTargetMap , fdMap , slctKey ) if err != nil { return err } } } } return nil }
deriveFeatureColumn will fill in "fcMap" with derivated FeatureColumns.
deriveFeatureColumn will fill in " fcMap " with derivated FeatureColumns .
// 1. Infer omitted category_id_column for embedding_columns // 2. Add derivated feature column. // // need to store FeatureColumn under it's target in case of // the same column used for different target, e.g. // COLUMN EMBEDDING(c1) for deep //        EMBEDDING(c2) for deep //        EMBEDDING(c1) for wide // create map for current target // Try as regex to match the selected fields // ================== MAIN LOOP ================== // Update or generate FeatureColumn for each selected field: // skip label field // if column clause have more than one target, each target should specify the // full list of the columns to use.