How to use Format method of types Package

Best Testkube code snippet using types.Format

printf.go

Source:printf.go Github

copy

Full Screen

...414 return fn, fact.Kind415 }416 return fn, kindUnknown417}418// isFormatter reports whether t satisfies fmt.Formatter.419// The only interface method to look for is "Format(State, rune)".420func isFormatter(typ types.Type) bool {421 obj, _, _ := types.LookupFieldOrMethod(typ, false, nil, "Format")422 fn, ok := obj.(*types.Func)423 if !ok {424 return false425 }426 sig := fn.Type().(*types.Signature)427 return sig.Params().Len() == 2 &&428 sig.Results().Len() == 0 &&429 isNamed(sig.Params().At(0).Type(), "fmt", "State") &&430 types.Identical(sig.Params().At(1).Type(), types.Typ[types.Rune])431}432func isNamed(T types.Type, pkgpath, name string) bool {433 named, ok := T.(*types.Named)434 return ok && named.Obj().Pkg().Path() == pkgpath && named.Obj().Name() == name435}436// formatState holds the parsed representation of a printf directive such as "%3.*[4]d".437// It is constructed by parsePrintfVerb.438type formatState struct {439 verb rune // the format verb: 'd' for "%d"440 format string // the full format directive from % through verb, "%.3d".441 name string // Printf, Sprintf etc.442 flags []byte // the list of # + etc.443 argNums []int // the successive argument numbers that are consumed, adjusted to refer to actual arg in call444 firstArg int // Index of first argument after the format in the Printf call.445 // Used only during parse.446 pass *analysis.Pass447 call *ast.CallExpr448 argNum int // Which argument we're expecting to format now.449 hasIndex bool // Whether the argument is indexed.450 indexPending bool // Whether we have an indexed argument that has not resolved.451 nbytes int // number of bytes of the format string consumed.452}453// checkPrintf checks a call to a formatted print routine such as Printf.454func checkPrintf(pass *analysis.Pass, kind funcKind, call *ast.CallExpr, fn *types.Func) {455 format, idx := formatString(pass, call)456 if idx < 0 {457 if false {458 pass.Reportf(call.Lparen, "can't check non-constant format in call to %s", fn.Name())459 }460 return461 }462 firstArg := idx + 1 // Arguments are immediately after format string.463 if !strings.Contains(format, "%") {464 if len(call.Args) > firstArg {465 pass.Reportf(call.Lparen, "%s call has arguments but no formatting directives", fn.Name())466 }467 return468 }469 // Hard part: check formats against args.470 argNum := firstArg471 maxArgNum := firstArg472 anyIndex := false473 anyW := false474 for i, w := 0, 0; i < len(format); i += w {475 w = 1476 if format[i] != '%' {477 continue478 }479 state := parsePrintfVerb(pass, call, fn.Name(), format[i:], firstArg, argNum)480 if state == nil {481 return482 }483 w = len(state.format)484 if !okPrintfArg(pass, call, state) { // One error per format is enough.485 return486 }487 if state.hasIndex {488 anyIndex = true489 }490 if state.verb == 'w' {491 if kind != kindErrorf {492 pass.Reportf(call.Pos(), "%s call has error-wrapping directive %%w", state.name)493 return494 }495 if anyW {496 pass.Reportf(call.Pos(), "%s call has more than one error-wrapping directive %%w", state.name)497 return498 }499 anyW = true500 }501 if len(state.argNums) > 0 {502 // Continue with the next sequential argument.503 argNum = state.argNums[len(state.argNums)-1] + 1504 }505 for _, n := range state.argNums {506 if n >= maxArgNum {507 maxArgNum = n + 1508 }509 }510 }511 // Dotdotdot is hard.512 if call.Ellipsis.IsValid() && maxArgNum >= len(call.Args)-1 {513 return514 }515 // If any formats are indexed, extra arguments are ignored.516 if anyIndex {517 return518 }519 // There should be no leftover arguments.520 if maxArgNum != len(call.Args) {521 expect := maxArgNum - firstArg522 numArgs := len(call.Args) - firstArg523 pass.Reportf(call.Pos(), "%s call needs %v but has %v", fn.Name(), count(expect, "arg"), count(numArgs, "arg"))524 }525}526// parseFlags accepts any printf flags.527func (s *formatState) parseFlags() {528 for s.nbytes < len(s.format) {529 switch c := s.format[s.nbytes]; c {530 case '#', '0', '+', '-', ' ':531 s.flags = append(s.flags, c)532 s.nbytes++533 default:534 return535 }536 }537}538// scanNum advances through a decimal number if present.539func (s *formatState) scanNum() {540 for ; s.nbytes < len(s.format); s.nbytes++ {541 c := s.format[s.nbytes]542 if c < '0' || '9' < c {543 return544 }545 }546}547// parseIndex scans an index expression. It returns false if there is a syntax error.548func (s *formatState) parseIndex() bool {549 if s.nbytes == len(s.format) || s.format[s.nbytes] != '[' {550 return true551 }552 // Argument index present.553 s.nbytes++ // skip '['554 start := s.nbytes555 s.scanNum()556 ok := true557 if s.nbytes == len(s.format) || s.nbytes == start || s.format[s.nbytes] != ']' {558 ok = false559 s.nbytes = strings.Index(s.format, "]")560 if s.nbytes < 0 {561 s.pass.Reportf(s.call.Pos(), "%s format %s is missing closing ]", s.name, s.format)562 return false563 }564 }565 arg32, err := strconv.ParseInt(s.format[start:s.nbytes], 10, 32)566 if err != nil || !ok || arg32 <= 0 || arg32 > int64(len(s.call.Args)-s.firstArg) {567 s.pass.Reportf(s.call.Pos(), "%s format has invalid argument index [%s]", s.name, s.format[start:s.nbytes])568 return false569 }570 s.nbytes++ // skip ']'571 arg := int(arg32)572 arg += s.firstArg - 1 // We want to zero-index the actual arguments.573 s.argNum = arg574 s.hasIndex = true575 s.indexPending = true576 return true577}578// parseNum scans a width or precision (or *). It returns false if there's a bad index expression.579func (s *formatState) parseNum() bool {580 if s.nbytes < len(s.format) && s.format[s.nbytes] == '*' {581 if s.indexPending { // Absorb it.582 s.indexPending = false583 }584 s.nbytes++585 s.argNums = append(s.argNums, s.argNum)586 s.argNum++587 } else {588 s.scanNum()589 }590 return true591}592// parsePrecision scans for a precision. It returns false if there's a bad index expression.593func (s *formatState) parsePrecision() bool {594 // If there's a period, there may be a precision.595 if s.nbytes < len(s.format) && s.format[s.nbytes] == '.' {596 s.flags = append(s.flags, '.') // Treat precision as a flag.597 s.nbytes++598 if !s.parseIndex() {599 return false600 }601 if !s.parseNum() {602 return false603 }604 }605 return true606}607// parsePrintfVerb looks the formatting directive that begins the format string608// and returns a formatState that encodes what the directive wants, without looking609// at the actual arguments present in the call. The result is nil if there is an error.610func parsePrintfVerb(pass *analysis.Pass, call *ast.CallExpr, name, format string, firstArg, argNum int) *formatState {611 state := &formatState{612 format: format,613 name: name,614 flags: make([]byte, 0, 5),615 argNum: argNum,616 argNums: make([]int, 0, 1),617 nbytes: 1, // There's guaranteed to be a percent sign.618 firstArg: firstArg,619 pass: pass,620 call: call,621 }622 // There may be flags.623 state.parseFlags()624 // There may be an index.625 if !state.parseIndex() {626 return nil627 }628 // There may be a width.629 if !state.parseNum() {630 return nil631 }632 // There may be a precision.633 if !state.parsePrecision() {634 return nil635 }636 // Now a verb, possibly prefixed by an index (which we may already have).637 if !state.indexPending && !state.parseIndex() {638 return nil639 }640 if state.nbytes == len(state.format) {641 pass.Reportf(call.Pos(), "%s format %s is missing verb at end of string", name, state.format)642 return nil643 }644 verb, w := utf8.DecodeRuneInString(state.format[state.nbytes:])645 state.verb = verb646 state.nbytes += w647 if verb != '%' {648 state.argNums = append(state.argNums, state.argNum)649 }650 state.format = state.format[:state.nbytes]651 return state652}653// printfArgType encodes the types of expressions a printf verb accepts. It is a bitmask.654type printfArgType int655const (656 argBool printfArgType = 1 << iota657 argInt658 argRune659 argString660 argFloat661 argComplex662 argPointer663 argError664 anyType printfArgType = ^0665)666type printVerb struct {667 verb rune // User may provide verb through Formatter; could be a rune.668 flags string // known flags are all ASCII669 typ printfArgType670}671// Common flag sets for printf verbs.672const (673 noFlag = ""674 numFlag = " -+.0"675 sharpNumFlag = " -+.0#"676 allFlags = " -+.0#"677)678// printVerbs identifies which flags are known to printf for each verb.679var printVerbs = []printVerb{680 // '-' is a width modifier, always valid.681 // '.' is a precision for float, max width for strings.682 // '+' is required sign for numbers, Go format for %v.683 // '#' is alternate format for several verbs.684 // ' ' is spacer for numbers685 {'%', noFlag, 0},686 {'b', numFlag, argInt | argFloat | argComplex | argPointer},687 {'c', "-", argRune | argInt},688 {'d', numFlag, argInt | argPointer},689 {'e', sharpNumFlag, argFloat | argComplex},690 {'E', sharpNumFlag, argFloat | argComplex},691 {'f', sharpNumFlag, argFloat | argComplex},692 {'F', sharpNumFlag, argFloat | argComplex},693 {'g', sharpNumFlag, argFloat | argComplex},694 {'G', sharpNumFlag, argFloat | argComplex},695 {'o', sharpNumFlag, argInt | argPointer},696 {'p', "-#", argPointer},697 {'q', " -+.0#", argRune | argInt | argString},698 {'s', " -+.0", argString},699 {'t', "-", argBool},700 {'T', "-", anyType},701 {'U', "-#", argRune | argInt},702 {'v', allFlags, anyType},703 {'w', allFlags, argError},704 {'x', sharpNumFlag, argRune | argInt | argString | argPointer},705 {'X', sharpNumFlag, argRune | argInt | argString | argPointer},706}707// okPrintfArg compares the formatState to the arguments actually present,708// reporting any discrepancies it can discern. If the final argument is ellipsissed,709// there's little it can do for that.710func okPrintfArg(pass *analysis.Pass, call *ast.CallExpr, state *formatState) (ok bool) {711 var v printVerb712 found := false713 // Linear scan is fast enough for a small list.714 for _, v = range printVerbs {715 if v.verb == state.verb {716 found = true717 break718 }719 }720 // Does current arg implement fmt.Formatter?721 formatter := false722 if state.argNum < len(call.Args) {723 if tv, ok := pass.TypesInfo.Types[call.Args[state.argNum]]; ok {724 formatter = isFormatter(tv.Type)725 }726 }727 if !formatter {728 if !found {729 pass.Reportf(call.Pos(), "%s format %s has unknown verb %c", state.name, state.format, state.verb)730 return false731 }732 for _, flag := range state.flags {733 // TODO: Disable complaint about '0' for Go 1.10. To be fixed properly in 1.11.734 // See issues 23598 and 23605.735 if flag == '0' {736 continue737 }738 if !strings.ContainsRune(v.flags, rune(flag)) {739 pass.Reportf(call.Pos(), "%s format %s has unrecognized flag %c", state.name, state.format, flag)740 return false741 }742 }743 }744 // Verb is good. If len(state.argNums)>trueArgs, we have something like %.*s and all745 // but the final arg must be an integer.746 trueArgs := 1747 if state.verb == '%' {748 trueArgs = 0749 }750 nargs := len(state.argNums)751 for i := 0; i < nargs-trueArgs; i++ {752 argNum := state.argNums[i]753 if !argCanBeChecked(pass, call, i, state) {754 return755 }756 arg := call.Args[argNum]757 if !matchArgType(pass, argInt, nil, arg) {758 pass.Reportf(call.Pos(), "%s format %s uses non-int %s as argument of *", state.name, state.format, analysisutil.Format(pass.Fset, arg))759 return false760 }761 }762 if state.verb == '%' || formatter {763 return true764 }765 argNum := state.argNums[len(state.argNums)-1]766 if !argCanBeChecked(pass, call, len(state.argNums)-1, state) {767 return false768 }769 arg := call.Args[argNum]770 if isFunctionValue(pass, arg) && state.verb != 'p' && state.verb != 'T' {771 pass.Reportf(call.Pos(), "%s format %s arg %s is a func value, not called", state.name, state.format, analysisutil.Format(pass.Fset, arg))772 return false773 }774 if !matchArgType(pass, v.typ, nil, arg) {775 typeString := ""776 if typ := pass.TypesInfo.Types[arg].Type; typ != nil {777 typeString = typ.String()778 }779 pass.Reportf(call.Pos(), "%s format %s has arg %s of wrong type %s", state.name, state.format, analysisutil.Format(pass.Fset, arg), typeString)780 return false781 }782 if v.typ&argString != 0 && v.verb != 'T' && !bytes.Contains(state.flags, []byte{'#'}) && recursiveStringer(pass, arg) {783 pass.Reportf(call.Pos(), "%s format %s with arg %s causes recursive String method call", state.name, state.format, analysisutil.Format(pass.Fset, arg))784 return false785 }786 return true787}788// recursiveStringer reports whether the argument e is a potential789// recursive call to stringer, such as t and &t in these examples:790//791// func (t *T) String() string { printf("%s", t) }792// func (t T) String() string { printf("%s", t) }793// func (t T) String() string { printf("%s", &t) }794//795func recursiveStringer(pass *analysis.Pass, e ast.Expr) bool {796 typ := pass.TypesInfo.Types[e].Type797 // It's unlikely to be a recursive stringer if it has a Format method.798 if isFormatter(typ) {799 return false800 }801 // Does e allow e.String()?802 obj, _, _ := types.LookupFieldOrMethod(typ, false, pass.Pkg, "String")803 stringMethod, ok := obj.(*types.Func)804 if !ok {805 return false806 }807 // Is the expression e within the body of that String method?808 if stringMethod.Pkg() != pass.Pkg || !stringMethod.Scope().Contains(e.Pos()) {809 return false810 }811 sig := stringMethod.Type().(*types.Signature)812 if !isStringer(sig) {813 return false814 }815 // Is it the receiver r, or &r?816 if u, ok := e.(*ast.UnaryExpr); ok && u.Op == token.AND {817 e = u.X // strip off & from &r818 }819 if id, ok := e.(*ast.Ident); ok {820 return pass.TypesInfo.Uses[id] == sig.Recv()821 }822 return false823}824// isStringer reports whether the method signature matches the String() definition in fmt.Stringer.825func isStringer(sig *types.Signature) bool {826 return sig.Params().Len() == 0 &&827 sig.Results().Len() == 1 &&828 sig.Results().At(0).Type() == types.Typ[types.String]829}830// isFunctionValue reports whether the expression is a function as opposed to a function call.831// It is almost always a mistake to print a function value.832func isFunctionValue(pass *analysis.Pass, e ast.Expr) bool {833 if typ := pass.TypesInfo.Types[e].Type; typ != nil {834 _, ok := typ.(*types.Signature)835 return ok836 }837 return false838}839// argCanBeChecked reports whether the specified argument is statically present;840// it may be beyond the list of arguments or in a terminal slice... argument, which841// means we can't see it.842func argCanBeChecked(pass *analysis.Pass, call *ast.CallExpr, formatArg int, state *formatState) bool {843 argNum := state.argNums[formatArg]844 if argNum <= 0 {845 // Shouldn't happen, so catch it with prejudice.846 panic("negative arg num")847 }848 if argNum < len(call.Args)-1 {849 return true // Always OK.850 }851 if call.Ellipsis.IsValid() {852 return false // We just can't tell; there could be many more arguments.853 }854 if argNum < len(call.Args) {855 return true856 }857 // There are bad indexes in the format or there are fewer arguments than the format needs.858 // This is the argument number relative to the format: Printf("%s", "hi") will give 1 for the "hi".859 arg := argNum - state.firstArg + 1 // People think of arguments as 1-indexed.860 pass.Reportf(call.Pos(), "%s format %s reads arg #%d, but call has %v", state.name, state.format, arg, count(len(call.Args)-state.firstArg, "arg"))861 return false862}863// printFormatRE is the regexp we match and report as a possible format string864// in the first argument to unformatted prints like fmt.Print.865// We exclude the space flag, so that printing a string like "x % y" is not reported as a format.866var printFormatRE = regexp.MustCompile(`%` + flagsRE + numOptRE + `\.?` + numOptRE + indexOptRE + verbRE)867const (868 flagsRE = `[+\-#]*`869 indexOptRE = `(\[[0-9]+\])?`870 numOptRE = `([0-9]+|` + indexOptRE + `\*)?`871 verbRE = `[bcdefgopqstvxEFGTUX]`872)873// checkPrint checks a call to an unformatted print routine such as Println.874func checkPrint(pass *analysis.Pass, call *ast.CallExpr, fn *types.Func) {875 firstArg := 0876 typ := pass.TypesInfo.Types[call.Fun].Type877 if typ == nil {878 // Skip checking functions with unknown type.879 return880 }881 if sig, ok := typ.(*types.Signature); ok {882 if !sig.Variadic() {883 // Skip checking non-variadic functions.884 return885 }886 params := sig.Params()887 firstArg = params.Len() - 1888 typ := params.At(firstArg).Type()889 typ = typ.(*types.Slice).Elem()890 it, ok := typ.(*types.Interface)891 if !ok || !it.Empty() {892 // Skip variadic functions accepting non-interface{} args.893 return894 }895 }896 args := call.Args897 if len(args) <= firstArg {898 // Skip calls without variadic args.899 return900 }901 args = args[firstArg:]902 if firstArg == 0 {903 if sel, ok := call.Args[0].(*ast.SelectorExpr); ok {904 if x, ok := sel.X.(*ast.Ident); ok {905 if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") {906 pass.Reportf(call.Pos(), "%s does not take io.Writer but has first arg %s", fn.Name(), analysisutil.Format(pass.Fset, call.Args[0]))907 }908 }909 }910 }911 arg := args[0]912 if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING {913 // Ignore trailing % character in lit.Value.914 // The % in "abc 0.0%" couldn't be a formatting directive.915 s := strings.TrimSuffix(lit.Value, `%"`)916 if strings.Contains(s, "%") {917 m := printFormatRE.FindStringSubmatch(s)918 if m != nil {919 pass.Reportf(call.Pos(), "%s call has possible formatting directive %s", fn.Name(), m[0])920 }921 }922 }923 if strings.HasSuffix(fn.Name(), "ln") {924 // The last item, if a string, should not have a newline.925 arg = args[len(args)-1]926 if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING {927 str, _ := strconv.Unquote(lit.Value)928 if strings.HasSuffix(str, "\n") {929 pass.Reportf(call.Pos(), "%s arg list ends with redundant newline", fn.Name())930 }931 }932 }933 for _, arg := range args {934 if isFunctionValue(pass, arg) {935 pass.Reportf(call.Pos(), "%s arg %s is a func value, not called", fn.Name(), analysisutil.Format(pass.Fset, arg))936 }937 if recursiveStringer(pass, arg) {938 pass.Reportf(call.Pos(), "%s arg %s causes recursive call to String method", fn.Name(), analysisutil.Format(pass.Fset, arg))939 }940 }941}942// count(n, what) returns "1 what" or "N whats"943// (assuming the plural of what is whats).944func count(n int, what string) string {945 if n == 1 {946 return "1 " + what947 }948 return fmt.Sprintf("%d %ss", n, what)949}950// stringSet is a set-of-nonempty-strings-valued flag.951// Note: elements without a '.' get lower-cased.952type stringSet map[string]bool...

Full Screen

Full Screen

converted_types.go

Source:converted_types.go Github

copy

Full Screen

1// Licensed to the Apache Software Foundation (ASF) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The ASF licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing, software12// distributed under the License is distributed on an "AS IS" BASIS,13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14// See the License for the specific language governing permissions and15// limitations under the License.16package schema17import (18 format "github.com/apache/arrow/go/v9/parquet/internal/gen-go/parquet"19)20// ConvertedType corresponds to the ConvertedType in the parquet.Thrift,21// with added values of None and NA for handling when these values are not22// set in the metadata23type ConvertedType format.ConvertedType24var (25 // ConvertedTypes is a struct containing the constants for the types26 // to make it easy to reference them while making it clear what they are27 ConvertedTypes = struct {28 None ConvertedType29 UTF8 ConvertedType30 Map ConvertedType31 MapKeyValue ConvertedType32 List ConvertedType33 Enum ConvertedType34 Decimal ConvertedType35 Date ConvertedType36 TimeMillis ConvertedType37 TimeMicros ConvertedType38 TimestampMillis ConvertedType39 TimestampMicros ConvertedType40 Uint8 ConvertedType41 Uint16 ConvertedType42 Uint32 ConvertedType43 Uint64 ConvertedType44 Int8 ConvertedType45 Int16 ConvertedType46 Int32 ConvertedType47 Int64 ConvertedType48 JSON ConvertedType49 BSON ConvertedType50 Interval ConvertedType51 NA ConvertedType52 }{53 None: -1, // thrift enum starts at 0, so we know this will not be used54 UTF8: ConvertedType(format.ConvertedType_UTF8),55 Map: ConvertedType(format.ConvertedType_MAP),56 MapKeyValue: ConvertedType(format.ConvertedType_MAP_KEY_VALUE),57 List: ConvertedType(format.ConvertedType_LIST),58 Enum: ConvertedType(format.ConvertedType_ENUM),59 Decimal: ConvertedType(format.ConvertedType_DECIMAL),60 Date: ConvertedType(format.ConvertedType_DATE),61 TimeMillis: ConvertedType(format.ConvertedType_TIME_MILLIS),62 TimeMicros: ConvertedType(format.ConvertedType_TIME_MICROS),63 TimestampMillis: ConvertedType(format.ConvertedType_TIMESTAMP_MILLIS),64 TimestampMicros: ConvertedType(format.ConvertedType_TIMESTAMP_MICROS),65 Uint8: ConvertedType(format.ConvertedType_UINT_8),66 Uint16: ConvertedType(format.ConvertedType_UINT_16),67 Uint32: ConvertedType(format.ConvertedType_UINT_32),68 Uint64: ConvertedType(format.ConvertedType_UINT_64),69 Int8: ConvertedType(format.ConvertedType_INT_8),70 Int16: ConvertedType(format.ConvertedType_INT_16),71 Int32: ConvertedType(format.ConvertedType_INT_32),72 Int64: ConvertedType(format.ConvertedType_INT_64),73 JSON: ConvertedType(format.ConvertedType_JSON),74 BSON: ConvertedType(format.ConvertedType_BSON),75 Interval: ConvertedType(format.ConvertedType_INTERVAL),76 NA: 24, // should always be the last values after Interval77 }78)79func (p ConvertedType) String() string {80 switch p {81 case ConvertedTypes.None:82 return "NONE"83 case ConvertedTypes.NA:84 return "UNKNOWN"85 default:86 return format.ConvertedType(p).String()87 }88}89// ToLogicalType returns the correct LogicalType for the given ConvertedType, using the decimal90// metadata provided to define the precision/scale if necessary91func (p ConvertedType) ToLogicalType(convertedDecimal DecimalMetadata) LogicalType {92 switch p {93 case ConvertedTypes.UTF8:94 return StringLogicalType{}95 case ConvertedTypes.Map, ConvertedTypes.MapKeyValue:96 return MapLogicalType{}97 case ConvertedTypes.List:98 return ListLogicalType{}99 case ConvertedTypes.Enum:100 return EnumLogicalType{}101 case ConvertedTypes.Decimal:102 return NewDecimalLogicalType(convertedDecimal.Precision, convertedDecimal.Scale)103 case ConvertedTypes.Date:104 return DateLogicalType{}105 case ConvertedTypes.TimeMillis:106 return NewTimeLogicalType(true /* adjustedToUTC */, TimeUnitMillis)107 case ConvertedTypes.TimeMicros:108 return NewTimeLogicalType(true /* adjustedToUTC */, TimeUnitMicros)109 case ConvertedTypes.TimestampMillis:110 t := NewTimestampLogicalType(true /* adjustedToUTC */, TimeUnitMillis)111 t.(*TimestampLogicalType).fromConverted = true112 return t113 case ConvertedTypes.TimestampMicros:114 t := NewTimestampLogicalType(true /* adjustedToUTC */, TimeUnitMicros)115 t.(*TimestampLogicalType).fromConverted = true116 return t117 case ConvertedTypes.Interval:118 return IntervalLogicalType{}119 case ConvertedTypes.Int8:120 return NewIntLogicalType(8 /* bitWidth */, true /* signed */)121 case ConvertedTypes.Int16:122 return NewIntLogicalType(16 /* bitWidth */, true /* signed */)123 case ConvertedTypes.Int32:124 return NewIntLogicalType(32 /* bitWidth */, true /* signed */)125 case ConvertedTypes.Int64:126 return NewIntLogicalType(64 /* bitWidth */, true /* signed */)127 case ConvertedTypes.Uint8:128 return NewIntLogicalType(8 /* bitWidth */, false /* signed */)129 case ConvertedTypes.Uint16:130 return NewIntLogicalType(16 /* bitWidth */, false /* signed */)131 case ConvertedTypes.Uint32:132 return NewIntLogicalType(32 /* bitWidth */, false /* signed */)133 case ConvertedTypes.Uint64:134 return NewIntLogicalType(64 /* bitWidth */, false /* signed */)135 case ConvertedTypes.JSON:136 return JSONLogicalType{}137 case ConvertedTypes.BSON:138 return BSONLogicalType{}139 case ConvertedTypes.None:140 return NoLogicalType{}141 case ConvertedTypes.NA:142 fallthrough143 default:144 return UnknownLogicalType{}145 }146}147// GetSortOrder defaults to the sort order based on the physical type if convert148// is ConvertedTypes.None, otherwise determines the sort order by the converted type.149func GetSortOrder(convert ConvertedType, primitive format.Type) SortOrder {150 if convert == ConvertedTypes.None {151 return DefaultSortOrder(primitive)152 }153 switch convert {154 case ConvertedTypes.Int8,155 ConvertedTypes.Int16,156 ConvertedTypes.Int32,157 ConvertedTypes.Int64,158 ConvertedTypes.Date,159 ConvertedTypes.TimeMicros,160 ConvertedTypes.TimeMillis,161 ConvertedTypes.TimestampMicros,162 ConvertedTypes.TimestampMillis,163 ConvertedTypes.Decimal:164 return SortSIGNED165 case ConvertedTypes.Uint8,166 ConvertedTypes.Uint16,167 ConvertedTypes.Uint32,168 ConvertedTypes.Uint64,169 ConvertedTypes.Enum,170 ConvertedTypes.UTF8,171 ConvertedTypes.BSON,172 ConvertedTypes.JSON:173 return SortUNSIGNED174 case ConvertedTypes.List,175 ConvertedTypes.Map,176 ConvertedTypes.MapKeyValue,177 ConvertedTypes.Interval,178 ConvertedTypes.None,179 ConvertedTypes.NA:180 return SortUNKNOWN181 default:182 return SortUNKNOWN183 }184}...

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("i =", i)4 fmt.Println("f =", f)5 fmt.Println("b =", b)6 fmt.Println("s =", s)7 fmt.Printf("i = %d8 fmt.Printf("f = %f9 fmt.Printf("b = %t10 fmt.Printf("s = %s11 fmt.Printf("s = %q12}13import "fmt"14func main() {15 fmt.Printf("i = %v16 fmt.Printf("f = %v17 fmt.Printf("b = %v18 fmt.Printf("s = %v19 fmt.Printf("s = %q20}21import "fmt"22func main() {23 fmt.Printf("i = %#v24 fmt.Printf("f = %#v25 fmt.Printf("b = %#v26 fmt.Printf("s = %#v27 fmt.Printf("s = %q28}29import "fmt"30func main() {31 fmt.Printf("i = %T32 fmt.Printf("f = %T33 fmt.Printf("b = %T34 fmt.Printf("s = %T35 fmt.Printf("

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3}4import "fmt"5func main() {6 fmt.Printf("Hello, %s7}8import "fmt"9func main() {10 fmt.Printf("Hello, %s11 fmt.Printf("Hello, %s12}13import "fmt"14func main() {15 fmt.Printf("Hello, %s16 fmt.Printf("Hello, %s17 fmt.Printf("Hello, %s18}19import "fmt"20func main() {21 fmt.Printf("Hello, %s22 fmt.Printf("Hello, %s

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4 fmt.Println("Hello","World")5 fmt.Println("Hello","World","!")6 fmt.Println(1,2,3)7 fmt.Println(true,false)8 fmt.Println(1.0,2.0,3.0)9 fmt.Println(true,false,true)10 fmt.Println("Hello", 1, true)11}12import "fmt"13func main() {14 fmt.Println("Hello World")15 fmt.Println("Hello","World")16 fmt.Println("Hello","World","!")17 fmt.Println(1,2,3)18 fmt.Println(true,false)19 fmt.Println(1.0,2.0,3.0)20 fmt.Println(true,false,true)21 fmt.Println("Hello", 1, true)22}23import "fmt"24func main() {25 fmt.Println("Hello World")26 fmt.Println("Hello","World")27 fmt.Println("Hello","World","!")28 fmt.Println(1,2,3)29 fmt.Println(true,false)30 fmt.Println(1.0,2.0,3.0)31 fmt.Println(true,false,true)32 fmt.Println("Hello", 1, true)33}34import "fmt"35func main() {36 fmt.Println("Hello World")37 fmt.Println("Hello","World")38 fmt.Println("Hello","World","!")39 fmt.Println(1,2,3)40 fmt.Println(true,false)41 fmt.Println(1.0,2.0,3.0)42 fmt.Println(true,false,true)43 fmt.Println("Hello",

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Printf("%d %f %s %t", a, b, c, d)4}5import "fmt"6func main() {7 fmt.Println(a)8}9import "fmt"10func main() {11 fmt.Println(a)12}13import "fmt"14func main() {15 fmt.Println(a)16}17import "fmt"18func main() {19 fmt.Println(a)20}21import "fmt"22func main() {23 fmt.Println(a)24}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4 fmt.Println("Hello, World!")5}6import "fmt"7func main() {8 fmt.Println("Hello, World!")9 fmt.Println("Hello, World!")10}11import "fmt"12func main() {13 fmt.Println("Hello, World!")14 fmt.Println("Hello, World!")15}16import "fmt"17func main() {18 fmt.Println("Hello, World!")19 fmt.Println("Hello, World!")20}21import "fmt"22func main() {23 fmt.Println("Hello, World!")24 fmt.Println("Hello, World!")25}26import "fmt"27func main() {28 fmt.Println("Hello, World!")29 fmt.Println("Hello, World!")30}31import "fmt"32func main() {33 fmt.Println("Hello, World!")34 fmt.Println("Hello, World!")35}36import "fmt"37func main() {38 fmt.Println("Hello, World!")39 fmt.Println("Hello, World!")40}41import "fmt"42func main() {43 fmt.Println("Hello, World!")44 fmt.Println("Hello, World!")45}46import "fmt"47func main() {48 fmt.Println("Hello, World!")49 fmt.Println("Hello, World!")50}51import "fmt"52func main() {53 fmt.Println("Hello, World!")54 fmt.Println("Hello, World!")55}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4 fmt.Printf("Hello World")5 fmt.Println("Hello", "World")6 fmt.Printf("Hello %s", "World")7}8Verb Description %v The value in a default format. When printing structs, the plus flag (%+v) adds field names %T Type of the value %t Boolean %d Integer %b Binary %c Character %x, %X Hexadecimal, base 16, with lower-case and upper-case letters, respectively %o Octal %f, %F Decimal %e, %E Scientific notation %s, %q String %p Pointer %U Unicode format: U+1234; same as "U+%04X"9import "fmt"10func main() {11 fmt.Println("Hello World")12 fmt.Printf("Hello World")13 fmt.Println("Hello", "World")14 fmt.Printf("Hello %s", "World")15 fmt.Println("Hello", "World")16 fmt.Printf("Hello %s", "World")17 fmt.Println("Hello", "World")18 fmt.Printf("Hello %s", "World")19 fmt.Println("Hello", "World")20 fmt.Printf("Hello %s", "World")21 fmt.Println("Hello", "World")22 fmt.Printf("Hello %s", "World")23 fmt.Println("Hello", "World")24 fmt.Printf("Hello %s", "World")25 fmt.Println("Hello", "World")26 fmt.Printf("Hello %s", "World")27 fmt.Println("Hello", "World")28 fmt.Printf("Hello %s", "World")29 fmt.Println("Hello", "World")30 fmt.Printf("Hello %s", "World")31 fmt.Println("Hello", "World")32 fmt.Printf("Hello %s", "World")33 fmt.Println("Hello", "World")34 fmt.Printf("Hello %s", "World")35 fmt.Println("Hello", "World")36 fmt.Printf("Hello %s", "World")37}

Full Screen

Full Screen

Format

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Current time is", time.Now())4 fmt.Println("Current time is", time.Now().Format("02 Jan 2006 15:04:05"))5}6import (7func main() {8 date, err := time.Parse("02 Jan 2006", "06 Oct 2019")9 if err != nil {10 fmt.Println(err)11 }12 fmt.Println("date is", date)13}14import (15func main() {16 date, err := time.Parse("02 Jan 2006", "06 Oct 2019")17 if err != nil {18 fmt.Println(err)19 }20 date = date.Add(time.Hour * 24 * 2)21 fmt.Println("date is", date)22}23import (24func main() {25 date, err := time.Parse("02 Jan 2006", "06 Oct 2019")26 if err != nil {27 fmt.Println(err)28 }29 date = date.Add(time.Hour * 24 * -2)30 fmt.Println("date is", date)31}

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 Testkube automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful