ソースを参照

refactor: move custom schema out of core

It depends on plugin framework which will add 2MB+ to the core binary

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
Jiyong Huang 2 年 前
コミット
3b8f4524ec

+ 1 - 3
internal/converter/converter.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package converter
 import (
 import (
 	"fmt"
 	"fmt"
 	"github.com/lf-edge/ekuiper/internal/converter/binary"
 	"github.com/lf-edge/ekuiper/internal/converter/binary"
-	"github.com/lf-edge/ekuiper/internal/converter/custom"
 	"github.com/lf-edge/ekuiper/internal/converter/delimited"
 	"github.com/lf-edge/ekuiper/internal/converter/delimited"
 	"github.com/lf-edge/ekuiper/internal/converter/json"
 	"github.com/lf-edge/ekuiper/internal/converter/json"
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"github.com/lf-edge/ekuiper/pkg/ast"
@@ -40,7 +39,6 @@ var ( // init once and read only
 		message.FormatDelimited: func(_ string, _ string, delimiter string) (message.Converter, error) {
 		message.FormatDelimited: func(_ string, _ string, delimiter string) (message.Converter, error) {
 			return delimited.NewConverter(delimiter)
 			return delimited.NewConverter(delimiter)
 		},
 		},
-		message.FormatCustom: custom.LoadConverter,
 	}
 	}
 )
 )
 
 

+ 3 - 2
internal/converter/ext_protobuf.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
 // limitations under the License.
 // limitations under the License.
 
 
 //go:build schema || !core
 //go:build schema || !core
-// +build schema !core
 
 
 package converter
 package converter
 
 
 import (
 import (
+	"github.com/lf-edge/ekuiper/internal/converter/custom"
 	"github.com/lf-edge/ekuiper/internal/converter/protobuf"
 	"github.com/lf-edge/ekuiper/internal/converter/protobuf"
 	"github.com/lf-edge/ekuiper/internal/pkg/def"
 	"github.com/lf-edge/ekuiper/internal/pkg/def"
 	"github.com/lf-edge/ekuiper/internal/schema"
 	"github.com/lf-edge/ekuiper/internal/schema"
@@ -32,4 +32,5 @@ func init() {
 		}
 		}
 		return protobuf.NewConverter(ffs.SchemaFile, ffs.SoFile, schemaMessageName)
 		return protobuf.NewConverter(ffs.SchemaFile, ffs.SoFile, schemaMessageName)
 	}
 	}
+	converters[message.FormatCustom] = custom.LoadConverter
 }
 }

+ 7 - 1
internal/schema/inferer_custom.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@
 // See the License for the specific language governing permissions and
 // See the License for the specific language governing permissions and
 // limitations under the License.
 // limitations under the License.
 
 
+//go:build schema || !core
+
 package schema
 package schema
 
 
 import (
 import (
@@ -24,6 +26,10 @@ import (
 	"plugin"
 	"plugin"
 )
 )
 
 
+func init() {
+	inferes[message.FormatCustom] = InferCustom
+}
+
 func InferCustom(schemaFile string, messageName string) (ast.StreamFields, error) {
 func InferCustom(schemaFile string, messageName string) (ast.StreamFields, error) {
 	conf.Log.Infof("Load custom schema from file %s, for symbol Get%s", schemaFile, messageName)
 	conf.Log.Infof("Load custom schema from file %s, for symbol Get%s", schemaFile, messageName)
 	ffs, err := GetSchemaFile(def.CUSTOM, schemaFile)
 	ffs, err := GetSchemaFile(def.CUSTOM, schemaFile)

+ 6 - 1
internal/schema/inferer_custom_test.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -16,12 +16,17 @@ package schema
 
 
 import (
 import (
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/conf"
+	"github.com/lf-edge/ekuiper/internal/testx"
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
 	"testing"
 	"testing"
 )
 )
 
 
+func init() {
+	testx.InitEnv()
+}
+
 func TestInferCustom(t *testing.T) {
 func TestInferCustom(t *testing.T) {
 	// Prepare test schema file
 	// Prepare test schema file
 	dataDir, err := conf.GetDataLoc()
 	dataDir, err := conf.GetDataLoc()

+ 2 - 5
internal/schema/inferer.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -17,16 +17,13 @@ package schema
 import (
 import (
 	"fmt"
 	"fmt"
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"github.com/lf-edge/ekuiper/pkg/ast"
-	"github.com/lf-edge/ekuiper/pkg/message"
 	"strings"
 	"strings"
 )
 )
 
 
 type inferer func(schemaFileName string, SchemaMessageName string) (ast.StreamFields, error)
 type inferer func(schemaFileName string, SchemaMessageName string) (ast.StreamFields, error)
 
 
 var ( // init once and read only
 var ( // init once and read only
-	inferes = map[string]inferer{
-		message.FormatCustom: InferCustom,
-	}
+	inferes = map[string]inferer{}
 )
 )
 
 
 func InferFromSchemaFile(schemaType string, schemaId string) (ast.StreamFields, error) {
 func InferFromSchemaFile(schemaType string, schemaId string) (ast.StreamFields, error) {