Skip to content

Commit

Permalink
model schema log
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anshul committed Dec 19, 2023
1 parent edafbe6 commit fab1632
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions runtime/reconcilers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"encoding/hex"
"errors"
"fmt"
"strings"
"time"

runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
"github.com/rilldata/rill/runtime"
compilerv1 "github.com/rilldata/rill/runtime/compilers/rillv1"
"github.com/rilldata/rill/runtime/drivers"
"go.uber.org/zap"
"golang.org/x/exp/slog"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -222,6 +225,10 @@ func (r *ModelReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceNa
if createErr != nil {
createErr = fmt.Errorf("failed to create model: %w", createErr)
}

// temporarily for debugging
r.logModelNameAndType(ctx, self, stagingTableName)

if createErr == nil && stage {
// Rename the staging table to main view/table
err = olapForceRenameTable(ctx, r.C, connector, stagingTableName, !materialize, tableName)
Expand Down Expand Up @@ -459,3 +466,32 @@ func (r *ModelReconciler) createModel(ctx context.Context, self *runtimev1.Resou

return olap.CreateTableAsSelect(ctx, tableName, view, sql)
}

func (r *ModelReconciler) logModelNameAndType(ctx context.Context, self *runtimev1.Resource, name string) {
olap, release, err := r.C.AcquireOLAP(ctx, self.GetModel().Spec.Connector)
if err != nil {
r.C.Logger.Error("ModelReconciler: failed to acquire OLAP", zap.Error(err))
return
}
defer release()

res, err := olap.Execute(context.Background(), &drivers.Statement{Query: "SELECT column_name, data_type FROM information_schema.columns WHERE table_name=? ORDER BY column_name ASC", Args: []any{name}})
if err != nil {
r.C.Logger.Error("ModelReconciler: failed information_schema.columns", zap.Error(err))
return
}
defer res.Close()

colTyp := make([]string, 0)
var col, typ string
for res.Next() {
err = res.Scan(&col, &typ)
if err != nil {
r.C.Logger.Error("ModelReconciler: failed scan", zap.Error(err))
return
}
colTyp = append(colTyp, fmt.Sprintf("%s:%s", col, typ))
}

r.C.Logger.Info("ModelReconciler: ", slog.String("name", name), slog.String("schema", strings.Join(colTyp, ", ")))
}

0 comments on commit fab1632

Please sign in to comment.