Skip to content

Commit

Permalink
v1.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnmllr committed Jan 12, 2024
1 parent 435e931 commit 36ea7b4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Release Notes

## v1.7.0

#### v1.7.4
- performance improvements

#### v1.7.3
- updated dependencies
- test performance improvements
Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// DriverVersion is the version number of the hdb driver.
const DriverVersion = "1.7.3"
const DriverVersion = "1.7.4"

// DriverName is the driver name to use with sql.Open for hdb databases.
const DriverName = "hdb"
Expand Down
14 changes: 9 additions & 5 deletions driver/internal/protocol/fieldtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func (ft _lobCESU8Type) encodePrm(e *encoding.Encoder, v any) error {

func encodeLobPrm(e *encoding.Encoder, descr *LobInDescr) error {
e.Byte(byte(descr.Opt))
e.Int32(int32(len(descr.b)))
e.Int32(int32(descr.size()))
e.Int32(int32(descr.pos))
return nil
}
Expand Down Expand Up @@ -962,10 +962,14 @@ func (_cesu8Type) decodeRes(d *encoding.Decoder) (any, error) {
}

func decodeLobPrm(d *encoding.Decoder) (any, error) {
descr := &LobInDescr{}
descr.Opt = LobOptions(d.Byte())
descr._size = int(d.Int32())
descr.pos = int(d.Int32())
// real decoding (sniffer) not yet supported
// descr := &LobInDescr{}
// descr.Opt = LobOptions(d.Byte())
// descr._size = int(d.Int32())
// descr.pos = int(d.Int32())
d.Byte()
d.Int32()
d.Int32()
return nil, nil
}

Expand Down
52 changes: 17 additions & 35 deletions driver/internal/protocol/lob.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package protocol

import (
"bytes"
"errors"
"fmt"
"io"

"github.com/SAP/go-hdb/driver/internal/exp/slices"
"github.com/SAP/go-hdb/driver/internal/minmax"
"github.com/SAP/go-hdb/driver/internal/protocol/encoding"
)

Expand Down Expand Up @@ -76,11 +80,10 @@ var _ LobDecoderSetter = (*LobOutDescr)(nil)

// LobInDescr represents a lob input descriptor.
type LobInDescr struct {
rd io.Reader
Opt LobOptions
_size int
pos int
b []byte
rd io.Reader
Opt LobOptions
pos int
buf bytes.Buffer
}

func newLobInDescr(rd io.Reader) *LobInDescr {
Expand All @@ -89,31 +92,20 @@ func newLobInDescr(rd io.Reader) *LobInDescr {

func (d *LobInDescr) String() string {
// restrict output size
b := d.b
if len(b) >= 25 {
b = d.b[:25]
}
return fmt.Sprintf("options %s size %d pos %d bytes %v", d.Opt, d._size, d.pos, b)
return fmt.Sprintf("options %s size %d pos %d bytes %v", d.Opt, d.buf.Len(), d.pos, d.buf.Bytes()[:minmax.MinInt(d.buf.Len(), 25)])
}

// FetchNext fetches the next lob chunk.
func (d *LobInDescr) FetchNext(chunkSize int) error {
if cap(d.b) < chunkSize {
d.b = make([]byte, chunkSize)
}
d.b = d.b[:chunkSize]

var err error
/*
We need to guarantee, that a max amount of data is read to prevent
piece wise LOB writing when avoidable
--> ReadFull
--> copy up to chunkSize
*/
d._size, err = io.ReadFull(d.rd, d.b)
d.b = d.b[:d._size]

d.buf.Reset()
_, err := io.CopyN(&d.buf, d.rd, int64(chunkSize))
d.Opt = loDataincluded
if err != io.EOF && err != io.ErrUnexpectedEOF {
if !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) {
return err
}
d.Opt |= loLastdata
Expand All @@ -122,11 +114,9 @@ func (d *LobInDescr) FetchNext(chunkSize int) error {

func (d *LobInDescr) setPos(pos int) { d.pos = pos }

func (d *LobInDescr) size() int { return d._size }
func (d *LobInDescr) size() int { return d.buf.Len() }

func (d *LobInDescr) writeFirst(enc *encoding.Encoder) {
enc.Bytes(d.b)
}
func (d *LobInDescr) writeFirst(enc *encoding.Encoder) { enc.Bytes(d.buf.Bytes()) }

// LobOutDescr represents a lob output descriptor.
type LobOutDescr struct {
Expand Down Expand Up @@ -185,7 +175,7 @@ func (d *WriteLobDescr) FetchNext(chunkSize int) error {
}
d.Opt = d.LobInDescr.Opt
d.ofs = -1 // offset (-1 := append)
d.b = d.LobInDescr.b
d.b = d.LobInDescr.buf.Bytes()
return nil
}

Expand Down Expand Up @@ -316,14 +306,6 @@ func (r *ReadLobReply) String() string {
return fmt.Sprintf("id %d options %s bytes %v", r.ID, r.Opt, r.B)
}

func (r *ReadLobReply) resize(size int) {
if r.B == nil || size > cap(r.B) {
r.B = make([]byte, size)
} else {
r.B = r.B[:size]
}
}

func (r *ReadLobReply) decodeNumArg(dec *encoding.Decoder, numArg int) error {
if numArg != 1 {
panic("numArg == 1 expected")
Expand All @@ -332,7 +314,7 @@ func (r *ReadLobReply) decodeNumArg(dec *encoding.Decoder, numArg int) error {
r.Opt = LobOptions(dec.Int8())
size := int(dec.Int32())
dec.Skip(3)
r.resize(size)
r.B = slices.Grow(r.B, size)[:size]
dec.Bytes(r.B)
return nil
}

0 comments on commit 36ea7b4

Please sign in to comment.