How to use GT method of types Package

Best Ginkgo code snippet using types.GT

generator.go

Source:generator.go Github

copy

Full Screen

1package main2import (3 "bytes"4 "encoding/json"5 "fmt"6 "go/format"7 "io/ioutil"8 "log"9 "os"10 "path/filepath"11 "regexp"12 "sort"13 "strings"14 "unicode"15 "gopkg.in/alecthomas/kingpin.v2"16 "github.com/gedex/inflector"17 "github.com/idubinskiy/schematyper/stringset"18)19//go:generate schematyper --root-type=metaSchema --prefix=meta metaschema.json20var (21 outToStdout = kingpin.Flag("console", "output to console instead of file").Default("false").Short('c').Bool()22 outputFile = kingpin.Flag("out-file", "filename for output; default is <schema>_schematype.go").Short('o').String()23 packageName = kingpin.Flag("package", `package name for generated file; default is "main"`).Default("main").String()24 rootTypeName = kingpin.Flag("root-type", `name of root type; default is generated from the filename`).String()25 typeNamesPrefix = kingpin.Flag("prefix", `prefix for non-root types`).String()26 ptrForOmit = kingpin.Flag("ptr-for-omit", "use a pointer to a struct for an object property that is represented as a struct if the property is not required (i.e., has omitempty tag)").Default("false").Bool()27 inputFile = kingpin.Arg("input", "file containing a valid JSON schema").Required().ExistingFile()28)29type structField struct {30 Name string31 TypeRef string32 TypePrefix string33 Nullable bool34 PropertyName string35 Required bool36 Embedded bool37 PtrForOmit bool38}39type structFields []structField40func (s structFields) Len() int {41 return len(s)42}43func (s structFields) Less(i, j int) bool {44 return s[i].Name < s[j].Name45}46func (s structFields) Swap(i, j int) {47 s[i], s[j] = s[j], s[i]48}49type goType struct {50 Name string51 TypeRef string52 TypePrefix string53 Nullable bool54 Fields structFields55 Comment string56 parentPath string57 origTypeName string58 ambiguityDepth int59}60func (gt goType) print(buf *bytes.Buffer) {61 if gt.Comment != "" {62 commentLines := strings.Split(gt.Comment, "\n")63 for _, line := range commentLines {64 buf.WriteString(fmt.Sprintf("// %s\n", line))65 }66 }67 typeStr := gt.TypePrefix68 baseType, ok := types[gt.TypeRef]69 if ok {70 typeStr += baseType.Name71 }72 buf.WriteString(fmt.Sprintf("type %s %s", gt.Name, typeStr))73 if typeStr != typeStruct {74 buf.WriteString("\n")75 return76 }77 buf.WriteString(" {\n")78 sort.Stable(gt.Fields)79 for _, sf := range gt.Fields {80 sfTypeStr := sf.TypePrefix81 sfBaseType, ok := types[sf.TypeRef]82 if ok {83 sfTypeStr += sfBaseType.Name84 }85 if sf.Nullable && sfTypeStr != typeEmptyInterface {86 sfTypeStr = "*" + sfTypeStr87 }88 var tagString string89 if !sf.Embedded {90 tagString = "`json:\"" + sf.PropertyName91 if !sf.Required {92 if *ptrForOmit && sf.PtrForOmit && !sf.Nullable {93 sfTypeStr = "*" + sfTypeStr94 }95 tagString += ",omitempty"96 }97 tagString += "\"`"98 }99 buf.WriteString(fmt.Sprintf("%s %s %s\n", sf.Name, sfTypeStr, tagString))100 }101 buf.WriteString("}\n")102}103type goTypes []goType104func (t goTypes) Len() int {105 return len(t)106}107func (t goTypes) Less(i, j int) bool {108 return t[i].Name < t[j].Name109}110func (t goTypes) Swap(i, j int) {111 t[i], t[j] = t[j], t[i]112}113var needTimeImport bool114const (115 typeString = "string"116 typeInteger = "integer"117 typeInt = "int"118 typeNumber = "number"119 typeFloat64 = "float64"120 typeBoolean = "boolean"121 typeBool = "bool"122 typeNull = "null"123 typeNil = "nil"124 typeObject = "object"125 typeArray = "array"126 typeEmptyInterface = "interface{}"127 typeEmptyInterfaceSlice = "[]interface{}"128 typeTime = "time.Time"129 typeStruct = "struct"130)131var typeStrings = map[string]string{132 typeString: typeString,133 typeInteger: typeInt,134 typeNumber: typeFloat64,135 typeBoolean: typeBool,136 typeNull: typeNil,137 typeObject: typeObject,138 typeArray: typeArray,139}140func getTypeString(jsonType, format string) string {141 if format == "date-time" {142 needTimeImport = true143 return typeTime144 }145 if ts, ok := typeStrings[jsonType]; ok {146 return ts147 }148 return typeEmptyInterface149}150// copied from golint (https://github.com/golang/lint/blob/4946cea8b6efd778dc31dc2dbeb919535e1b7529/lint.go#L701)151var commonInitialisms = stringset.New(152 "API",153 "ASCII",154 "CPU",155 "CSS",156 "DNS",157 "EOF",158 "GUID",159 "HTML",160 "HTTP",161 "HTTPS",162 "ID",163 "IP",164 "JSON",165 "LHS",166 "QPS",167 "RAM",168 "RHS",169 "RPC",170 "SLA",171 "SMTP",172 "SQL",173 "SSH",174 "TCP",175 "TLS",176 "TTL",177 "UDP",178 "UI",179 "UID",180 "UUID",181 "URI",182 "URL",183 "UTF8",184 "VM",185 "XML",186 "XSRF",187 "XSS",188)189func dashedToWords(s string) string {190 return regexp.MustCompile("-|_").ReplaceAllString(s, " ")191}192func camelCaseToWords(s string) string {193 return regexp.MustCompile(`([\p{Ll}\p{N}])(\p{Lu})`).ReplaceAllString(s, "$1 $2")194}195func getExportedIdentifierPart(part string) string {196 upperedPart := strings.ToUpper(part)197 if commonInitialisms.Has(upperedPart) {198 return upperedPart199 }200 return strings.Title(strings.ToLower(part))201}202func generateIdentifier(origName string, exported bool) string {203 spacedName := camelCaseToWords(dashedToWords(origName))204 titledName := strings.Title(spacedName)205 nameParts := strings.Split(titledName, " ")206 for i, part := range nameParts {207 nameParts[i] = getExportedIdentifierPart(part)208 }209 if !exported {210 nameParts[0] = strings.ToLower(nameParts[0])211 }212 rawName := strings.Join(nameParts, "")213 // make sure we build a valid identifier214 buf := &bytes.Buffer{}215 for pos, char := range rawName {216 if unicode.IsLetter(char) || char == '_' || (unicode.IsDigit(char) && pos > 0) {217 buf.WriteRune(char)218 }219 }220 return buf.String()221}222func generateTypeName(origName string) string {223 if *packageName != "main" || *typeNamesPrefix != "" {224 return *typeNamesPrefix + generateIdentifier(origName, true)225 }226 return generateIdentifier(origName, false)227}228func generateFieldName(origName string) string {229 return generateIdentifier(origName, true)230}231func getTypeSchema(typeInterface interface{}) *metaSchema {232 typeSchemaJSON, _ := json.Marshal(typeInterface)233 var typeSchema metaSchema234 json.Unmarshal(typeSchemaJSON, &typeSchema)235 return &typeSchema236}237func getTypeSchemas(typeInterface interface{}) map[string]*metaSchema {238 typeSchemasJSON, _ := json.Marshal(typeInterface)239 var typeSchemas map[string]*metaSchema240 json.Unmarshal(typeSchemasJSON, &typeSchemas)241 return typeSchemas242}243func singularize(plural string) string {244 singular := inflector.Singularize(plural)245 if singular == plural {246 singular += "Item"247 }248 return singular249}250func parseAdditionalProperties(ap interface{}) (hasAddl bool, addlSchema *metaSchema) {251 switch ap := ap.(type) {252 case bool:253 return ap, nil254 case map[string]interface{}:255 return true, getTypeSchema(ap)256 default:257 return258 }259}260type deferredType struct {261 schema *metaSchema262 name string263 desc string264 parentPath string265}266type stringSetMap map[string]stringset.StringSet267func (m stringSetMap) addTo(set, val string) {268 if m[set] == nil {269 m[set] = stringset.New()270 }271 m[set].Add(val)272}273func (m stringSetMap) removeFrom(set, val string) {274 if m[set] == nil {275 return276 }277 m[set].Remove(val)278}279func (m stringSetMap) existsIn(set, val string) bool {280 if m[set] == nil {281 return false282 }283 return m[set].Has(val)284}285func (m stringSetMap) delete(set string) {286 delete(m, set)287}288func (m stringSetMap) has(set string) bool {289 _, ok := m[set]290 return ok291}292var types = make(map[string]goType)293var deferredTypes = make(map[string]deferredType)294var typesByName = make(stringSetMap)295var transitiveRefs = make(map[string]string)296func processType(s *metaSchema, pName, pDesc, path, parentPath string) (typeRef string) {297 if len(s.Definitions) > 0 {298 parseDefs(s, path)299 }300 var gt goType301 // avoid 'recursive type' problem, at least for the root type302 if path == "#" {303 gt.Nullable = true304 }305 if s.Ref != "" {306 ref, ok := transitiveRefs[s.Ref]307 if !ok {308 ref = s.Ref309 }310 if _, ok := types[ref]; ok {311 transitiveRefs[path] = ref312 return ref313 }314 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}315 return ""316 }317 gt.parentPath = parentPath318 if path == "#" {319 gt.origTypeName = *rootTypeName320 gt.Name = *rootTypeName321 } else {322 gt.origTypeName = s.Title323 if gt.origTypeName == "" {324 gt.origTypeName = pName325 }326 if gt.Name = generateTypeName(gt.origTypeName); gt.Name == "" {327 log.Fatalln("Can't generate type without name.")328 }329 }330 typeRef = path331 gt.Comment = s.Description332 if gt.Comment == "" {333 gt.Comment = pDesc334 }335 required := stringset.New()336 for _, req := range s.Required {337 required.Add(string(req))338 }339 defer func() {340 types[path] = gt341 typesByName.addTo(gt.Name, path)342 }()343 var jsonType string344 switch schemaType := s.Type.(type) {345 case []interface{}:346 if len(schemaType) == 2 && (schemaType[0] == typeNull || schemaType[1] == typeNull) {347 gt.Nullable = true348 jsonType = schemaType[0].(string)349 if jsonType == typeNull {350 jsonType = schemaType[1].(string)351 }352 }353 case string:354 jsonType = schemaType355 }356 hasAllOf := len(s.AllOf) > 0357 if jsonType == "" && hasAllOf {358 for index, allOfSchema := range s.AllOf {359 childPath := fmt.Sprintf("%s/allOf/%d", path, index)360 gotType := processType(&allOfSchema, fmt.Sprintf("%sEmbedded%d", pName, index), allOfSchema.Description, childPath, path)361 if gotType == "" {362 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}363 return ""364 }365 childType := types[gotType]366 // if any chid is an object, the parent is an object367 if childType.TypePrefix == "struct" {368 jsonType = "object"369 }370 // if any child is nullable, the parent is nullable371 if childType.Nullable {372 gt.Nullable = true373 }374 }375 }376 props := getTypeSchemas(s.Properties)377 hasProps := len(props) > 0378 hasAddlProps, addlPropsSchema := parseAdditionalProperties(s.AdditionalProperties)379 ts := getTypeString(jsonType, s.Format)380 switch ts {381 case typeObject:382 if gt.Name == "Properties" {383 panic(fmt.Errorf("props: %+v\naddlPropsSchema: %+v\n", props, addlPropsSchema))384 }385 if (hasProps || hasAllOf) && !hasAddlProps {386 gt.TypePrefix = typeStruct387 } else if !hasProps && !hasAllOf && hasAddlProps && addlPropsSchema != nil {388 singularName := singularize(gt.origTypeName)389 gotType := processType(addlPropsSchema, singularName, s.Description, path+"/additionalProperties", path)390 if gotType == "" {391 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}392 return ""393 }394 gt.TypePrefix = "map[string]"395 gt.TypeRef = gotType396 } else {397 gt.TypePrefix = "map[string]interface{}"398 }399 case typeArray:400 switch arrayItemType := s.Items.(type) {401 case []interface{}:402 if len(arrayItemType) == 1 {403 singularName := singularize(gt.origTypeName)404 typeSchema := getTypeSchema(arrayItemType[0])405 gotType := processType(typeSchema, singularName, s.Description, path+"/items/0", path)406 if gotType == "" {407 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}408 return ""409 }410 gt.TypePrefix = "[]"411 gt.TypeRef = gotType412 } else {413 gt.TypePrefix = typeEmptyInterfaceSlice414 }415 case interface{}:416 singularName := singularize(gt.origTypeName)417 typeSchema := getTypeSchema(arrayItemType)418 gotType := processType(typeSchema, singularName, s.Description, path+"/items", path)419 if gotType == "" {420 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}421 return ""422 }423 gt.TypePrefix = "[]"424 gt.TypeRef = gotType425 default:426 gt.TypePrefix = typeEmptyInterfaceSlice427 }428 default:429 gt.TypePrefix = ts430 }431 for propName, propSchema := range props {432 sf := structField{433 PropertyName: propName,434 Required: required.Has(propName),435 }436 var fieldName string437 if propSchema.Title != "" {438 fieldName = propSchema.Title439 } else {440 fieldName = propName441 }442 if sf.Name = generateFieldName(fieldName); sf.Name == "" {443 log.Fatalln("Can't generate field without name.")444 }445 if propSchema.Ref != "" {446 if refType, ok := types[propSchema.Ref]; ok {447 sf.TypeRef, sf.Nullable = propSchema.Ref, refType.Nullable448 if refType.TypePrefix == typeStruct {449 sf.PtrForOmit = true450 }451 gt.Fields = append(gt.Fields, sf)452 continue453 }454 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}455 return ""456 }457 switch propType := propSchema.Type.(type) {458 case []interface{}:459 if len(propType) == 2 && (propType[0] == typeNull || propType[1] == typeNull) {460 sf.Nullable = true461 jsonType := propType[0]462 if jsonType == typeNull {463 jsonType = propType[1]464 }465 sf.TypePrefix = getTypeString(jsonType.(string), propSchema.Format)466 }467 case string:468 sf.TypePrefix = getTypeString(propType, propSchema.Format)469 case nil:470 sf.TypePrefix = typeEmptyInterface471 }472 refPath := path + "/properties/" + propName473 props := getTypeSchemas(propSchema.Properties)474 hasProps := len(props) > 0475 hasAddlProps, addlPropsSchema := parseAdditionalProperties(propSchema.AdditionalProperties)476 if sf.TypePrefix == typeObject {477 if hasProps && !hasAddlProps {478 gotType := processType(propSchema, sf.Name, propSchema.Description, refPath, path)479 if gotType == "" {480 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}481 return ""482 }483 sf.TypePrefix = ""484 sf.TypeRef = gotType485 sf.PtrForOmit = true486 } else if !hasProps && hasAddlProps && addlPropsSchema != nil {487 singularName := singularize(propName)488 gotType := processType(addlPropsSchema, singularName, propSchema.Description, refPath+"/additionalProperties", path)489 if gotType == "" {490 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}491 return ""492 }493 sf.TypePrefix = "map[string]"494 sf.TypeRef = gotType495 } else {496 sf.TypePrefix = "map[string]interface{}"497 }498 } else if sf.TypePrefix == typeArray {499 switch arrayItemType := propSchema.Items.(type) {500 case []interface{}:501 if len(arrayItemType) == 1 {502 singularName := singularize(propName)503 typeSchema := getTypeSchema(arrayItemType[0])504 gotType := processType(typeSchema, singularName, propSchema.Description, refPath+"/items/0", path)505 if gotType == "" {506 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}507 return ""508 }509 sf.TypePrefix = "[]"510 sf.TypeRef = gotType511 } else {512 sf.TypePrefix = typeEmptyInterfaceSlice513 }514 case interface{}:515 singularName := singularize(propName)516 typeSchema := getTypeSchema(arrayItemType)517 gotType := processType(typeSchema, singularName, propSchema.Description, refPath+"/items", path)518 if gotType == "" {519 deferredTypes[path] = deferredType{schema: s, name: pName, desc: pDesc, parentPath: parentPath}520 return ""521 }522 sf.TypePrefix = "[]"523 sf.TypeRef = gotType524 default:525 sf.TypePrefix = typeEmptyInterfaceSlice526 }527 }528 gt.Fields = append(gt.Fields, sf)529 }530 for index := range s.AllOf {531 sf := structField{532 Embedded: true,533 }534 childPath := fmt.Sprintf("%s/allOf/%d", path, index)535 if _, ok := transitiveRefs[childPath]; ok {536 childPath = transitiveRefs[childPath]537 }538 sf.TypeRef = childPath539 gt.Fields = append(gt.Fields, sf)540 }541 return542}543func processDeferred() {544 for len(deferredTypes) > 0 {545 startDeferredPaths, _ := stringset.FromMapKeys(deferredTypes)546 for _, path := range startDeferredPaths.Sorted() {547 deferred := deferredTypes[path]548 name := processType(deferred.schema, deferred.name, deferred.desc, path, deferred.parentPath)549 if name != "" {550 delete(deferredTypes, path)551 }552 }553 // if the list is the same as before, we're stuck554 endDeferredPaths, _ := stringset.FromMapKeys(deferredTypes)555 if endDeferredPaths.Equals(startDeferredPaths) {556 log.Fatalln("Can't resolve:", startDeferredPaths)557 }558 }559}560func dedupeTypes() {561 for len(typesByName) > 0 {562 // clear all singles first; otherwise some types will not be disambiguated563 for name, dupes := range typesByName {564 if len(dupes) == 1 {565 typesByName.delete(name)566 }567 }568 newTypesByName := make(stringSetMap)569 typeNames, _ := stringset.FromMapKeys(typesByName)570 sortedTypeNames := typeNames.Sorted()571 for _, name := range sortedTypeNames {572 dupes := typesByName[name]573 // delete these dupes; will put back in as necessary in subsequent loop574 typesByName.delete(name)575 dupesLoop:576 for _, dupePath := range dupes.Sorted() {577 gt := types[dupePath]578 gt.ambiguityDepth++579 topChild := gt580 var parent goType581 for i := 0; i < gt.ambiguityDepth; i++ {582 parent = types[topChild.parentPath]583 // handle parents before children to avoid stuttering584 if typesByName.has(parent.Name) {585 // add back the child to be processed later586 newTypesByName.addTo(gt.Name, dupePath)587 gt.ambiguityDepth--588 continue dupesLoop589 }590 topChild = parent591 }592 if parent.origTypeName == "" {593 log.Fatalln("Can't disabiguate:", dupes)594 }595 gt.origTypeName = parent.origTypeName + "-" + gt.origTypeName596 gt.Name = generateTypeName(gt.origTypeName)597 types[dupePath] = gt598 // add with new name in case we still have dupes599 newTypesByName.addTo(gt.Name, dupePath)600 }601 }602 typesByName = newTypesByName603 }604}605func parseDefs(s *metaSchema, path string) {606 defs := getTypeSchemas(s.Definitions)607 for defName, defSchema := range defs {608 name := processType(defSchema, defName, defSchema.Description, path+"/definitions/"+defName, path)609 if name == "" {610 deferredTypes[path+"/definitions/"+defName] = deferredType{schema: defSchema, name: defName, desc: defSchema.Description, parentPath: path}611 }612 }613}614func main() {615 kingpin.Parse()616 file, err := ioutil.ReadFile(*inputFile)617 if err != nil {618 log.Fatalln("Error reading file:", err)619 }620 var s metaSchema621 if err = json.Unmarshal(file, &s); err != nil {622 log.Fatalln("Error parsing JSON:", err)623 }624 schemaName := strings.Split(filepath.Base(*inputFile), ".")[0]625 if *rootTypeName == "" {626 exported := *packageName != "main"627 *rootTypeName = generateIdentifier(schemaName, exported)628 }629 processType(&s, *rootTypeName, s.Description, "#", "")630 processDeferred()631 dedupeTypes()632 var resultSrc bytes.Buffer633 resultSrc.WriteString(fmt.Sprintln("package", *packageName))634 resultSrc.WriteString(fmt.Sprintf("\n// generated by \"%s\" -- DO NOT EDIT\n", strings.Join(os.Args, " ")))635 resultSrc.WriteString("\n")636 if needTimeImport {637 resultSrc.WriteString("import \"time\"\n")638 }639 typesSlice := make(goTypes, 0, len(types))640 for _, gt := range types {641 typesSlice = append(typesSlice, gt)642 }643 sort.Stable(typesSlice)644 for _, gt := range typesSlice {645 gt.print(&resultSrc)646 resultSrc.WriteString("\n")647 }648 formattedSrc, err := format.Source(resultSrc.Bytes())649 if err != nil {650 fmt.Println(resultSrc.String())651 log.Fatalln("Error running gofmt:", err)652 }653 if *outToStdout {654 fmt.Print(string(formattedSrc))655 } else {656 outputFileName := *outputFile657 if outputFileName == "" {658 compactSchemaName := strings.ToLower(*rootTypeName)659 outputFileName = fmt.Sprintf("%s_schematype.go", compactSchemaName)660 }661 err = ioutil.WriteFile(outputFileName, formattedSrc, 0644)662 if err != nil {663 log.Fatalf("Error writing to %s: %s\n", outputFileName, err)664 }665 }666}...

Full Screen

Full Screen

gt.go

Source:gt.go Github

copy

Full Screen

1// Copyright 2022 Matrix Origin2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14package operator15import (16 "errors"17 "github.com/matrixorigin/matrixone/pkg/container/nulls"18 "github.com/matrixorigin/matrixone/pkg/container/types"19 "github.com/matrixorigin/matrixone/pkg/container/vector"20 "github.com/matrixorigin/matrixone/pkg/vectorize/gt"21 "github.com/matrixorigin/matrixone/pkg/vectorize/lt"22 "github.com/matrixorigin/matrixone/pkg/vm/process"23)24func great[T OrderedValue](d1, d2 interface{}, aScale, bScale int32) bool {25 l, v := d1.(T), d2.(T)26 return l > v27}28func great_B(d1, d2 interface{}, aScale, bScale int32) bool {29 l, v := d1.(bool), d2.(bool)30 return l && !v31}32func great_D(d1, d2 interface{}, aScale, bScale int32) bool {33 l, v := d1.(types.Decimal128), d2.(types.Decimal128)34 return types.CompareDecimal128Decimal128(l, v, aScale, bScale) > 035}36type GtOpFunc = func(d1, d2 interface{}, aScale, bScale int32) bool37var GtOpFuncMap = map[int]GtOpFunc{}38var GtOpFuncVec = []GtOpFunc{39 great[int8], great[int16], great[int32], great[int64], great[uint8], great[uint16], great[uint32],40 great[uint64], great[float32], great[float64], great[string], great_B, great[types.Date],41 great[types.Datetime], great[types.Decimal64], great_D,42}43func InitGtOpFuncMap() {44 for i := 0; i < len(GtOpFuncVec); i++ {45 GtOpFuncMap[i] = GtOpFuncVec[i]46 }47}48var StrGtOpFuncMap = map[int]StrCompOpFunc{}49var StrGtOpFuncVec = []StrCompOpFunc{50 greatCol_Col, greatCol_Const, greatConst_Col, greatConst_Const,51}52func greatCol_Col(d1, d2 *vector.Vector) ([]bool, error) {53 lvs, ok := d1.Col.(*types.Bytes)54 if !ok {55 return nil, errors.New("the left col type is not *types.Bytes")56 }57 rvs, ok := d2.Col.(*types.Bytes)58 if !ok {59 return nil, errors.New("the right col type is not *types.Bytes")60 }61 rs := make([]int64, len(lvs.Lengths))62 rs = gt.StrGt(lvs, rvs, rs)63 col := make([]bool, len(lvs.Lengths))64 rsi := 065 for i := 0; i < len(col); i++ {66 if rsi >= len(rs) {67 break68 }69 if int64(i) == rs[rsi] {70 col[i] = true71 rsi++72 }73 if nulls.Contains(d1.Nsp, uint64(i)) || nulls.Contains(d2.Nsp, uint64(i)) {74 col[i] = false75 }76 }77 return col, nil78}79func greatCol_Const(d1, d2 *vector.Vector) ([]bool, error) {80 lvs, ok := d1.Col.(*types.Bytes)81 if !ok {82 return nil, errors.New("the left col type is not *types.Bytes")83 }84 rvs, ok := d2.Col.(*types.Bytes)85 if !ok {86 return nil, errors.New("the right col type is not *types.Bytes")87 }88 rs := make([]int64, len(lvs.Lengths))89 rs = lt.StrLtScalar(rvs.Data, lvs, rs)90 col := make([]bool, len(lvs.Lengths))91 rsi := 092 for i := 0; i < len(col); i++ {93 if rsi >= len(rs) {94 break95 }96 if int64(i) == rs[rsi] {97 col[i] = true98 rsi++99 }100 if nulls.Contains(d1.Nsp, uint64(i)) {101 col[i] = false102 }103 }104 return col, nil105}106func greatConst_Col(d1, d2 *vector.Vector) ([]bool, error) {107 lvs, ok := d1.Col.(*types.Bytes)108 if !ok {109 return nil, errors.New("the left col type is not *types.Bytes")110 }111 rvs, ok := d2.Col.(*types.Bytes)112 if !ok {113 return nil, errors.New("the right col type is not *types.Bytes")114 }115 rs := make([]int64, len(rvs.Lengths))116 rs = gt.StrGtScalar(lvs.Data, rvs, rs)117 col := make([]bool, len(rvs.Lengths))118 rsi := 0119 for i := 0; i < len(col); i++ {120 if rsi >= len(rs) {121 break122 }123 if int64(i) == rs[rsi] {124 col[i] = true125 rsi++126 }127 if nulls.Contains(d2.Nsp, uint64(i)) {128 col[i] = false129 }130 }131 return col, nil132}133func greatConst_Const(d1, d2 *vector.Vector) ([]bool, error) {134 lvs, ok := d1.Col.(*types.Bytes)135 if !ok {136 return nil, errors.New("the left col type is not *types.Bytes")137 }138 rvs, ok := d2.Col.(*types.Bytes)139 if !ok {140 return nil, errors.New("the right col type is not *types.Bytes")141 }142 return []bool{string(lvs.Data) > string(rvs.Data)}, nil143}144func InitStrGtOpFuncMap() {145 for i := 0; i < len(StrGtOpFuncVec); i++ {146 StrGtOpFuncMap[i] = StrGtOpFuncVec[i]147 }148}149func ColGtCol[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {150 n := GetRetColLen[T](lv)151 vec, err := proc.AllocVector(proc.GetBoolTyp(lv.Typ), int64(n)*1)152 if err != nil {153 return nil, err154 }155 nulls.Or(lv.Nsp, rv.Nsp, vec.Nsp)156 col, err := GetRetCol[T](lv, rv, col_col, GtOpFuncMap, StrGtOpFuncMap)157 if err != nil {158 return nil, err159 }160 vector.SetCol(vec, col)161 return vec, nil162}163func ColGtConst[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {164 n := GetRetColLen[T](lv)165 vec, err := proc.AllocVector(proc.GetBoolTyp(lv.Typ), int64(n)*1)166 if err != nil {167 return nil, err168 }169 nulls.Or(lv.Nsp, rv.Nsp, vec.Nsp)170 col, err := GetRetCol[T](lv, rv, col_const, GtOpFuncMap, StrGtOpFuncMap)171 if err != nil {172 return nil, err173 }174 vector.SetCol(vec, col)175 return vec, nil176}177func ColGtNull[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {178 return proc.AllocScalarNullVector(proc.GetBoolTyp(lv.Typ)), nil179}180func ConstGtCol[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {181 n := GetRetColLen[T](rv)182 vec, err := proc.AllocVector(proc.GetBoolTyp(lv.Typ), int64(n)*1)183 if err != nil {184 return nil, err185 }186 nulls.Or(lv.Nsp, rv.Nsp, vec.Nsp)187 col, err := GetRetCol[T](lv, rv, const_col, GtOpFuncMap, StrGtOpFuncMap)188 if err != nil {189 return nil, err190 }191 vector.SetCol(vec, col)192 return vec, nil193}194func ConstGtConst[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {195 vec := proc.AllocScalarVector(proc.GetBoolTyp(lv.Typ))196 col, err := GetRetCol[T](lv, rv, const_const, GtOpFuncMap, StrGtOpFuncMap)197 if err != nil {198 return nil, err199 }200 vector.SetCol(vec, col)201 return vec, nil202}203func ConstGtNull[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {204 return proc.AllocScalarNullVector(proc.GetBoolTyp(lv.Typ)), nil205}206func NullGtCol[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {207 return proc.AllocScalarNullVector(proc.GetBoolTyp(lv.Typ)), nil208}209func NullGtConst[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {210 return proc.AllocScalarNullVector(proc.GetBoolTyp(lv.Typ)), nil211}212func NullGtNull[T DataValue](lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error) {213 return proc.AllocScalarNullVector(proc.GetBoolTyp(lv.Typ)), nil214}215type GtFunc = func(lv, rv *vector.Vector, proc *process.Process) (*vector.Vector, error)216var GtFuncMap = map[int]GtFunc{}217var GtFuncVec = []GtFunc{218 ColGtCol[int8], ColGtCol[int16], ColGtCol[int32], ColGtCol[int64], ColGtCol[uint8], ColGtCol[uint16],219 ColGtCol[uint32], ColGtCol[uint64], ColGtCol[float32], ColGtCol[float64], ColGtCol[string], ColGtCol[bool],220 ColGtCol[types.Date], ColGtCol[types.Datetime], ColGtCol[types.Decimal64], ColGtCol[types.Decimal128],221 ColGtConst[int8], ColGtConst[int16], ColGtConst[int32], ColGtConst[int64], ColGtConst[uint8], ColGtConst[uint16],222 ColGtConst[uint32], ColGtConst[uint64], ColGtConst[float32], ColGtConst[float64], ColGtConst[string], ColGtConst[bool],223 ColGtConst[types.Date], ColGtConst[types.Datetime], ColGtConst[types.Decimal64], ColGtConst[types.Decimal128],224 ColGtNull[int8], ColGtNull[int16], ColGtNull[int32], ColGtNull[int64], ColGtNull[uint8], ColGtNull[uint16],225 ColGtNull[uint32], ColGtNull[uint64], ColGtNull[float32], ColGtNull[float64], ColGtNull[string], ColGtNull[bool],226 ColGtNull[types.Date], ColGtNull[types.Datetime], ColGtNull[types.Decimal64], ColGtNull[types.Decimal128],227 ConstGtCol[int8], ConstGtCol[int16], ConstGtCol[int32], ConstGtCol[int64], ConstGtCol[uint8], ConstGtCol[uint16],228 ConstGtCol[uint32], ConstGtCol[uint64], ConstGtCol[float32], ConstGtCol[float64], ConstGtCol[string], ConstGtCol[bool],229 ConstGtCol[types.Date], ConstGtCol[types.Datetime], ConstGtCol[types.Decimal64], ConstGtCol[types.Decimal128],230 ConstGtConst[int8], ConstGtConst[int16], ConstGtConst[int32], ConstGtConst[int64], ConstGtConst[uint8], ConstGtConst[uint16],231 ConstGtConst[uint32], ConstGtConst[uint64], ConstGtConst[float32], ConstGtConst[float64], ConstGtConst[string], ConstGtConst[bool],232 ConstGtConst[types.Date], ConstGtConst[types.Datetime], ConstGtConst[types.Decimal64], ConstGtConst[types.Decimal128],233 ConstGtNull[int8], ConstGtNull[int16], ConstGtNull[int32], ConstGtNull[int64], ConstGtNull[uint8], ConstGtNull[uint16],234 ConstGtNull[uint32], ConstGtNull[uint64], ConstGtNull[float32], ConstGtNull[float64], ConstGtNull[string], ConstGtNull[bool],235 ConstGtNull[types.Date], ConstGtNull[types.Datetime], ConstGtNull[types.Decimal64], ConstGtNull[types.Decimal128],236 NullGtCol[int8], NullGtCol[int16], NullGtCol[int32], NullGtCol[int64], NullGtCol[uint8], NullGtCol[uint16],237 NullGtCol[uint32], NullGtCol[uint64], NullGtCol[float32], NullGtCol[float64], NullGtCol[string], NullGtCol[bool],238 NullGtCol[types.Date], NullGtCol[types.Datetime], NullGtCol[types.Decimal64], NullGtCol[types.Decimal128],239 NullGtConst[int8], NullGtConst[int16], NullGtConst[int32], NullGtConst[int64], NullGtConst[uint8], NullGtConst[uint16],240 NullGtConst[uint32], NullGtConst[uint64], NullGtConst[float32], NullGtConst[float64], NullGtConst[string], NullGtConst[bool],241 NullGtConst[types.Date], NullGtConst[types.Datetime], NullGtConst[types.Decimal64], NullGtConst[types.Decimal128],242 NullGtNull[int8], NullGtNull[int16], NullGtNull[int32], NullGtNull[int64], NullGtNull[uint8], NullGtNull[uint16],243 NullGtNull[uint32], NullGtNull[uint64], NullGtNull[float32], NullGtNull[float64], NullGtNull[string], NullGtNull[bool],244 NullGtNull[types.Date], NullGtNull[types.Datetime], NullGtNull[types.Decimal64], NullGtNull[types.Decimal128],245}246func InitGtFuncMap() {247 InitGtOpFuncMap()248 InitStrGtOpFuncMap()249 for i := 0; i < len(GtFuncVec); i++ {250 GtFuncMap[i] = GtFuncVec[i]251 }252}253func GtDataValue[T DataValue](vectors []*vector.Vector, proc *process.Process) (*vector.Vector, error) {254 lv := vectors[0]255 rv := vectors[1]256 lt, rt := GetTypeID(lv), GetTypeID(rv)257 dataID := GetDatatypeID[T]()258 vec, err := GtFuncMap[(lt*3+rt)*dataTypeNum+dataID](lv, rv, proc)259 if err != nil {260 return nil, errors.New("Gt function: " + err.Error())261 }262 return vec, nil263}...

Full Screen

Full Screen

GT

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 ret = max(a, b)4 fmt.Printf("Max value is : %d", ret)5}6func max(num1, num2 int) int {7 if (num1 > num2) {8 } else {9 }10}

Full Screen

Full Screen

GT

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "types"3func main() {4 a.GT()5 b.GT()6 c.GT()7 d.GT()8}9import "fmt"10type A struct {11}12func (a A) GT() {13 fmt.Println("A")14}15type B struct {16}17func (b B) GT() {18 fmt.Println("B")19}20type C struct {21}22func (c C) GT() {23 fmt.Println("C")24}25type D struct {26}27func (d D) GT() {28 fmt.Println("D")29}30import "fmt"31import "types"32func GT(t types.T) {33 t.GT()34}35func main() {36 GT(a)37 GT(b)38 GT(c)39 GT(d)40}41import "fmt"42import "types"43func GT(ts []types.T) {44 for _, t := range ts {45 t.GT()46 }47}48func main() {49 GT([]types.T{a, b, c, d})50}

Full Screen

Full Screen

GT

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scanf("%d", &a)5 fmt.Scanf("%d", &b)6 if a.GT(b) {7 fmt.Println("a is greater than b")8 } else {9 fmt.Println("b is greater than a")10 }11}12func (a Int) GT(b Int) bool {13 if a > b {14 } else {15 }16}

Full Screen

Full Screen

GT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("types.GT(1, 2)=", types.GT(1, 2))4 fmt.Println("types.GT(2, 1)=", types.GT(2, 1))5 fmt.Println("types.GT(2, 2)=", types.GT(2, 2))6}7types.GT(1, 2)= false8types.GT(2, 1)= true9types.GT(2, 2)= false10import (11func main() {12 fmt.Println("types.LT(1, 2)=", types.LT(1, 2))13 fmt.Println("types.LT(2, 1)=", types.LT(2, 1))14 fmt.Println("types.LT(2, 2)=", types.LT(2, 2))15}16types.LT(1, 2)= true17types.LT(2, 1)= false18types.LT(2, 2)= false19import (20func main() {21 fmt.Println("types.EQ(1, 2)=", types.EQ(1, 2))22 fmt.Println("types.EQ(2, 1)=", types.EQ(2, 1))23 fmt.Println("types.EQ(2, 2)=", types.EQ(2, 2))24}25types.EQ(1, 2)= false26types.EQ(2, 1)= false27types.EQ(2, 2)= true28import (29func main() {30 fmt.Println("types.GE(1, 2)=", types.GE(1, 2))

Full Screen

Full Screen

GT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var s []int = []int{1, 2, 3}4 var t []string = []string{"a", "b", "c"}5 var u [3]int = [3]int{1, 2, 3}6 var v [3]string = [3]string{"a", "b", "c"}7 var w map[int]string = map[int]string{1: "a", 2: "b", 3: "c"}8 var x map[string]int = map[string]int{"a": 1, "b": 2, "c": 3}9 var y struct {10 }11 var z interface{} = "hello"12 var aa interface{} = 1013 var bb interface{} = 10.014 var cc interface{} = false15 var dd interface{} = 1 + 2i16 var ee interface{} = 'a'17 var ff interface{} = []int{1, 2, 3}18 var gg interface{} = [3]int{1, 2, 3}19 var hh interface{} = map[int]string{1: "a", 2: "b", 3: "c"}20 var ii interface{} = struct {21 }{}22 var jj interface{} = nil23 var kk interface{} = (*int)(nil)24 var ll interface{} = (*[]int)(nil)25 var mm interface{} = (*[3]int)(nil)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful