github.com/snowflakedb/gosnowflake@v1.9.0/query.go (about) 1 // Copyright (c) 2017-2022 Snowflake Computing Inc. All rights reserved. 2 3 package gosnowflake 4 5 import ( 6 "encoding/json" 7 "time" 8 ) 9 10 type resultFormat string 11 12 const ( 13 jsonFormat resultFormat = "json" 14 arrowFormat resultFormat = "arrow" 15 ) 16 17 type execBindParameter struct { 18 Type string `json:"type"` 19 Value interface{} `json:"value"` 20 } 21 22 type execRequest struct { 23 SQLText string `json:"sqlText"` 24 AsyncExec bool `json:"asyncExec"` 25 SequenceID uint64 `json:"sequenceId"` 26 IsInternal bool `json:"isInternal"` 27 DescribeOnly bool `json:"describeOnly,omitempty"` 28 Parameters map[string]interface{} `json:"parameters,omitempty"` 29 Bindings map[string]execBindParameter `json:"bindings,omitempty"` 30 BindStage string `json:"bindStage,omitempty"` 31 QueryContext requestQueryContext `json:"queryContextDTO,omitempty"` 32 } 33 34 type requestQueryContext struct { 35 Entries []requestQueryContextEntry `json:"entries,omitempty"` 36 } 37 38 type requestQueryContextEntry struct { 39 Context contextData `json:"context,omitempty"` 40 ID int `json:"id"` 41 Priority int `json:"priority"` 42 Timestamp int64 `json:"timestamp,omitempty"` 43 } 44 45 type contextData struct { 46 Base64Data string `json:"base64Data,omitempty"` 47 } 48 49 type execResponseRowType struct { 50 Name string `json:"name"` 51 ByteLength int64 `json:"byteLength"` 52 Length int64 `json:"length"` 53 Type string `json:"type"` 54 Precision int64 `json:"precision"` 55 Scale int64 `json:"scale"` 56 Nullable bool `json:"nullable"` 57 } 58 59 type execResponseChunk struct { 60 URL string `json:"url"` 61 RowCount int `json:"rowCount"` 62 UncompressedSize int64 `json:"uncompressedSize"` 63 CompressedSize int64 `json:"compressedSize"` 64 } 65 66 type execResponseCredentials struct { 67 AwsKeyID string `json:"AWS_KEY_ID,omitempty"` 68 AwsSecretKey string `json:"AWS_SECRET_KEY,omitempty"` 69 AwsToken string `json:"AWS_TOKEN,omitempty"` 70 AwsID string `json:"AWS_ID,omitempty"` 71 AwsKey string `json:"AWS_KEY,omitempty"` 72 AzureSasToken string `json:"AZURE_SAS_TOKEN,omitempty"` 73 GcsAccessToken string `json:"GCS_ACCESS_TOKEN,omitempty"` 74 } 75 76 type execResponseStageInfo struct { 77 LocationType string `json:"locationType,omitempty"` 78 Location string `json:"location,omitempty"` 79 Path string `json:"path,omitempty"` 80 Region string `json:"region,omitempty"` 81 StorageAccount string `json:"storageAccount,omitempty"` 82 IsClientSideEncrypted bool `json:"isClientSideEncrypted,omitempty"` 83 Creds execResponseCredentials `json:"creds,omitempty"` 84 PresignedURL string `json:"presignedUrl,omitempty"` 85 EndPoint string `json:"endPoint,omitempty"` 86 } 87 88 // make all data field optional 89 type execResponseData struct { 90 // succeed query response data 91 Parameters []nameValueParameter `json:"parameters,omitempty"` 92 RowType []execResponseRowType `json:"rowtype,omitempty"` 93 RowSet [][]*string `json:"rowset,omitempty"` 94 RowSetBase64 string `json:"rowsetbase64,omitempty"` 95 Total int64 `json:"total,omitempty"` // java:long 96 Returned int64 `json:"returned,omitempty"` // java:long 97 QueryID string `json:"queryId,omitempty"` 98 SQLState string `json:"sqlState,omitempty"` 99 DatabaseProvider string `json:"databaseProvider,omitempty"` 100 FinalDatabaseName string `json:"finalDatabaseName,omitempty"` 101 FinalSchemaName string `json:"finalSchemaName,omitempty"` 102 FinalWarehouseName string `json:"finalWarehouseName,omitempty"` 103 FinalRoleName string `json:"finalRoleName,omitempty"` 104 NumberOfBinds int `json:"numberOfBinds,omitempty"` // java:int 105 StatementTypeID int64 `json:"statementTypeId,omitempty"` // java:long 106 Version int64 `json:"version,omitempty"` // java:long 107 Chunks []execResponseChunk `json:"chunks,omitempty"` 108 Qrmk string `json:"qrmk,omitempty"` 109 ChunkHeaders map[string]string `json:"chunkHeaders,omitempty"` 110 111 // ping pong response data 112 GetResultURL string `json:"getResultUrl,omitempty"` 113 ProgressDesc string `json:"progressDesc,omitempty"` 114 QueryAbortTimeout time.Duration `json:"queryAbortsAfterSecs,omitempty"` 115 ResultIDs string `json:"resultIds,omitempty"` 116 ResultTypes string `json:"resultTypes,omitempty"` 117 QueryResultFormat string `json:"queryResultFormat,omitempty"` 118 119 // async response placeholders 120 AsyncResult *snowflakeResult `json:"asyncResult,omitempty"` 121 AsyncRows *snowflakeRows `json:"asyncRows,omitempty"` 122 123 // file transfer response data 124 UploadInfo execResponseStageInfo `json:"uploadInfo,omitempty"` 125 LocalLocation string `json:"localLocation,omitempty"` 126 SrcLocations []string `json:"src_locations,omitempty"` 127 Parallel int64 `json:"parallel,omitempty"` 128 Threshold int64 `json:"threshold,omitempty"` 129 AutoCompress bool `json:"autoCompress,omitempty"` 130 Overwrite bool `json:"overwrite,omitempty"` 131 SourceCompression string `json:"sourceCompression,omitempty"` 132 ShowEncryptionParameter bool `json:"clientShowEncryptionParameter,omitempty"` 133 EncryptionMaterial encryptionWrapper `json:"encryptionMaterial,omitempty"` 134 PresignedURLs []string `json:"presignedUrls,omitempty"` 135 StageInfo execResponseStageInfo `json:"stageInfo,omitempty"` 136 Command string `json:"command,omitempty"` 137 Kind string `json:"kind,omitempty"` 138 Operation string `json:"operation,omitempty"` 139 140 // HTAP 141 QueryContext json.RawMessage `json:"queryContext,omitempty"` 142 } 143 144 type execResponse struct { 145 Data execResponseData `json:"Data"` 146 Message string `json:"message"` 147 Code string `json:"code"` 148 Success bool `json:"success"` 149 }